All Downloads are FREE. Search and download functionalities are using the official Maven repository.

chapi.app.analyser.JavaAnalyserApp.kt Maven / Gradle / Ivy

Go to download

Chapi is A common language meta information convertor, convert different languages to same meta-data model

There is a newer version: 1.5.10
Show newest version
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()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy