Skip to content

Commit

Permalink
refactor: simplify job for tasking
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 7, 2023
1 parent 9b97f73 commit 6f5c476
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 45 deletions.
42 changes: 2 additions & 40 deletions unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/PickJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,13 @@ import java.security.MessageDigest

@Serializable
class PickJob(
var language: String = "",
var possibleLanguages: List<String> = listOf(),
var filename: String = "",
var extension: String = "",
var location: String = "",
var symlocation: String = "",
var content: ByteArray = byteArrayOf(),
var bytes: Long = 0,
var lines: Long = 0,
var code: Long = 0,
var comment: Long = 0,
var blank: Long = 0,
var complexity: Long = 0,
var weightedComplexity: Double = 0.0,
// skip serialisation
@Transient
var hash: MessageDigest = MessageDigest.getInstance("SHA-256"),
var binary: Boolean = false,
var minified: Boolean = false,
var generated: Boolean = false,
var endPoint: Int = 0,
var fileSummary: FileJob,
var container: CodeContainer? = null,
) {
companion object {
fun from(fileJob: FileJob): PickJob {
return PickJob(
language = fileJob.language,
possibleLanguages = fileJob.possibleLanguages,
filename = fileJob.filename,
extension = fileJob.extension,
location = fileJob.location,
symlocation = fileJob.symlocation,
content = fileJob.content,
bytes = fileJob.bytes,
lines = fileJob.lines,
code = fileJob.code,
comment = fileJob.comment,
blank = fileJob.blank,
complexity = fileJob.complexity,
weightedComplexity = fileJob.weightedComplexity,
hash = fileJob.hash,
binary = fileJob.binary,
minified = fileJob.minified,
generated = fileJob.generated,
endPoint = fileJob.endPoint,
fileSummary = fileJob
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ class JavaLangWorker : LangWorker() {

override fun addJob(job: PickJob) {
this.jobs.add(job)
val code = job.content.decodeToString()
val code = job.fileSummary.content.decodeToString()
tryAddClassToTree(code, job)

job.container = JavaAnalyser().analysis(code, job.fileSummary.location)
}

private fun tryAddClassToTree(code: String, job: PickJob) {
val packageMatch = packageRegex.find(code)
if (packageMatch != null) {
val packageName = packageMatch.groupValues[1]
val className = job.filename.substring(0, job.filename.length - extLength)
val className = job.fileSummary.filename.substring(0, job.fileSummary.filename.length - extLength)
val fullClassName = "$packageName.$className"
packageTree[fullClassName] = job
}

job.container = JavaAnalyser().analysis(code, job.location)
}

override suspend fun start(): List<Instruction> = coroutineScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WorkerManager {
)

fun addJob(job: PickJob) {
val language = job.language.toSupportLanguage()
val language = job.fileSummary.language.toSupportLanguage()
val worker = workers[language]
worker?.addJob(job)
}
Expand Down

0 comments on commit 6f5c476

Please sign in to comment.