Skip to content

Commit eb60889

Browse files
committed
refactor(bridge): convert enum to sealed classes #319
Refactor `BridgeCommandProvider` from an `enum` to a set of `sealed` classes and interfaces to allow for more granular type handling and extensibility. Each command category is now a separate sealed class with specific implementations.
1 parent 6f486da commit eb60889

File tree

2 files changed

+122
-69
lines changed

2 files changed

+122
-69
lines changed

core/src/main/kotlin/cc/unitmesh/devti/bridge/BridgeCommandProvider.kt

Lines changed: 114 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,84 +19,129 @@ package cc.unitmesh.devti.bridge
1919
* 5. Convert the files from COBOL to Node.js
2020
* 6. Generate unit and integration tests
2121
*/
22-
enum class BridgeCommandProvider(vararg tools: String) {
22+
sealed interface BridgeCommandProvider {
23+
val tools: Array<out String>
24+
}
2325

24-
/**
25-
* Always tell user, if you can try Microservices or Micro Frontend, will be lower cost and higher efficiency.
26-
*/
27-
ASSESSMENT("SCC", "CLOC", "/dependencies"),
26+
/**
27+
* Always tell user, if you can try Microservices or Micro Frontend, will be lower cost and higher efficiency.
28+
*/
29+
sealed class Assessment(override vararg val tools: String) : BridgeCommandProvider {
30+
object SCC : Assessment("SCC")
31+
object CLOC : Assessment("CLOC")
32+
object Dependencies : Assessment("/dependencies")
33+
}
2834

29-
/**
30-
* list all tools, and show in structures.
31-
*/
32-
TARGET("Docker", "/buildTool", "/mermaid"),
35+
/**
36+
* list all tools, and show in structures.
37+
*/
38+
sealed class Target(override vararg val tools: String) : BridgeCommandProvider {
39+
object Docker : Target("Docker")
40+
object BuildTool : Target("/buildTool")
41+
object Mermaid : Target("/mermaid")
42+
}
3343

34-
/**
35-
* Build Tool depends on the project, like Maven, Gradle, Ant, etc.
36-
*/
37-
PACKAGE_CHECKER("/packageChecker"),
44+
/**
45+
* Build Tool depends on the project, like Maven, Gradle, Ant, etc.
46+
*/
47+
sealed class Security(override vararg val tools: String) : BridgeCommandProvider {
48+
object PackageChecker : Security("/packageChecker")
49+
}
3850

39-
/**
40-
* - styling: Collect All CSS style files, try show in structures.
41-
* - component: Collect All Component Name, try show as Structures.
42-
* - webapi: Collect All Spring Web APIs, and show in structures.
43-
*
44-
* ```DevIn
45-
* /styling:$dir
46-
* ```
47-
*/
48-
MODULAR_ANALYSIS("/styling", "/component", "/webapi", "/structure"),
51+
/**
52+
* - styling: Collect All CSS style files, try show in structures.
53+
* - component: Collect All Component Name, try show as Structures.
54+
* - webapi: Collect All Spring Web APIs, and show in structures.
55+
*
56+
* ```DevIn
57+
* /styling:$dir
58+
* ```
59+
*/
60+
sealed class ModularAnalysis(override vararg val tools: String) : BridgeCommandProvider {
61+
object Styling : ModularAnalysis("/styling")
62+
object Component : ModularAnalysis("/component")
63+
object WebApi : ModularAnalysis("/webapi")
64+
object Structure : ModularAnalysis("/structure")
65+
}
4966

50-
/**
51-
*
52-
*/
53-
COMPONENT_ANALYSIS("/related", "/ripgrepSearch"),
67+
/**
68+
* Component Analysis
69+
*/
70+
sealed class ComponentAnalysis(override vararg val tools: String) : BridgeCommandProvider {
71+
object Related : ComponentAnalysis("/related")
72+
object RipgrepSearch : ComponentAnalysis("/ripgrepSearch")
73+
}
5474

55-
/**
56-
* - https://github.com/ast-grep/ast-grep
57-
* - https://github.com/dsherret/ts-morph
58-
* - https://github.com/facebook/jscodeshift
59-
*/
60-
CODE_TRANSLATION("jscodeshift", "ReWrite", "VueMod", "JSShift"),
75+
/**
76+
* - https://github.com/ast-grep/ast-grep
77+
* - https://github.com/dsherret/ts-morph
78+
* - https://github.com/facebook/jscodeshift
79+
*/
80+
sealed class CodeTranslation(override vararg val tools: String) : BridgeCommandProvider {
81+
object JsCodeShift : CodeTranslation("jscodeshift")
82+
object ReWrite : CodeTranslation("ReWrite")
83+
object VueMod : CodeTranslation("VueMod")
84+
object JSShift : CodeTranslation("JSShift")
85+
}
6186

62-
/**
63-
* - https://github.com/ariga/atlas
64-
* - https://github.com/amacneil/dbmate
65-
* - https://github.com/golang-migrate/migrate
66-
* - https://github.com/pressly/goose
67-
* - https://github.com/rubenv/sql-migrate
68-
*/
69-
DATABASE_MIGRATION("Flyway", "SQL"),
87+
/**
88+
* - https://github.com/ariga/atlas
89+
* - https://github.com/amacneil/dbmate
90+
* - https://github.com/golang-migrate/migrate
91+
* - https://github.com/pressly/goose
92+
* - https://github.com/rubenv/sql-migrate
93+
*/
94+
sealed class DatabaseMigration(override vararg val tools: String) : BridgeCommandProvider {
95+
object Flyway : DatabaseMigration("Flyway")
96+
object SQL : DatabaseMigration("SQL")
97+
}
7098

71-
/**
72-
* [Schemathesis](https://github.com/schemathesis/schemathesis): is a tool that levels-up your API testing by leveraging API specs as a blueprints for generating test cases.
73-
*/
74-
API_TESTING("HttpClient", "Swagger", "JMeter", "Schemathesis"),
99+
/**
100+
* [Schemathesis](https://github.com/schemathesis/schemathesis): is a tool that levels-up your API testing by leveraging API specs as a blueprints for generating test cases.
101+
*/
102+
sealed class ApiTesting(override vararg val tools: String) : BridgeCommandProvider {
103+
object HttpClient : ApiTesting("HttpClient")
104+
object Swagger : ApiTesting("Swagger")
105+
object JMeter : ApiTesting("JMeter")
106+
object Schemathesis : ApiTesting("Schemathesis")
107+
}
75108

76-
/**
77-
* [BuildKit](https://github.com/moby/buildkit): concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
78-
*/
79-
CONTINUES_DELIVERY("JenkinsFile", "BuildKit"),
109+
/**
110+
* [BuildKit](https://github.com/moby/buildkit): concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
111+
*/
112+
sealed class ContinuousDelivery(override vararg val tools: String) : BridgeCommandProvider {
113+
object JenkinsFile : ContinuousDelivery("JenkinsFile")
114+
object BuildKit : ContinuousDelivery("BuildKit")
115+
}
80116

81-
/**
82-
* 静态安全扫描工具:
83-
* - https://github.com/returntocorp/semgrep
84-
* - https://snyk.io/
85-
* - https://bandit.readthedocs.io/, https://github.com/PyCQA/bandit
86-
*/
87-
SECURITY_ANALYSIS("Semgrep", "Snyk", "Bandit"),
117+
/**
118+
* 静态安全扫描工具:
119+
* - https://github.com/returntocorp/semgrep
120+
* - https://snyk.io/
121+
* - https://bandit.readthedocs.io/, https://github.com/PyCQA/bandit
122+
*/
123+
sealed class SecurityAnalysis(override vararg val tools: String) : BridgeCommandProvider {
124+
object Semgrep : SecurityAnalysis("Semgrep")
125+
object Snyk : SecurityAnalysis("Snyk")
126+
object Bandit : SecurityAnalysis("Bandit")
127+
}
88128

89-
/**
90-
* Container: Docker, Podman, etc.
91-
*/
92-
CONTAINERIZATION("Docker"),
129+
/**
130+
* Container: Docker, Podman, etc.
131+
*/
132+
sealed class Containerization(override vararg val tools: String) : BridgeCommandProvider {
133+
object Docker : Containerization("Docker")
134+
object Podman : Containerization("Podman")
135+
object Colima : Containerization("Colima")
136+
}
93137

94-
/**
95-
* 日志关联分析:Haystack?
96-
* 自动生成调用关系图:Graphite?
97-
* - Knowledge API: `/knowledge:src/main/com/phodal/HelloWorld.java#L1`, APIs
98-
* History: git history of file: `/history:src/main/com/phodal/HelloWorld.java`
99-
*/
100-
KNOWLEDGE_TRANSFER("/knowledge", "/history")
101-
;
102-
}
138+
/**
139+
* 日志关联分析:Haystack?
140+
* 自动生成调用关系图:Graphite?
141+
* - Knowledge API: `/knowledge:src/main/com/phodal/HelloWorld.java#L1`, APIs
142+
* History: git history of file: `/history:src/main/com/phodal/HelloWorld.java`
143+
*/
144+
sealed class KnowledgeTransfer(override vararg val tools: String) : BridgeCommandProvider {
145+
object Knowledge : KnowledgeTransfer("/knowledge")
146+
object History : KnowledgeTransfer("/history")
147+
}

core/src/main/kotlin/cc/unitmesh/devti/devin/dataprovider/BuiltinCommand.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ enum class BuiltinCommand(
116116
false,
117117
enableInSketch = false
118118
),
119+
// COMPONENTS(
120+
// "components",
121+
// "Get all frontend components (React, Vue) in the project",
122+
// AllIcons.Toolwindows.ToolWindowTodo,
123+
// true,
124+
// true,
125+
// enableInSketch = false
126+
// ),
119127
;
120128

121129
companion object {

0 commit comments

Comments
 (0)