FIR CLI: count lines/files and report events to perfman
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.pipeline
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.CharsetToolkit
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.builder.PsiHandlingMode
|
||||
@@ -17,16 +19,28 @@ import org.jetbrains.kotlin.fir.session.sourcesToPathsMapper
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import java.io.File
|
||||
|
||||
fun FirSession.buildFirViaLightTree(files: Collection<File>, diagnosticsReporter: DiagnosticReporter? = null): List<FirFile> {
|
||||
fun FirSession.buildFirViaLightTree(
|
||||
files: Collection<File>,
|
||||
diagnosticsReporter: DiagnosticReporter? = null,
|
||||
reportFilesAndLines: ((Int, Int) -> Unit)? = null
|
||||
): List<FirFile> {
|
||||
val firProvider = (firProvider as FirProviderImpl)
|
||||
val sourcesToPathsMapper = sourcesToPathsMapper
|
||||
val builder = LightTree2Fir(this, firProvider.kotlinScopeProvider, diagnosticsReporter)
|
||||
return files.map {
|
||||
builder.buildFirFile(it).also { firFile ->
|
||||
val shouldCountLines = (reportFilesAndLines != null)
|
||||
var linesCount = 0
|
||||
val firFiles = files.map { file ->
|
||||
val code = FileUtil.loadFile(file, CharsetToolkit.UTF8, true /* code below relies on conversion */)
|
||||
if (shouldCountLines) {
|
||||
linesCount += code.count { it == '\n' } // assuming converted line separators
|
||||
}
|
||||
builder.buildFirFile(code, file.name, file.path).also { firFile ->
|
||||
firProvider.recordFile(firFile)
|
||||
sourcesToPathsMapper.registerFileSource(firFile.source!!, it.path)
|
||||
sourcesToPathsMapper.registerFileSource(firFile.source!!, file.path)
|
||||
}
|
||||
}
|
||||
reportFilesAndLines?.invoke(files.count(), linesCount)
|
||||
return firFiles
|
||||
}
|
||||
|
||||
fun FirSession.buildFirFromKtFiles(ktFiles: Collection<KtFile>): List<FirFile> {
|
||||
|
||||
Reference in New Issue
Block a user