FIR CLI: count lines/files and report events to perfman

This commit is contained in:
Ilya Chernikov
2022-01-31 18:57:06 +01:00
committed by teamcity
parent 090a451902
commit 973273c6c6
5 changed files with 98 additions and 34 deletions
@@ -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> {