FIR IDE: do not remove duplicated diagnostics

This hides the real problem why diagnostics are duplicated
This commit is contained in:
Ilya Kirillov
2021-04-12 12:28:36 +02:00
parent 77ae1fa1f2
commit d438d2db40
5 changed files with 22 additions and 14 deletions
@@ -6,10 +6,12 @@
package org.jetbrains.kotlin.checkers package org.jetbrains.kotlin.checkers
import com.intellij.rt.execution.junit.FileComparisonFailure import com.intellij.rt.execution.junit.FileComparisonFailure
import org.jetbrains.kotlin.idea.highlighter.AbstractHighlightingTest
import org.jetbrains.kotlin.idea.invalidateCaches import org.jetbrains.kotlin.idea.invalidateCaches
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
import org.jetbrains.kotlin.idea.withPossiblyDisabledDuplicatedFirSourceElementsException import org.jetbrains.kotlin.idea.withPossiblyDisabledDuplicatedFirSourceElementsException
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.uitls.IgnoreTests import org.jetbrains.kotlin.test.uitls.IgnoreTests
import org.jetbrains.kotlin.test.uitls.IgnoreTests.DIRECTIVES import org.jetbrains.kotlin.test.uitls.IgnoreTests.DIRECTIVES
import org.jetbrains.kotlin.test.uitls.IgnoreTests.cleanUpIdenticalFirTestFile import org.jetbrains.kotlin.test.uitls.IgnoreTests.cleanUpIdenticalFirTestFile
@@ -45,14 +47,20 @@ abstract class AbstractFirKotlinHighlightingPassTest : AbstractKotlinHighlightin
checkWeakWarnings: Boolean checkWeakWarnings: Boolean
): Long { ): Long {
val fileText = file.text val fileText = file.text
return withCustomCompilerOptions(fileText, project, module) { val isDuplicatedHighlightingExpected =
try { InTextDirectivesUtils.isDirectiveDefined(fileText, AbstractHighlightingTest.EXPECTED_DUPLICATED_HIGHLIGHTING_PREFIX)
withPossiblyDisabledDuplicatedFirSourceElementsException(fileText) { var result: Long? = null
myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings) AbstractHighlightingTest.withExpectedDuplicatedHighlighting(isDuplicatedHighlightingExpected, /*isFirPlugin*/true) {
withCustomCompilerOptions(fileText, project, module) {
try {
withPossiblyDisabledDuplicatedFirSourceElementsException(fileText) {
result = myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings)
}
} catch (e: FileComparisonFailure) {
throw FileComparisonFailure(e.message, e.expected, e.actual, File(e.filePath).absolutePath)
} }
} catch (e: FileComparisonFailure) {
throw FileComparisonFailure(e.message, e.expected, e.actual, File(e.filePath).absolutePath)
} }
} }
return result!!
} }
} }
@@ -64,12 +64,12 @@ internal class FileStructure(
fun getAllDiagnosticsForFile(diagnosticCheckerFilter: DiagnosticCheckerFilter): Collection<FirPsiDiagnostic<*>> { fun getAllDiagnosticsForFile(diagnosticCheckerFilter: DiagnosticCheckerFilter): Collection<FirPsiDiagnostic<*>> {
val structureElements = getAllStructureElements() val structureElements = getAllStructureElements()
return buildSet { return buildList {
collectDiagnosticsFromStructureElements(structureElements, diagnosticCheckerFilter) collectDiagnosticsFromStructureElements(structureElements, diagnosticCheckerFilter)
} }
} }
private fun MutableSet<FirPsiDiagnostic<*>>.collectDiagnosticsFromStructureElements( private fun MutableCollection<FirPsiDiagnostic<*>>.collectDiagnosticsFromStructureElements(
structureElements: Collection<FileStructureElement>, structureElements: Collection<FileStructureElement>,
diagnosticCheckerFilter: DiagnosticCheckerFilter diagnosticCheckerFilter: DiagnosticCheckerFilter
) { ) {
+2 -2
View File
@@ -1,4 +1,4 @@
// EXPECTED_DUPLICATED_HIGHLIGHTING
open class NoC open class NoC
class NoC1 : NoC() class NoC1 : NoC()
@@ -18,7 +18,7 @@ class WithPC1(a : Int) {
} }
class Foo() : WithPC0(), <error descr="Type expected"><error descr="[SYNTAX] Syntax error">this</error></error>() { class Foo() : WithPC0(), <error descr="Type expected"><error descr="[SYNTAX] Syntax error"><error descr="[SYNTAX] Syntax error">this</error></error></error>() {
} }
+1 -1
View File
@@ -1,4 +1,4 @@
// EXPECTED_DUPLICATED_HIGHLIGHTING
open class NoC open class NoC
class NoC1 : NoC() class NoC1 : NoC()
@@ -39,7 +39,7 @@ public abstract class AbstractHighlightingTest extends KotlinLightCodeInsightFix
myFixture.configureByFile(fileName()); myFixture.configureByFile(fileName());
withExpectedDuplicatedHighlighting(expectedDuplicatedHighlighting, () -> { withExpectedDuplicatedHighlighting(expectedDuplicatedHighlighting, isFirPlugin(), () -> {
try { try {
checkHighlighting(fileText); checkHighlighting(fileText);
} }
@@ -54,7 +54,7 @@ public abstract class AbstractHighlightingTest extends KotlinLightCodeInsightFix
}); });
} }
private void withExpectedDuplicatedHighlighting(boolean expectedDuplicatedHighlighting, Runnable runnable) { public static void withExpectedDuplicatedHighlighting(boolean expectedDuplicatedHighlighting, boolean isFirPlugin, Runnable runnable) {
if (!expectedDuplicatedHighlighting) { if (!expectedDuplicatedHighlighting) {
runnable.run(); runnable.run();
return; return;
@@ -63,7 +63,7 @@ public abstract class AbstractHighlightingTest extends KotlinLightCodeInsightFix
try { try {
ExpectedHighlightingData.expectedDuplicatedHighlighting(runnable); ExpectedHighlightingData.expectedDuplicatedHighlighting(runnable);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
if (isFirPlugin()) { if (isFirPlugin) {
runnable.run(); runnable.run();
} else { } else {
throw e; throw e;