diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/JvmBackendDiagnosticsHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/JvmBackendDiagnosticsHandler.kt index c9969ecc23f..6228f0a32e0 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/JvmBackendDiagnosticsHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/JvmBackendDiagnosticsHandler.kt @@ -5,14 +5,17 @@ package org.jetbrains.kotlin.test.backend.handlers +import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticReporter import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticReporter import org.jetbrains.kotlin.test.frontend.classic.handlers.withNewInferenceModeEnabled +import org.jetbrains.kotlin.test.frontend.fir.handlers.toMetaInfos import org.jetbrains.kotlin.test.model.BinaryArtifacts import org.jetbrains.kotlin.test.model.FrontendKinds import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.dependencyProvider +import org.jetbrains.kotlin.test.services.globalMetadataInfoHandler class JvmBackendDiagnosticsHandler(testServices: TestServices) : JvmBinaryArtifactHandler(testServices) { private val reporter = ClassicDiagnosticReporter(testServices) @@ -29,6 +32,16 @@ class JvmBackendDiagnosticsHandler(testServices: TestServices) : JvmBinaryArtifa val testFile = ktFileToTestFileMap[ktFile] ?: continue reporter.reportDiagnostic(diagnostic, module, testFile, configuration, withNewInferenceModeEnabled) } + val ktDiagnosticReporter = generationState.diagnosticReporter as BaseDiagnosticReporter + val globalMetadataInfoHandler = testServices.globalMetadataInfoHandler + for ((testFile, ktFile) in testFileToKtFileMap.entries) { + val ktDiagnostics = ktDiagnosticReporter.diagnosticsByFilePath[ktFile.virtualFilePath] ?: continue + ktDiagnostics.forEach { + val metaInfos = + it.toMetaInfos(testFile, globalMetadataInfoHandler, false, false) + globalMetadataInfoHandler.addMetadataInfosForFile(testFile, metaInfos) + } + } } override fun processAfterAllModules(someAssertionWasFailed: Boolean) {} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/ir/JvmIrBackendFacade.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/ir/JvmIrBackendFacade.kt index f0a1ce8aeea..4f01fa3a4ba 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/ir/JvmIrBackendFacade.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/ir/JvmIrBackendFacade.kt @@ -9,7 +9,9 @@ import org.jetbrains.kotlin.backend.common.BackendException import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.test.backend.classic.JavaCompilerFacade import org.jetbrains.kotlin.test.directives.CodegenTestDirectives -import org.jetbrains.kotlin.test.model.* +import org.jetbrains.kotlin.test.model.ArtifactKinds +import org.jetbrains.kotlin.test.model.BinaryArtifacts +import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.compilerConfigurationProvider diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontend2IrConverter.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontend2IrConverter.kt index 9e774194d12..6d3aa56fe01 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontend2IrConverter.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontend2IrConverter.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.codegen.ClassBuilderFactories import org.jetbrains.kotlin.codegen.CodegenFactory import org.jetbrains.kotlin.codegen.state.GenerationState +import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory import org.jetbrains.kotlin.test.backend.ir.IrBackendInput import org.jetbrains.kotlin.test.directives.CodegenTestDirectives import org.jetbrains.kotlin.test.model.BackendKinds @@ -43,6 +44,7 @@ class ClassicFrontend2IrConverter( ).codegenFactory(codegenFactory) .isIrBackend(true) .ignoreErrors(CodegenTestDirectives.IGNORE_ERRORS in module.directives) + .diagnosticReporter(DiagnosticReporterFactory.createReporter()) .build() return IrBackendInput(state, codegenFactory.convertToIr(CodegenFactory.IrConversionInput.fromGenerationState(state))) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirDiagnosticsHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirDiagnosticsHandler.kt index 0ab8487dfb0..dfedebd01e6 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirDiagnosticsHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/handlers/FirDiagnosticsHandler.kt @@ -95,7 +95,12 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes // SYNTAX errors will be reported later if (diagnostic.factory == FirErrors.SYNTAX) return@flatMap emptyList() if (!diagnostic.isValid) return@flatMap emptyList() - diagnostic.toMetaInfos(file, lightTreeEnabled, lightTreeComparingModeEnabled) + diagnostic.toMetaInfos( + file, + globalMetadataInfoHandler, + lightTreeEnabled, + lightTreeComparingModeEnabled + ) } globalMetadataInfoHandler.addMetadataInfosForFile(file, diagnosticsMetadataInfos) collectSyntaxDiagnostics(file, firFile, lightTreeEnabled, lightTreeComparingModeEnabled) @@ -103,27 +108,6 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes } } - private fun KtDiagnostic.toMetaInfos( - file: TestFile, - lightTreeEnabled: Boolean, - lightTreeComparingModeEnabled: Boolean, - forceRenderArguments: Boolean = false - ): List { - val ranges = factory.defaultPositioningStrategy.markDiagnostic(this) - return ranges.map { range -> - val metaInfo = FirDiagnosticCodeMetaInfo(this, FirMetaInfoUtils.renderDiagnosticNoArgs, range) - val shouldRenderArguments = forceRenderArguments || globalMetadataInfoHandler.getExistingMetaInfosForActualMetadata(file, metaInfo) - .any { it.description != null } - if (shouldRenderArguments) { - metaInfo.replaceRenderConfiguration(FirMetaInfoUtils.renderDiagnosticWithArgs) - } - if (lightTreeComparingModeEnabled) { - metaInfo.attributes += if (lightTreeEnabled) PsiLightTreeMetaInfoProcessor.LT else PsiLightTreeMetaInfoProcessor.PSI - } - metaInfo - } - } - @OptIn(InternalDiagnosticFactoryMethod::class) private fun collectSyntaxDiagnostics( testFile: TestFile, @@ -134,12 +118,22 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes val metaInfos = if (firFile.psi != null) { AnalyzingUtils.getSyntaxErrorRanges(firFile.psi!!).flatMap { FirErrors.SYNTAX.on(KtRealPsiSourceElement(it), positioningStrategy = null) - .toMetaInfos(testFile, lightTreeEnabled, lightTreeComparingModeEnabled) + .toMetaInfos( + testFile, + globalMetadataInfoHandler1 = globalMetadataInfoHandler, + lightTreeEnabled, + lightTreeComparingModeEnabled + ) } } else { collectLightTreeSyntaxErrors(firFile).flatMap { sourceElement -> FirErrors.SYNTAX.on(sourceElement, positioningStrategy = null) - .toMetaInfos(testFile, lightTreeEnabled, lightTreeComparingModeEnabled) + .toMetaInfos( + testFile, + globalMetadataInfoHandler1 = globalMetadataInfoHandler, + lightTreeEnabled, + lightTreeComparingModeEnabled + ) } } @@ -195,7 +189,13 @@ class FirDiagnosticsHandler(testServices: TestServices) : FirAnalysisHandler(tes }.let(firFile::accept) globalMetadataInfoHandler.addMetadataInfosForFile( testFile, - result.flatMap { it.toMetaInfos(testFile, lightTreeEnabled, lightTreeComparingModeEnabled, forceRenderArguments = true) } + result.flatMap { it.toMetaInfos( + testFile, + globalMetadataInfoHandler, + lightTreeEnabled, + lightTreeComparingModeEnabled, + forceRenderArguments = true + ) } ) } @@ -344,3 +344,22 @@ class PsiLightTreeMetaInfoProcessor(testServices: TestServices) : AbstractTwoAtt } } +fun KtDiagnostic.toMetaInfos( + file: TestFile, + globalMetadataInfoHandler1: GlobalMetadataInfoHandler, + lightTreeEnabled: Boolean, + lightTreeComparingModeEnabled: Boolean, + forceRenderArguments: Boolean = false +): List = textRanges.map { range -> + val metaInfo = FirDiagnosticCodeMetaInfo(this, FirMetaInfoUtils.renderDiagnosticNoArgs, range) + val shouldRenderArguments = forceRenderArguments || globalMetadataInfoHandler1.getExistingMetaInfosForActualMetadata(file, metaInfo) + .any { it.description != null } + if (shouldRenderArguments) { + metaInfo.replaceRenderConfiguration(FirMetaInfoUtils.renderDiagnosticWithArgs) + } + if (lightTreeComparingModeEnabled) { + metaInfo.attributes += if (lightTreeEnabled) PsiLightTreeMetaInfoProcessor.LT else PsiLightTreeMetaInfoProcessor.PSI + } + metaInfo +} +