-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for anlysis content by content
- Loading branch information
Showing
2 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
50 changes: 48 additions & 2 deletions
50
unit-picker/src/main/kotlin/org/unimesh/eval/picker/bs/EstimateAnalyser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,52 @@ | ||
package org.unimesh.eval.picker.bs | ||
|
||
import chapi.domain.core.CodeDataStruct | ||
import org.archguard.scanner.analyser.count.FileJob | ||
import org.archguard.scanner.analyser.count.LanguageSummary | ||
import org.archguard.scanner.analyser.count.LanguageWorker | ||
import java.nio.file.Path | ||
|
||
class EstimateAnalyser(val data: List<CodeDataStruct>) { | ||
class EstimateAnalyser() { | ||
companion object { | ||
private var instance: EstimateAnalyser? = null | ||
fun getInstance(): EstimateAnalyser { | ||
if (instance == null) { | ||
instance = EstimateAnalyser() | ||
} | ||
|
||
return instance!! | ||
} | ||
} | ||
|
||
private var languageWorker = LanguageWorker() | ||
|
||
fun analysisByPath(path: Path): LanguageSummary? { | ||
val file = path.toFile() | ||
val content = file.readText() | ||
|
||
return analysisByContent(content, file.name) | ||
} | ||
|
||
fun analysisByContent(content: String, filename: String): LanguageSummary? { | ||
val fileContent = content.toByteArray() | ||
val fileJob = FileJob( | ||
language = "Go", | ||
content = fileContent, | ||
filename = filename, | ||
bytes = fileContent.size.toLong(), | ||
) | ||
|
||
|
||
val countStats = languageWorker.countStats(fileJob) ?: return null | ||
|
||
return LanguageSummary( | ||
name = countStats.language, | ||
lines = countStats.lines, | ||
code = countStats.code, | ||
blank = countStats.blank, | ||
comment = countStats.comment, | ||
complexity = countStats.complexity, | ||
weightedComplexity = countStats.weightedComplexity, | ||
bytes = countStats.bytes, | ||
) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
unit-picker/src/test/kotlin/org/unimesh/eval/picker/bs/EstimateAnalyserTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.unimesh.eval.picker.bs; | ||
|
||
import org.junit.jupiter.api.Assertions.assertNull | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
import kotlin.test.assertEquals | ||
|
||
class EstimateAnalyserTest { | ||
|
||
@Test | ||
fun should_return_null_when_analysis_by_content_with_empty_content() { | ||
// given | ||
val content = """type BSDataStruct struct { | ||
core_domain.CodeDataStruct | ||
Functions []BSFunction | ||
DataStructBS ClassBadSmellInfo | ||
}""" | ||
val file = File("sample.txt").canonicalPath | ||
|
||
// when | ||
val summary = EstimateAnalyser.getInstance().analysisByContent(content, file)!! | ||
|
||
// then | ||
println(summary) | ||
assertEquals("Go", summary.name) | ||
} | ||
} |