Skip to content

Commit

Permalink
feat: init support lang design
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 23, 2023
1 parent 5449f50 commit 280ee34
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
12 changes: 12 additions & 0 deletions unit-picker/src/main/kotlin/cc/unitmesh/pick/SupportedLang.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cc.unitmesh.pick

enum class SupportedLang {
JAVA,
;

companion object {
fun all(): List<SupportedLang> {
return listOf(JAVA)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import chapi.domain.core.CodeFunction
import chapi.domain.core.CodeImport

class JavaTestCodeService(val context: JobContext) : UnitTestService {
override fun isApplicable(dataStruct: CodeDataStruct): Boolean {
return dataStruct.NodeName.endsWith("Test") || dataStruct.NodeName.endsWith("Tests")
}

override fun findUnderTestFile(dataStruct: CodeDataStruct): List<CodeDataStruct> {
val fileTree = context.fileTree
val testClass = dataStruct.NodeName.removeSuffix("Test").removeSuffix("Tests")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cc.unitmesh.pick.builder.unittest.lang

import cc.unitmesh.pick.SupportedLang
import cc.unitmesh.pick.worker.job.JobContext
import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeFunction

Expand All @@ -16,6 +18,11 @@ import chapi.domain.core.CodeFunction
* for these methods based on the specific requirements of the testing framework or tool being used.
*/
interface UnitTestService {
/**
* Checks if the given data structure is a test file.
*/
fun isApplicable(dataStruct: CodeDataStruct): Boolean

/**
* Finds the files that contain the under test code related to the given data structure.
*
Expand Down Expand Up @@ -46,5 +53,17 @@ interface UnitTestService {
* @return A list of code data structures representing the relevant classes found for the given code function and data structure.
*/
fun lookupRelevantClass(codeFunction: CodeFunction, dataStruct: CodeDataStruct): List<CodeDataStruct>

companion object {
fun lookup(codeDataStruct: CodeDataStruct, job: JobContext): List<JavaTestCodeService> {
val testCodeServices = SupportedLang.all().map {
when (it) {
SupportedLang.JAVA -> JavaTestCodeService(job)
}
}

return testCodeServices.filter { it.isApplicable(codeDataStruct) }
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import org.slf4j.Logger
* This class extends the SimilarChunksWithPaths class, providing additional functionality for handling Java code.
*/
class JavaSimilarChunker(private val fileTree: HashMap<String, InstructionFileJob>) : SimilarChunker() {
companion object {
val logger: Logger = org.slf4j.LoggerFactory.getLogger(JavaSimilarChunker::class.java)
}

/**
* Calculates the similar code chunks based on the given text and canonical name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cc.unitmesh.pick.strategy.bizcode

import cc.unitmesh.pick.builder.completionBuilders
import cc.unitmesh.pick.builder.ins.RelatedCodeIns
import cc.unitmesh.pick.builder.unittest.lang.UnitTestService
import cc.unitmesh.pick.strategy.base.CodeStrategyBuilder
import cc.unitmesh.pick.worker.job.JobContext
import chapi.domain.core.CodeContainer
Expand All @@ -26,6 +27,9 @@ class RelatedCodeStrategyBuilder(private val context: JobContext) : CodeStrategy
val builders = completionBuilders(context.completionBuilderTypes, context)

val codeCompletionIns = dataStructs.map { ds ->
UnitTestService.lookup(ds, context).map {
// it.build(ds)
}
ds.Functions.map { function ->
builders.asSequence().map {
it.build(function)
Expand Down

0 comments on commit 280ee34

Please sign in to comment.