From a1ae108ce5dd5a4ae714e533ecb79bffa3e3d0ba Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 20 May 2021 13:00:51 +0300 Subject: [PATCH] [FIR] Properly generate IDE diagnostics from multiple diagnostics lists --- build.gradle.kts | 1 + compiler/cli/build.gradle.kts | 1 + compiler/fir/analysis-tests/build.gradle.kts | 1 + .../legacy-fir-tests/build.gradle.kts | 1 + .../kotlin/fir/checkers/generator/Main.kt | 6 +-- .../diagnostics/FirDiagnosticsList.kt | 10 ++--- .../diagnostics/FirJvmDiagnosticsList.kt | 2 +- .../diagnostics/model/DiagnosticData.kt | 1 + .../diagnostics/model/DiagnosticGroup.kt | 22 ++++++++--- .../diagnostics/model/DiagnosticList.kt | 37 +++++++++++++++++-- .../model/DiagnosticListGenerator.kt | 7 ++-- .../model/DiagnosticListRenderer.kt | 2 +- .../model/ErrorListDiagnosticListRenderer.kt | 12 +++--- compiler/tests-common/build.gradle.kts | 1 + idea/build.gradle.kts | 1 + idea/idea-core/build.gradle.kts | 1 + .../fir/generator/DiagnosticClassGenerator.kt | 23 ++---------- .../idea/frontend/api/fir/generator/Main.kt | 5 ++- .../AbstractDiagnosticsDataClassRenderer.kt | 2 +- ...agnosticToKtDiagnosticConverterRenderer.kt | 3 +- .../diagnostics/KtFirDataClassConverters.kt | 7 ++++ .../api/fir/diagnostics/KtFirDiagnostics.kt | 4 ++ .../fir/diagnostics/KtFirDiagnosticsImpl.kt | 7 ++++ .../fir/fir-plugin-prototype/build.gradle.kts | 1 + prepare/idea-plugin/build.gradle.kts | 1 + 25 files changed, 107 insertions(+), 52 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c9797181d48..3903debc168 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -297,6 +297,7 @@ extra["compilerModules"] = arrayOf( ":compiler:fir:java", ":compiler:fir:jvm", ":compiler:fir:checkers", + ":compiler:fir:checkers:checkers.jvm", ":compiler:fir:entrypoint", ":compiler:fir:analysis-tests", ":compiler:fir:analysis-tests:legacy-fir-tests", diff --git a/compiler/cli/build.gradle.kts b/compiler/cli/build.gradle.kts index e9860cdf637..83489d0bdf4 100644 --- a/compiler/cli/build.gradle.kts +++ b/compiler/cli/build.gradle.kts @@ -30,6 +30,7 @@ dependencies { compile(project(":compiler:fir:fir2ir")) compile(project(":compiler:fir:fir2ir:jvm-backend")) compile(project(":compiler:fir:checkers")) + compile(project(":compiler:fir:checkers:checkers.jvm")) compile(project(":kotlin-util-klib")) compile(project(":kotlin-util-io")) diff --git a/compiler/fir/analysis-tests/build.gradle.kts b/compiler/fir/analysis-tests/build.gradle.kts index ee8f76f6360..46a15239c0e 100644 --- a/compiler/fir/analysis-tests/build.gradle.kts +++ b/compiler/fir/analysis-tests/build.gradle.kts @@ -20,6 +20,7 @@ dependencies { testApi(projectTests(":compiler:tests-common-new")) testApi(project(":compiler:cli")) testApi(project(":compiler:fir:checkers")) + testApi(project(":compiler:fir:checkers:checkers.jvm")) testApi(project(":compiler:fir:fir-serialization")) testApi(project(":compiler:fir:entrypoint")) testApi(project(":compiler:frontend")) diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/build.gradle.kts b/compiler/fir/analysis-tests/legacy-fir-tests/build.gradle.kts index b20a8328451..0f3003c503c 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/build.gradle.kts +++ b/compiler/fir/analysis-tests/legacy-fir-tests/build.gradle.kts @@ -20,6 +20,7 @@ dependencies { testCompileOnly(project(":kotlin-test:kotlin-test-junit")) testApi(projectTests(":compiler:tests-common")) testApi(project(":compiler:fir:checkers")) + testApi(project(":compiler:fir:checkers:checkers.jvm")) testApi(project(":compiler:fir:entrypoint")) testApi(project(":compiler:frontend")) diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt index aa74354bc66..f622f90e231 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt @@ -6,7 +6,7 @@ package org.jetbrains.kotlin.fir.checkers.generator import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.DIAGNOSTICS_LIST -import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.FIR_JVM_DIAGNOSTICS_LIST +import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.JVM_DIAGNOSTICS_LIST import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.generateDiagnostics import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.expressions.* @@ -75,8 +75,8 @@ fun main(args: Array) { val jvmGenerationPath = File(arguments.getOrElse(1) { "compiler/fir/checkers/checkers.jvm/gen" }) - generateDiagnostics(generationPath, "$basePackage.diagnostics", "FirErrors", DIAGNOSTICS_LIST) - generateDiagnostics(jvmGenerationPath, "$basePackage.diagnostics.jvm", "FirJvmErrors", FIR_JVM_DIAGNOSTICS_LIST) + generateDiagnostics(generationPath, "$basePackage.diagnostics", DIAGNOSTICS_LIST) + generateDiagnostics(jvmGenerationPath, "$basePackage.diagnostics.jvm", JVM_DIAGNOSTICS_LIST) } /* diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index 537d04d1788..938c9e83588 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -30,7 +30,7 @@ import kotlin.properties.ReadOnlyProperty @Suppress("UNUSED_VARIABLE", "LocalVariableName", "ClassName", "unused") @OptIn(PrivateForInline::class) -object DIAGNOSTICS_LIST : DiagnosticList() { +object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { val MetaErrors by object : DiagnosticGroup("Meta-errors") { val UNSUPPORTED by error { parameter("unsupported") @@ -908,15 +908,15 @@ private val exposedVisibilityDiagnosticInit: DiagnosticBuilder.() -> Unit = { parameter("restrictingVisibility") } -private inline fun DiagnosticGroup.exposedVisibilityError( +private inline fun AbstractDiagnosticGroup.exposedVisibilityError( positioningStrategy: PositioningStrategy = PositioningStrategy.DEFAULT -): PropertyDelegateProvider> { +): PropertyDelegateProvider> { return error

(positioningStrategy, exposedVisibilityDiagnosticInit) } -private inline fun DiagnosticGroup.exposedVisibilityWarning( +private inline fun AbstractDiagnosticGroup.exposedVisibilityWarning( positioningStrategy: PositioningStrategy = PositioningStrategy.DEFAULT -): PropertyDelegateProvider> { +): PropertyDelegateProvider> { return warning

(positioningStrategy, exposedVisibilityDiagnosticInit) } diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJvmDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJvmDiagnosticsList.kt index 68a10b5851f..7677263e36c 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJvmDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirJvmDiagnosticsList.kt @@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.* @Suppress("UNUSED_VARIABLE", "LocalVariableName", "ClassName", "unused") @OptIn(PrivateForInline::class) -object FIR_JVM_DIAGNOSTICS_LIST : DiagnosticList() { +object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") { val DECLARATIONS by object : DiagnosticGroup("Declarations") { val CONFLICTING_JVM_DECLARATIONS by error() } diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticData.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticData.kt index 9cfd78324ee..98c3a3631aa 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticData.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticData.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.diagnostics.Severity import kotlin.reflect.KType data class DiagnosticData( + val containingObjectName: String, val severity: Severity, val name: String, val psiType: KType, diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticGroup.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticGroup.kt index c3aeb2ca70a..3c003a905ad 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticGroup.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticGroup.kt @@ -12,7 +12,7 @@ import kotlin.properties.PropertyDelegateProvider import kotlin.properties.ReadOnlyProperty import kotlin.reflect.typeOf -abstract class DiagnosticGroup @PrivateForInline constructor(val name: String) { +abstract class AbstractDiagnosticGroup @PrivateForInline constructor(val name: String, internal val containingObjectName: String) { @Suppress("PropertyName") @PrivateForInline val _diagnostics = mutableListOf() @@ -22,26 +22,27 @@ abstract class DiagnosticGroup @PrivateForInline constructor(val name: String) { get() = _diagnostics @OptIn(PrivateForInline::class) - inline fun error( + internal inline fun error( positioningStrategy: PositioningStrategy = PositioningStrategy.DEFAULT, crossinline init: DiagnosticBuilder.() -> Unit = {} ) = diagnosticDelegateProvider

(Severity.ERROR, positioningStrategy, init) @OptIn(PrivateForInline::class) - inline fun warning( + internal inline fun warning( positioningStrategy: PositioningStrategy = PositioningStrategy.DEFAULT, crossinline init: DiagnosticBuilder.() -> Unit = {} ) = diagnosticDelegateProvider

(Severity.WARNING, positioningStrategy, init) @PrivateForInline @OptIn(ExperimentalStdlibApi::class) - inline fun diagnosticDelegateProvider( + internal inline fun diagnosticDelegateProvider( severity: Severity, positioningStrategy: PositioningStrategy, crossinline init: DiagnosticBuilder.() -> Unit = {} - ) = PropertyDelegateProvider> { _, property -> + ) = PropertyDelegateProvider> { _, property -> val diagnostic = DiagnosticBuilder( + containingObjectName, severity, name = property.name, psiType = typeOf

(), @@ -50,4 +51,15 @@ abstract class DiagnosticGroup @PrivateForInline constructor(val name: String) { _diagnostics += diagnostic ReadOnlyProperty { _, _ -> diagnostic } } + + @OptIn(PrivateForInline::class) + operator fun plus(other: AbstractDiagnosticGroup): AbstractDiagnosticGroup { + require(name == other.name) + return object : AbstractDiagnosticGroup(name, "#Stub") { + init { + _diagnostics.addAll(this.diagnostics) + _diagnostics.addAll(other.diagnostics) + } + } + } } diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticList.kt index 18d15054b64..86325b200f0 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticList.kt @@ -12,15 +12,16 @@ import kotlin.reflect.KProperty import kotlin.reflect.KType import kotlin.reflect.typeOf -abstract class DiagnosticList { +abstract class DiagnosticList(internal val objectName: String) { @Suppress("PropertyName") @PrivateForInline - val _groups = mutableListOf() + val _groups = mutableListOf() @OptIn(PrivateForInline::class) - val groups: List + val groups: List get() = _groups + @OptIn(PrivateForInline::class) val allDiagnostics: List get() = groups.flatMap { it.diagnostics } @@ -34,9 +35,38 @@ abstract class DiagnosticList { _groups += group return ReadOnlyProperty { _, _ -> group } } + + @OptIn(PrivateForInline::class) + operator fun plus(other: DiagnosticList): DiagnosticList { + val groupsByName = mutableMapOf>() + + fun collect(groups: List) { + for (group in groups) { + val list = groupsByName.getOrPut(group.name) { mutableListOf() } + list += group + } + } + + collect(groups) + collect(other.groups) + + val resultingGroups = groupsByName.values.map { + it.reduce { acc, group -> acc + group } + } + + return object : DiagnosticList("#Stub") { + init { + _groups.addAll(resultingGroups) + } + } + } + + @PrivateForInline + abstract inner class DiagnosticGroup(name: String) : AbstractDiagnosticGroup(name, objectName) } class DiagnosticBuilder( + private val containingObjectName: String, private val severity: Severity, private val name: String, private val psiType: KType, @@ -58,6 +88,7 @@ class DiagnosticBuilder( @OptIn(PrivateForInline::class) fun build() = DiagnosticData( + containingObjectName, severity, name, psiType, diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticListGenerator.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticListGenerator.kt index 69ce40c21bb..e0fe19c3516 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticListGenerator.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticListGenerator.kt @@ -8,12 +8,11 @@ package org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model import org.jetbrains.kotlin.fir.checkers.generator.getGenerationPath import java.io.File -fun generateDiagnostics(rootPath: File, packageName: String, containingObjectName: String, diagnosticList: DiagnosticList) { +fun generateDiagnostics(rootPath: File, packageName: String, diagnosticList: DiagnosticList) { val generationPath = getGenerationPath(rootPath, packageName) ErrorListDiagnosticListRenderer.render( - generationPath.resolve("$containingObjectName.kt"), + generationPath.resolve("${diagnosticList.objectName}.kt"), diagnosticList, - packageName, - containingObjectName + packageName ) } diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticListRenderer.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticListRenderer.kt index 52e73d8b613..df2c4a73a96 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticListRenderer.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/DiagnosticListRenderer.kt @@ -8,5 +8,5 @@ package org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model import java.io.File abstract class DiagnosticListRenderer { - abstract fun render(file: File, diagnosticList: DiagnosticList, packageName: String, containingObjectName: String) + abstract fun render(file: File, diagnosticList: DiagnosticList, packageName: String) } diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/ErrorListDiagnosticListRenderer.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/ErrorListDiagnosticListRenderer.kt index 10ecfd33e8c..b5b965013d2 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/ErrorListDiagnosticListRenderer.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/ErrorListDiagnosticListRenderer.kt @@ -18,23 +18,23 @@ import kotlin.reflect.KTypeProjection object ErrorListDiagnosticListRenderer : DiagnosticListRenderer() { private const val BASE_PACKAGE = "org.jetbrains.kotlin.fir.analysis.diagnostics" - override fun render(file: File, diagnosticList: DiagnosticList, packageName: String, containingObjectName: String) { + override fun render(file: File, diagnosticList: DiagnosticList, packageName: String) { file.writeToFileUsingSmartPrinterIfFileContentChanged { - render(diagnosticList, packageName, containingObjectName) + render(diagnosticList, packageName) } } - private fun SmartPrinter.render(diagnosticList: DiagnosticList, packageName: String, containingObjectName: String) { + private fun SmartPrinter.render(diagnosticList: DiagnosticList, packageName: String) { printCopyright() println("package $packageName") println() collectAndPrintImports(diagnosticList, packageName) printGeneratedMessage() - printErrorsObject(diagnosticList, containingObjectName) + printErrorsObject(diagnosticList) } - private fun SmartPrinter.printErrorsObject(diagnosticList: DiagnosticList, containingObjectName: String) { - inBracketsWithIndent("object $containingObjectName") { + private fun SmartPrinter.printErrorsObject(diagnosticList: DiagnosticList) { + inBracketsWithIndent("object ${diagnosticList.objectName}") { for (group in diagnosticList.groups) { printDiagnosticGroup(group.name, group.diagnostics) println() diff --git a/compiler/tests-common/build.gradle.kts b/compiler/tests-common/build.gradle.kts index 19d17c4f937..bd14fe79e9b 100644 --- a/compiler/tests-common/build.gradle.kts +++ b/compiler/tests-common/build.gradle.kts @@ -25,6 +25,7 @@ dependencies { testCompile(project(":compiler:fir:cones")) testCompile(project(":compiler:fir:resolve")) testCompile(project(":compiler:fir:checkers")) + testCompile(project(":compiler:fir:checkers:checkers.jvm")) testCompile(project(":compiler:fir:java")) testCompile(project(":compiler:fir:entrypoint")) testCompile(project(":compiler:ir.ir2cfg")) diff --git a/idea/build.gradle.kts b/idea/build.gradle.kts index 95803164929..0b1948b01af 100644 --- a/idea/build.gradle.kts +++ b/idea/build.gradle.kts @@ -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")) diff --git a/idea/idea-core/build.gradle.kts b/idea/idea-core/build.gradle.kts index 44f2f32f36b..d5998d0deac 100644 --- a/idea/idea-core/build.gradle.kts +++ b/idea/idea-core/build.gradle.kts @@ -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 } diff --git a/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/DiagnosticClassGenerator.kt b/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/DiagnosticClassGenerator.kt index f8db34c204d..14e81d6745b 100644 --- a/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/DiagnosticClassGenerator.kt +++ b/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/DiagnosticClassGenerator.kt @@ -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) } } diff --git a/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/Main.kt b/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/Main.kt index 1f22e2cf8f7..f7e4b64122d 100644 --- a/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/Main.kt +++ b/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/Main.kt @@ -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) -} \ No newline at end of file + DiagnosticClassGenerator.generate(rootPath, DIAGNOSTICS_LIST + JVM_DIAGNOSTICS_LIST, packageName) +} diff --git a/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/rendererrs/AbstractDiagnosticsDataClassRenderer.kt b/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/rendererrs/AbstractDiagnosticsDataClassRenderer.kt index dfcd9c69e83..9ab9079d8c0 100644 --- a/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/rendererrs/AbstractDiagnosticsDataClassRenderer.kt +++ b/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/rendererrs/AbstractDiagnosticsDataClassRenderer.kt @@ -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) } } diff --git a/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/rendererrs/FirDiagnosticToKtDiagnosticConverterRenderer.kt b/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/rendererrs/FirDiagnosticToKtDiagnosticConverterRenderer.kt index 1d6f2f6982b..6072d043930 100644 --- a/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/rendererrs/FirDiagnosticToKtDiagnosticConverterRenderer.kt +++ b/idea/idea-frontend-fir/idea-frontend-fir-generator/src/org/jetbrains/kotlin/idea/frontend/api/fir/generator/rendererrs/FirDiagnosticToKtDiagnosticConverterRenderer.kt @@ -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", ) } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt index a48313ef676..942921e1955 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -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, + ) + } } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt index 790bec74624..c0acc1b858a 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt @@ -1743,4 +1743,8 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { abstract val symbol: KtSymbol } + abstract class ConflictingJvmDeclarations : KtFirDiagnostic() { + override val diagnosticClass get() = ConflictingJvmDeclarations::class + } + } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index 998d4d239c0..91d911e6fca 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -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 { + override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) +} + diff --git a/plugins/fir/fir-plugin-prototype/build.gradle.kts b/plugins/fir/fir-plugin-prototype/build.gradle.kts index a8b40c9c9f0..7bd2f0ef59a 100644 --- a/plugins/fir/fir-plugin-prototype/build.gradle.kts +++ b/plugins/fir/fir-plugin-prototype/build.gradle.kts @@ -20,6 +20,7 @@ dependencies { testCompileOnly(project(":kotlin-test:kotlin-test-junit")) testCompile(projectTests(":compiler:tests-common")) testCompile(project(":compiler:fir:checkers")) + testCompile(project(":compiler:fir:checkers:checkers.jvm")) testCompile(projectTests(":compiler:fir:analysis-tests:legacy-fir-tests")) testCompile(project(":compiler:frontend")) diff --git a/prepare/idea-plugin/build.gradle.kts b/prepare/idea-plugin/build.gradle.kts index 44d58c682b5..eb0bafb1523 100644 --- a/prepare/idea-plugin/build.gradle.kts +++ b/prepare/idea-plugin/build.gradle.kts @@ -46,6 +46,7 @@ val projectsToShadow by extra(listOf( ":compiler:psi", ":compiler:fir:cones", ":compiler:fir:checkers", + ":compiler:fir:checkers:checkers.jvm", ":compiler:fir:entrypoint", ":compiler:fir:resolve", ":compiler:fir:fir-serialization",