Skip to content

Commit

Permalink
refactor: reorg datastrucutre
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 8, 2023
1 parent 4c247de commit af04896
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cc.unitmesh.quality

import kotlinx.serialization.Serializable

@Serializable
enum class CodeQualityType {
BadSmell,
TestBadSmell,
JavaController,
JavaRepository,
JavaService,
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EstimateAnalyser {
private var languageWorker = LanguageWorker()

fun analysisByNode(node: CodeDataStruct): LanguageSummary? {
val summary = analysisByContent(node.Content, Path.of(node.FilePath).fileName.toString())
val summary = analysisByContent(node.Content, Path.of(node.FilePath).fileName.toString(), "Go")
return summary?.complexity?.let {
if (it > 0) {
summary
Expand All @@ -21,10 +21,10 @@ class EstimateAnalyser {
}
}

fun analysisByContent(content: String, filename: String): LanguageSummary? {
fun analysisByContent(content: String, filename: String, lang: String): LanguageSummary? {
val fileContent = content.toByteArray()
val fileJob = FileJob(
language = "Go",
language = lang,
content = fileContent,
filename = filename,
bytes = fileContent.size.toLong(),
Expand All @@ -44,15 +44,4 @@ class EstimateAnalyser {
bytes = countStats.bytes,
)
}

companion object {
private var instance: EstimateAnalyser? = null
fun getInstance(): EstimateAnalyser {
if (instance == null) {
instance = EstimateAnalyser()
}

return instance!!
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ package cc.unitmesh.quality.extension
import cc.unitmesh.quality.base.QualityAnalyser
import chapi.domain.core.CodeDataStruct
import org.archguard.linter.rule.webapi.WebApiRuleSetProvider
import org.archguard.linter.rule.webapi.WebApiRuleVisitor
import org.archguard.rule.core.Issue
import org.archguard.scanner.analyser.backend.JavaApiAnalyser

class JavaControllerAnalyser : QualityAnalyser {
private val webApiRuleSetProvider = WebApiRuleSetProvider()

override fun analysis(nodes: List<CodeDataStruct>): List<Issue> {
val apiAnalyser = JavaApiAnalyser()

nodes.forEach { data ->
apiAnalyser.analysisByNode(data, "")
}
val services = apiAnalyser.toContainerServices()
return WebApiRuleVisitor(services).visitor(listOf(webApiRuleSetProvider.get()))
// 检查 Service 长度,调用的 repository 数量,
return listOf()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cc.unitmesh.quality.extension

import cc.unitmesh.quality.base.QualityAnalyser
import chapi.domain.core.CodeDataStruct
import org.archguard.linter.rule.webapi.WebApiRuleSetProvider
import org.archguard.linter.rule.webapi.WebApiRuleVisitor
import org.archguard.rule.core.Issue
import org.archguard.scanner.analyser.backend.JavaApiAnalyser

class JavaServiceAnalyser : QualityAnalyser {
private val webApiRuleSetProvider = WebApiRuleSetProvider()

override fun analysis(nodes: List<CodeDataStruct>): List<Issue> {
val apiAnalyser = JavaApiAnalyser()

nodes.forEach { data ->
apiAnalyser.analysisByNode(data, "")
}
val services = apiAnalyser.toContainerServices()
return WebApiRuleVisitor(services).visitor(listOf(webApiRuleSetProvider.get()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EstimateAnalyserTest {
val file = File("sample.txt").canonicalPath

// when
val summary = EstimateAnalyser.getInstance().analysisByContent(content, file)!!
val summary = EstimateAnalyser.getInstance().analysisByContent(content, file, "Go")!!

// then
assertEquals("Go", summary.name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cc.unitmesh.pick.picker

import cc.unitmesh.pick.prompt.InstructionType
import cc.unitmesh.quality.CodeQualityType
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -15,8 +16,3 @@ data class PickerConfig(
val codeQualityTypes: List<CodeQualityType> = listOf()
)

@Serializable
enum class CodeQualityType {
BadSmell,
TestBadSmell
}

0 comments on commit af04896

Please sign in to comment.