[FIR] Properly generate IDE diagnostics from multiple diagnostics lists

This commit is contained in:
Dmitriy Novozhilov
2021-05-20 13:00:51 +03:00
committed by teamcityserver
parent 09e3629d5d
commit a1ae108ce5
25 changed files with 107 additions and 52 deletions
+1
View File
@@ -69,6 +69,7 @@ dependencies {
compile(project(":compiler:fir:fir2ir"))
compile(project(":compiler:fir:resolve"))
compile(project(":compiler:fir:checkers"))
compile(project(":compiler:fir:checkers:checkers.jvm"))
compile(project(":compiler:fir:java"))
compile(project(":compiler:fir:jvm"))
compile(project(":idea:idea-core"))
+1
View File
@@ -24,6 +24,7 @@ dependencies {
compile(project(":compiler:fir:fir2ir"))
compile(project(":compiler:fir:resolve"))
compile(project(":compiler:fir:checkers"))
compile(project(":compiler:fir:checkers:checkers.jvm"))
compile(project(":compiler:fir:java"))
compile(project(":compiler:fir:jvm"))
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false }
@@ -15,25 +15,8 @@ import java.nio.file.Path
object DiagnosticClassGenerator {
fun generate(rootPath: Path, diagnosticList: DiagnosticList, packageName: String) {
val path = getGenerationPath(rootPath.toFile(), packageName)
KtDiagnosticClassRenderer.render(
path.resolve("KtFirDiagnostics.kt"),
diagnosticList,
packageName,
"KtFirDiagnostics"
)
KtDiagnosticClassImplementationRenderer.render(
path.resolve("KtFirDiagnosticsImpl.kt"),
diagnosticList,
packageName,
"KtFirDiagnosticsImpl"
)
FirDiagnosticToKtDiagnosticConverterRenderer.render(
path.resolve("KtFirDataClassConverters.kt"),
diagnosticList,
packageName,
"KtFirDataClassConverters"
)
KtDiagnosticClassRenderer.render(path.resolve("KtFirDiagnostics.kt"), diagnosticList, packageName)
KtDiagnosticClassImplementationRenderer.render(path.resolve("KtFirDiagnosticsImpl.kt"), diagnosticList, packageName)
FirDiagnosticToKtDiagnosticConverterRenderer.render(path.resolve("KtFirDataClassConverters.kt"), diagnosticList, packageName)
}
}
@@ -6,10 +6,11 @@
package org.jetbrains.kotlin.idea.frontend.api.fir.generator
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.DIAGNOSTICS_LIST
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.JVM_DIAGNOSTICS_LIST
import java.nio.file.Paths
fun main() {
val rootPath = Paths.get("idea/idea-frontend-fir/src").toAbsolutePath()
val packageName = "org.jetbrains.kotlin.idea.frontend.api.fir.diagnostics"
DiagnosticClassGenerator.generate(rootPath, DIAGNOSTICS_LIST, packageName)
}
DiagnosticClassGenerator.generate(rootPath, DIAGNOSTICS_LIST + JVM_DIAGNOSTICS_LIST, packageName)
}
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.util.SmartPrinter
import java.io.File
abstract class AbstractDiagnosticsDataClassRenderer : DiagnosticListRenderer() {
override fun render(file: File, diagnosticList: DiagnosticList, packageName: String, containingObjectName: String) {
override fun render(file: File, diagnosticList: DiagnosticList, packageName: String) {
val hlDiagnosticsList = HLDiagnosticConverter.convert(diagnosticList)
file.writeToFileUsingSmartPrinterIfFileContentChanged { render(hlDiagnosticsList, packageName) }
}
@@ -25,7 +25,7 @@ object FirDiagnosticToKtDiagnosticConverterRenderer : AbstractDiagnosticsDataCla
}
private fun SmartPrinter.printConverter(diagnostic: HLDiagnostic) {
println("add(FirErrors.${diagnostic.original.name}) { firDiagnostic ->")
println("add(${diagnostic.original.containingObjectName}.${diagnostic.original.name}) { firDiagnostic ->")
withIndent {
println("${diagnostic.implClassName}(")
withIndent {
@@ -63,5 +63,6 @@ object FirDiagnosticToKtDiagnosticConverterRenderer : AbstractDiagnosticsDataCla
override val defaultImports = listOf(
"org.jetbrains.kotlin.fir.analysis.diagnostics.FirPsiDiagnostic",
"org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors",
"org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors",
)
}
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiTypeElement
import com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirPsiDiagnostic
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
@@ -2490,4 +2491,10 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirJvmErrors.CONFLICTING_JVM_DECLARATIONS) { firDiagnostic ->
ConflictingJvmDeclarationsImpl(
firDiagnostic as FirPsiDiagnostic<*>,
token,
)
}
}
@@ -1743,4 +1743,8 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
abstract val symbol: KtSymbol
}
abstract class ConflictingJvmDeclarations : KtFirDiagnostic<PsiElement>() {
override val diagnosticClass get() = ConflictingJvmDeclarations::class
}
}
@@ -2833,3 +2833,10 @@ internal class SuperCallFromPublicInlineImpl(
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
}
internal class ConflictingJvmDeclarationsImpl(
firDiagnostic: FirPsiDiagnostic<*>,
override val token: ValidityToken,
) : KtFirDiagnostic.ConflictingJvmDeclarations(), KtAbstractFirDiagnostic<PsiElement> {
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
}