chapi.app.analyser.JavaAnalyserApp.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chapi-application Show documentation
Show all versions of chapi-application Show documentation
Chapi is A common language meta information convertor, convert different languages to same meta-data model
package chapi.app.analyser
import chapi.app.analyser.config.ChapiConfig
import chapi.app.analyser.config.Language
import chapi.app.analyser.support.AbstractFile
import chapi.app.analyser.support.BaseAnalyser
import chapi.ast.javaast.JavaAnalyser
import chapi.domain.core.CodeDataStruct
import chapi.domain.core.DataStructType
open class JavaAnalyserApp(var config: ChapiConfig = ChapiConfig(language = Language.JAVA)) : BaseAnalyser(config) {
override fun analysisByFiles(files: Array): Array {
val basicNodes = analysisBasicInfo(files)
return analysisFullNodes(files, basicNodes)
}
override fun analysisByFile(file: AbstractFile): List {
val basicNodes = analysisBasicInfo(arrayOf(file))
return analysisFullNodes(arrayOf(file), basicNodes).toList()
}
private fun analysisFullNodes(
files: Array,
basicNodes: Array
): Array {
val identMap = HashMap()
for (node in basicNodes) {
identMap[node.getClassFullName()] = node
}
val classes = basicNodes.map { it.getClassFullName() }.toTypedArray()
return buildNodeInfos(files, classes, basicNodes)
}
private fun buildNodeInfos(
files: Array,
classes: Array,
basicNodes: Array
): Array {
return files.flatMap {
println("processing file: ${it.absolutePath}")
val codeContainer = JavaAnalyser().identFullInfo(it.content, it.fileName, classes, basicNodes)
codeContainer.DataStructures.map { ds -> ds.apply { ds.Imports = codeContainer.Imports } }
}.toTypedArray()
}
private fun analysisBasicInfo(files: Array): Array {
return files.flatMap {
val codeContainer = JavaAnalyser().identBasicInfo(it.content, it.fileName)
codeContainer.DataStructures.map { ds -> ds.apply { ds.Imports = codeContainer.Imports } }
}.toTypedArray()
}
}