From 1cc59f4b18270dcf2a32fa23a2b956b44a796e4e Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 5 Mar 2019 20:50:18 +0300 Subject: [PATCH] Mute false positive duplicate warnings in highlighting in 191 --- idea/testData/highlighter/Annotations.kt | 2 ++ idea/testData/highlighter/Destructuring.kt | 2 ++ idea/testData/highlighter/Field.kt | 3 ++ idea/testData/highlighter/Labels.kt | 2 ++ idea/testData/highlighter/TypeAlias.kt | 2 ++ idea/testData/highlighter/Variables.kt | 2 ++ .../highlighter/VariablesAsFunctions.kt | 2 ++ .../highlighter/AbstractHighlightingTest.java | 30 +++++++++++++------ .../idea/highlighter/duplicateHighlighting.kt | 12 ++++++++ .../highlighter/duplicateHighlighting.kt.191 | 15 ++++++++++ 10 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt create mode 100644 idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.191 diff --git a/idea/testData/highlighter/Annotations.kt b/idea/testData/highlighter/Annotations.kt index 0be6953c999..ad5c4c03ce7 100644 --- a/idea/testData/highlighter/Annotations.kt +++ b/idea/testData/highlighter/Annotations.kt @@ -1,3 +1,5 @@ +// EXPECTED_DUPLICATED_HIGHLIGHTING + @Target(AnnotationTarget.CLASS, AnnotationTarget.EXPRESSION) @Retention(AnnotationRetention.SOURCE) annotation class Ann diff --git a/idea/testData/highlighter/Destructuring.kt b/idea/testData/highlighter/Destructuring.kt index 5620a43c0c4..b35277cccdb 100644 --- a/idea/testData/highlighter/Destructuring.kt +++ b/idea/testData/highlighter/Destructuring.kt @@ -1,3 +1,5 @@ +// EXPECTED_DUPLICATED_HIGHLIGHTING + data class Box(val v: Int) fun consume(x: Int) {} diff --git a/idea/testData/highlighter/Field.kt b/idea/testData/highlighter/Field.kt index 3effdf76d5b..129887a6744 100644 --- a/idea/testData/highlighter/Field.kt +++ b/idea/testData/highlighter/Field.kt @@ -1,3 +1,6 @@ +// EXPECTED_DUPLICATED_HIGHLIGHTING +// FALSE_POSITIVE + var my = 0 get() = field set(arg) { diff --git a/idea/testData/highlighter/Labels.kt b/idea/testData/highlighter/Labels.kt index e32e016de38..32f15db9b0a 100644 --- a/idea/testData/highlighter/Labels.kt +++ b/idea/testData/highlighter/Labels.kt @@ -1,3 +1,5 @@ +// EXPECTED_DUPLICATED_HIGHLIGHTING + fun bar(block: () -> Int) = block() fun foo(): Int { diff --git a/idea/testData/highlighter/TypeAlias.kt b/idea/testData/highlighter/TypeAlias.kt index 2cf6a236554..bcabe5b0e63 100644 --- a/idea/testData/highlighter/TypeAlias.kt +++ b/idea/testData/highlighter/TypeAlias.kt @@ -1,2 +1,4 @@ +// EXPECTED_DUPLICATED_HIGHLIGHTING + typealias Predicate<T> = (T) -> Boolean fun baz(p: Predicate<Int>) = p(42) diff --git a/idea/testData/highlighter/Variables.kt b/idea/testData/highlighter/Variables.kt index 500e54837ae..e091289a96e 100644 --- a/idea/testData/highlighter/Variables.kt +++ b/idea/testData/highlighter/Variables.kt @@ -1,3 +1,5 @@ +// EXPECTED_DUPLICATED_HIGHLIGHTING + var x = 5 val Int.sq : Int diff --git a/idea/testData/highlighter/VariablesAsFunctions.kt b/idea/testData/highlighter/VariablesAsFunctions.kt index 3beb661c09f..97d2b253f95 100644 --- a/idea/testData/highlighter/VariablesAsFunctions.kt +++ b/idea/testData/highlighter/VariablesAsFunctions.kt @@ -1,3 +1,5 @@ +// EXPECTED_DUPLICATED_HIGHLIGHTING + interface FunctionLike { operator fun invoke() { } diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightingTest.java b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightingTest.java index 2e4785b2371..c442817c1fa 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightingTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractHighlightingTest.java @@ -23,19 +23,31 @@ public abstract class AbstractHighlightingTest extends KotlinLightCodeInsightFix boolean checkInfos = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_INFOS"); boolean checkWeakWarnings = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_WEAK_WARNINGS"); boolean checkWarnings = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_WARNINGS"); + boolean expectedDuplicatedHighlighting = InTextDirectivesUtils.isDirectiveDefined(fileText, "// EXPECTED_DUPLICATED_HIGHLIGHTING"); myFixture.configureByFile(filePath); - try { - myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings); - } - catch (FileComparisonFailure e) { - List highlights = - DaemonCodeAnalyzerImpl.getHighlights(myFixture.getDocument(myFixture.getFile()), null, myFixture.getProject()); - String text = myFixture.getFile().getText(); + withExpectedDuplicatedHighlighting(expectedDuplicatedHighlighting, () -> { + try { + myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings); + } + catch (FileComparisonFailure e) { + List highlights = + DaemonCodeAnalyzerImpl.getHighlights(myFixture.getDocument(myFixture.getFile()), null, myFixture.getProject()); + String text = myFixture.getFile().getText(); - System.out.println(TagsTestDataUtil.insertInfoTags(highlights, text)); - throw e; + System.out.println(TagsTestDataUtil.insertInfoTags(highlights, text)); + throw e; + } + }); + } + + private static void withExpectedDuplicatedHighlighting(boolean expectedDuplicatedHighlighting, Runnable runnable) { + if (!expectedDuplicatedHighlighting) { + runnable.run(); + return; } + + DuplicateHighlightingKt.expectedDuplicatedHighlighting(runnable); } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt b/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt new file mode 100644 index 00000000000..6a45e2e5567 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.highlighter + +// Idea 191 has an additional check for duplicate highlighting +// BUNCH: 183 +fun expectedDuplicatedHighlighting(runnable: Runnable) { + runnable.run() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.191 b/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.191 new file mode 100644 index 00000000000..e76e28a907c --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/duplicateHighlighting.kt.191 @@ -0,0 +1,15 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.highlighter + +import com.intellij.testFramework.ExpectedHighlightingData + +// Idea 191 has an additional check for duplicate highlighting +// BUNCH: 183 +fun expectedDuplicatedHighlighting(runnable: Runnable) { + @Suppress("DEPRECATION") + ExpectedHighlightingData.expectedDuplicatedHighlighting(runnable) +} \ No newline at end of file