diff --git a/idea/testData/usageHighlighter/implicitReturnExpressionsInLambdasNoHightlighting.kt b/idea/testData/usageHighlighter/implicitReturnExpressionsInLambdasNoHightlighting.kt
index 9e541e39396..7e34f79bb92 100644
--- a/idea/testData/usageHighlighter/implicitReturnExpressionsInLambdasNoHightlighting.kt
+++ b/idea/testData/usageHighlighter/implicitReturnExpressionsInLambdasNoHightlighting.kt
@@ -6,7 +6,7 @@ fun some(a: Int, b: Int) {
if (b > 100) {
101 + j
} else {
- ~102 * j
+ ~102 * j
}
} else {
return@run false
diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractUsageHighlightingTest.kt b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractUsageHighlightingTest.kt
index 436b7d4f953..b3821c9ef33 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractUsageHighlightingTest.kt
+++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/AbstractUsageHighlightingTest.kt
@@ -7,16 +7,20 @@ package org.jetbrains.kotlin.idea.highlighter
import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
-import com.intellij.codeInsight.highlighting.actions.HighlightUsagesAction
+import com.intellij.codeInsight.highlighting.HighlightUsagesHandler
+import com.intellij.openapi.editor.colors.EditorColors
+import com.intellij.openapi.editor.colors.EditorColorsManager
+import com.intellij.openapi.editor.markup.RangeHighlighter
+import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.testFramework.ExpectedHighlightingData
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
import org.jetbrains.kotlin.idea.test.extractMarkerOffset
-abstract class AbstractUsageHighlightingTest: KotlinLightCodeInsightFixtureTestCase() {
+abstract class AbstractUsageHighlightingTest : KotlinLightCodeInsightFixtureTestCase() {
companion object {
// Not standard to leave it in text after configureByFile and remove manually after collecting highlighting information
- val CARET_TAG = "~"
+ const val CARET_TAG = "~"
}
protected fun doTest(filePath: String) {
@@ -29,24 +33,37 @@ abstract class AbstractUsageHighlightingTest: KotlinLightCodeInsightFixtureTestC
assert(caret != -1) { "Caret marker '$CARET_TAG' expected" }
editor.caretModel.moveToOffset(caret)
- myFixture.testAction(HighlightUsagesAction())
+ HighlightUsagesHandler.invoke(project, editor, myFixture.file)
val highlighters = myFixture.editor.markupModel.allHighlighters
- val infos = highlighters.map { highlighter ->
- var startOffset = highlighter.startOffset
- var endOffset = highlighter.endOffset
+ val infos = highlighters
+ .filter { isUsageHighlighting(it) }
+ .map { highlighter ->
+ var startOffset = highlighter.startOffset
+ var endOffset = highlighter.endOffset
- if (startOffset > caret) startOffset += CARET_TAG.length
- if (endOffset > caret) endOffset += CARET_TAG.length
+ if (startOffset > caret) startOffset += CARET_TAG.length
+ if (endOffset > caret) endOffset += CARET_TAG.length
- HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(startOffset, endOffset).create()
- }
+ HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION)
+ .range(startOffset, endOffset)
+ .create()
+ }
data.checkResult(infos, StringBuilder(document.text).insert(caret, CARET_TAG).toString())
}
+ private fun isUsageHighlighting(info: RangeHighlighter): Boolean {
+ val globalScheme = EditorColorsManager.getInstance().globalScheme
+ val readAttributes: TextAttributes =
+ globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES)
+ val writeAttributes: TextAttributes =
+ globalScheme.getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES)
- override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE
+ return info.textAttributes == readAttributes || info.textAttributes == writeAttributes
+ }
+
+ override fun getProjectDescriptor(): KotlinLightProjectDescriptor = KotlinLightProjectDescriptor.INSTANCE
override fun getTestDataPath() = ""
}