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
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.test.withCustomCompilerOptions
import org.jetbrains.kotlin.idea.withPossiblyDisabledDuplicatedFirSourceElementsException
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.DIRECTIVES
import org.jetbrains.kotlin.test.uitls.IgnoreTests.cleanUpIdenticalFirTestFile
@@ -45,14 +47,20 @@ abstract class AbstractFirKotlinHighlightingPassTest : AbstractKotlinHighlightin
checkWeakWarnings: Boolean
): Long {
val fileText = file.text
return withCustomCompilerOptions(fileText, project, module) {
try {
withPossiblyDisabledDuplicatedFirSourceElementsException(fileText) {
myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings)
val isDuplicatedHighlightingExpected =
InTextDirectivesUtils.isDirectiveDefined(fileText, AbstractHighlightingTest.EXPECTED_DUPLICATED_HIGHLIGHTING_PREFIX)
var result: Long? = null
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<*>> {
val structureElements = getAllStructureElements()
return buildSet {
return buildList {
collectDiagnosticsFromStructureElements(structureElements, diagnosticCheckerFilter)
}
}
private fun MutableSet<FirPsiDiagnostic<*>>.collectDiagnosticsFromStructureElements(
private fun MutableCollection<FirPsiDiagnostic<*>>.collectDiagnosticsFromStructureElements(
structureElements: Collection<FileStructureElement>,
diagnosticCheckerFilter: DiagnosticCheckerFilter
) {
+2 -2
View File
@@ -1,4 +1,4 @@
// EXPECTED_DUPLICATED_HIGHLIGHTING
open class 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
class NoC1 : NoC()
@@ -39,7 +39,7 @@ public abstract class AbstractHighlightingTest extends KotlinLightCodeInsightFix
myFixture.configureByFile(fileName());
withExpectedDuplicatedHighlighting(expectedDuplicatedHighlighting, () -> {
withExpectedDuplicatedHighlighting(expectedDuplicatedHighlighting, isFirPlugin(), () -> {
try {
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) {
runnable.run();
return;
@@ -63,7 +63,7 @@ public abstract class AbstractHighlightingTest extends KotlinLightCodeInsightFix
try {
ExpectedHighlightingData.expectedDuplicatedHighlighting(runnable);
} catch (IllegalStateException e) {
if (isFirPlugin()) {
if (isFirPlugin) {
runnable.run();
} else {
throw e;