org.archguard.scanner.analyser.GoAnalyser.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lang_golang Show documentation
Show all versions of lang_golang 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.channels.Channel
import kotlinx.coroutines.runBlocking
import org.archguard.scanner.core.sourcecode.LanguageSourceCodeAnalyser
import org.archguard.scanner.core.sourcecode.SourceCodeContext
import java.io.File
class GoAnalyser(override val context: SourceCodeContext) : LanguageSourceCodeAnalyser {
private val client = context.client
private val impl = chapi.ast.goast.GoAnalyser()
private val logger = org.slf4j.LoggerFactory.getLogger(this.javaClass)
override fun analyse(): List = runBlocking {
getFilesByPath(context.path) {
it.absolutePath.endsWith(".go")
}
.map { async { analysisByFile(it) } }.awaitAll()
.flatten()
.also { client.saveDataStructure(it) }
}
private fun analysisByFile(file: File): List {
logger.info("analysis file: ${file.absolutePath}")
val content = file.readContent()
val lines = content.lines()
val codeContainer = impl.analysis(content, file.name)
return codeContainer.DataStructures.map { ds ->
ds.apply {
ds.Imports = codeContainer.Imports
ds.FilePath = file.absolutePath
if (context.withFunctionCode) {
ds.Content = contentByPosition(lines, ds.Position)
ds.Functions.map { it.apply { it.Content = contentByPosition(lines, it.Position) } }
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy