org.archguard.scanner.analyser.ScalaAnalyser.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lang_scala Show documentation
Show all versions of lang_scala Show documentation
ArchGuard is a architecture governance tool which can analysis architecture in container, component, code level, create architecture fitness functions, and anaysis system dependencies..
package org.archguard.scanner.analyser
import chapi.domain.core.CodeDataStruct
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import org.archguard.scanner.core.sourcecode.LanguageSourceCodeAnalyser
import org.archguard.scanner.core.sourcecode.SourceCodeContext
import java.io.File
class ScalaAnalyser(override val context: SourceCodeContext) : LanguageSourceCodeAnalyser {
private val client = context.client
private val impl = chapi.ast.scalaast.ScalaAnalyser()
override fun analyse(): List = runBlocking {
getFilesByPath(context.path) {
it.absolutePath.endsWith(".scala")
}
.map { async { analysisByFile(it) } }.awaitAll()
.flatten()
.also { client.saveDataStructure(it) }
}
private fun analysisByFile(file: File): List {
val codeContainer = impl.analysis(file.readContent(), file.name)
return codeContainer.DataStructures.map {
it.apply {
it.Imports = codeContainer.Imports
it.FilePath = file.absolutePath
}
}
}
}