Skip to content

Commit

Permalink
refactor: extract some lang logic to SupportedLang, so that it can ma…
Browse files Browse the repository at this point in the history
…ke easy to add new language support
  • Loading branch information
phodal committed Dec 23, 2023
1 parent edb892a commit 7c25a7f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 38 deletions.
19 changes: 19 additions & 0 deletions unit-core/src/main/kotlin/cc/unitmesh/core/SupportedLang.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cc.unitmesh.core

enum class SupportedLang {
JAVA,
;

companion object {
fun from(value: String): SupportedLang? {
return when (value.lowercase()) {
"java" -> JAVA
else -> null
}
}

fun all(): List<SupportedLang> {
return listOf(JAVA)
}
}
}
12 changes: 0 additions & 12 deletions unit-picker/src/main/kotlin/cc/unitmesh/pick/SupportedLang.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cc.unitmesh.pick.builder.unittest.lang

import cc.unitmesh.core.completion.TypedIns
import cc.unitmesh.core.unittest.TypedTestIns
import cc.unitmesh.pick.worker.job.InstructionFileJob
import cc.unitmesh.pick.worker.job.JobContext
Expand Down Expand Up @@ -51,10 +50,6 @@ class JavaTestCodeService(val context: JobContext) : UnitTestService {
return outboundType + inboundsType
}

override fun build(): TypedTestIns {
TODO("Not yet implemented")
}

fun filterDs(
imports: List<CodeImport>,
returnType: String,
Expand All @@ -66,5 +61,9 @@ class JavaTestCodeService(val context: JobContext) : UnitTestService {
null
}
}.flatten()

override fun build(): TypedTestIns {
TODO("Not yet implemented")
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cc.unitmesh.pick.builder.unittest.lang

import cc.unitmesh.core.completion.TypedIns
import cc.unitmesh.pick.SupportedLang
import cc.unitmesh.core.SupportedLang
import cc.unitmesh.pick.worker.job.JobContext
import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeFunction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cc.unitmesh.pick.worker

import cc.unitmesh.pick.worker.job.InstructionFileJob
import cc.unitmesh.core.Instruction
import cc.unitmesh.pick.worker.lang.JavaWorker
import cc.unitmesh.core.SupportedLang
import cc.unitmesh.pick.worker.base.LangWorker
import org.archguard.rule.common.Language
import cc.unitmesh.pick.worker.job.InstructionFileJob
import cc.unitmesh.pick.worker.lang.JavaWorker
import org.archguard.scanner.analyser.ScaAnalyser
import org.archguard.scanner.analyser.count.LanguageService
import org.archguard.scanner.core.client.ArchGuardClient
Expand All @@ -15,16 +15,16 @@ import java.io.File


class WorkerManager(private val workerContext: WorkerContext) {
private val workers: Map<Language, LangWorker> = mapOf(
Language.JAVA to JavaWorker(workerContext),
private val workers: Map<SupportedLang, LangWorker> = mapOf(
SupportedLang.JAVA to JavaWorker(workerContext),
// Language.TYPESCRIPT to TypescriptWorker(workerContext),
// Language.JAVASCRIPT to TypescriptWorker(workerContext),
)

private val language: LanguageService = LanguageService()

private val supportedExtensions: Set<String> = setOf(
language.getExtension(Language.JAVA.name.lowercase()),
language.getExtension(SupportedLang.JAVA.name.lowercase()),
)

private val logger: Logger = org.slf4j.LoggerFactory.getLogger(WorkerManager::class.java)
Expand Down Expand Up @@ -89,7 +89,7 @@ class WorkerManager(private val workerContext: WorkerContext) {
// return
// }

val language = summary.language.toSupportLanguage()
val language = SupportedLang.from(summary.language)
val worker = workers[language] ?: return
worker.addJob(job)
}
Expand All @@ -105,16 +105,3 @@ class WorkerManager(private val workerContext: WorkerContext) {
}.flatten()
}
}

private fun String.toSupportLanguage(): Language? {
return when (this.lowercase()) {
"java" -> Language.JAVA
"kotlin" -> Language.KOTLIN
"csharp", "c#" -> Language.CSHARP
"python" -> Language.PYTHON
"go" -> Language.GO
"typescript" -> Language.TYPESCRIPT
"javascript" -> Language.JAVASCRIPT
else -> null
}
}

0 comments on commit 7c25a7f

Please sign in to comment.