diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/ExpressionsOfTypeProcessor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/ExpressionsOfTypeProcessor.kt index bf6a18a8e6f..55b0b04e432 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/ExpressionsOfTypeProcessor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/ExpressionsOfTypeProcessor.kt @@ -56,7 +56,7 @@ class ExpressionsOfTypeProcessor( private val typeToSearch: FuzzyType, private val searchScope: SearchScope, private val suspiciousExpressionHandler: (KtExpression) -> Unit, - suspiciousScopeHandler: (SearchScope) -> Unit, + private val suspiciousScopeHandler: (SearchScope) -> Unit, private val resolutionFacade: ResolutionFacade ) { enum class Mode { @@ -88,11 +88,6 @@ class ExpressionsOfTypeProcessor( private val project = resolutionFacade.project - private val plainSearchHandler: (SearchScope) -> Unit = { scope -> - testLog?.add("Used plain search in ${scope.logPresentation()}") - suspiciousScopeHandler(scope) - } - // note: a Task must define equals & hashCode! private interface Task { fun perform() @@ -114,7 +109,7 @@ class ExpressionsOfTypeProcessor( // for class from library always use plain search because we cannot search usages in compiled code (we could though) if (!ProjectRootsUtil.isInProjectSource(psiClass)) { - plainSearchHandler(searchScope) + suspiciousScopeHandler(searchScope) return } @@ -123,7 +118,7 @@ class ExpressionsOfTypeProcessor( processTasks() val scopeElements = scopesToUsePlainSearch.values.flatMap { it }.toTypedArray() - plainSearchHandler(LocalSearchScope(scopeElements)) + suspiciousScopeHandler(LocalSearchScope(scopeElements)) } private fun addTask(task: Task) { @@ -142,7 +137,7 @@ class ExpressionsOfTypeProcessor( private fun downShiftToPlainSearch() { tasks.clear() scopesToUsePlainSearch.clear() - plainSearchHandler(searchScope) + suspiciousScopeHandler(searchScope) } private fun addClassToProcess(classToSearch: PsiClass) { @@ -620,33 +615,4 @@ class ExpressionsOfTypeProcessor( else -> false } } - - private fun SearchScope.logPresentation(): String { - return when (this) { - searchScope -> "whole search scope" - - is LocalSearchScope -> { - scope - .map { element -> - " " + when (element) { - is KtFunctionLiteral -> element.text - is KtWhenEntry -> { - if (element.isElse) - "KtWhenEntry \"else\"" - else - "KtWhenEntry \"" + element.conditions.joinToString(", ") { it.text } + "\"" - } - is KtNamedDeclaration -> element.node.elementType.toString() + ":" + element.name - else -> element.toString() - } - } - .toList() - .sorted() - .joinToString("\n", "LocalSearchScope:\n") - } - - else -> this.displayName - } - - } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/OperatorReferenceSearch.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/OperatorReferenceSearch.kt index d48522d1782..80043ebb8f3 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/OperatorReferenceSearch.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/OperatorReferenceSearch.kt @@ -171,6 +171,8 @@ abstract class OperatorReferenceSearcher( } private fun doPlainSearch(scope: SearchScope) { + testLog?.add("Used plain search of ${logPresentation(targetDeclaration)} in ${scope.logPresentation()}") + if (scope is LocalSearchScope) { for (element in scope.scope) { element.accept(object : PsiRecursiveElementWalkingVisitor() { @@ -209,4 +211,33 @@ abstract class OperatorReferenceSearcher( } } } + + private fun SearchScope.logPresentation(): String { + return when (this) { + searchScope -> "whole search scope" + + is LocalSearchScope -> { + scope + .map { element -> + " " + when (element) { + is KtFunctionLiteral -> element.text + is KtWhenEntry -> { + if (element.isElse) + "KtWhenEntry \"else\"" + else + "KtWhenEntry \"" + element.conditions.joinToString(", ") { it.text } + "\"" + } + is KtNamedDeclaration -> element.node.elementType.toString() + ":" + element.name + else -> element.toString() + } + } + .toList() + .sorted() + .joinToString("\n", "LocalSearchScope:\n") + } + + else -> this.displayName + } + + } } diff --git a/idea/testData/findUsages/kotlin/conventions/components/SAM.log b/idea/testData/findUsages/kotlin/conventions/components/SAM.log index c948db9ee67..bbb3d7264d1 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/SAM.log +++ b/idea/testData/findUsages/kotlin/conventions/components/SAM.log @@ -2,6 +2,6 @@ Resolved java class to descriptor: JavaSAM Searched references to JavaClass.takeSAM() in Kotlin files Searched references to JavaSAM in java files Searched references to pack.A -Used plain search in LocalSearchScope: +Used plain search of parameter a in A() in LocalSearchScope: CLASS:A { val (x, y) = it } diff --git a/idea/testData/findUsages/kotlin/conventions/components/callableReferences.log b/idea/testData/findUsages/kotlin/conventions/components/callableReferences.log index d50ccac6db2..c24f4fa3dcd 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/callableReferences.log +++ b/idea/testData/findUsages/kotlin/conventions/components/callableReferences.log @@ -12,5 +12,5 @@ Searched references to constructor in Kotlin files Searched references to f1() in Kotlin files Searched references to fun2 in Kotlin files Searched references to fun3 in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of parameter a in A() in LocalSearchScope: CLASS:A diff --git a/idea/testData/findUsages/kotlin/conventions/components/companionObjectAccess.log b/idea/testData/findUsages/kotlin/conventions/components/companionObjectAccess.log index f24dc0317bf..e71318ff2e0 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/companionObjectAccess.log +++ b/idea/testData/findUsages/kotlin/conventions/components/companionObjectAccess.log @@ -1,3 +1,3 @@ Searched references to A -Used plain search in LocalSearchScope: +Used plain search of parameter x in A() in LocalSearchScope: CLASS:A diff --git a/idea/testData/findUsages/kotlin/conventions/components/componentFunForGenericType1.log b/idea/testData/findUsages/kotlin/conventions/components/componentFunForGenericType1.log index 68041e8157b..3f11937eda1 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/componentFunForGenericType1.log +++ b/idea/testData/findUsages/kotlin/conventions/components/componentFunForGenericType1.log @@ -2,7 +2,7 @@ Checked type of f() Resolved (x, y) Searched references to X Searched references to f() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of component1() in LocalSearchScope: CLASS:X FUN:component1 FUN:component2 \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/componentFunForGenericType2.log b/idea/testData/findUsages/kotlin/conventions/components/componentFunForGenericType2.log index e7abbe77beb..07d10fe8fff 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/componentFunForGenericType2.log +++ b/idea/testData/findUsages/kotlin/conventions/components/componentFunForGenericType2.log @@ -3,7 +3,7 @@ Checked type of g() Resolved (x1, y1) Searched references to X Searched references to f() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of component1() in LocalSearchScope: CLASS:X FUN:component1 FUN:component1 diff --git a/idea/testData/findUsages/kotlin/conventions/components/dataClass.log b/idea/testData/findUsages/kotlin/conventions/components/dataClass.log index a56ac141c2e..94e145d5736 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/dataClass.log +++ b/idea/testData/findUsages/kotlin/conventions/components/dataClass.log @@ -23,7 +23,7 @@ Searched references to pack.A Searched references to pack.X Searched references to parameter p1 in test2() in Kotlin files Searched references to parameter p2 in test2() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of parameter n in A() in LocalSearchScope: CLASS:A CLASS:X FUN:ext1 diff --git a/idea/testData/findUsages/kotlin/conventions/components/dataClassComponentByRef.log b/idea/testData/findUsages/kotlin/conventions/components/dataClassComponentByRef.log index 538c8c46725..f7552a01447 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/dataClassComponentByRef.log +++ b/idea/testData/findUsages/kotlin/conventions/components/dataClassComponentByRef.log @@ -2,5 +2,5 @@ Checked type of a Resolved (x, y, z) Searched references to A Searched references to a in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of parameter n in A() in LocalSearchScope: CLASS:A \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.log b/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.log index 63b8d7f9bbd..b060af5a822 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.log +++ b/idea/testData/findUsages/kotlin/conventions/components/dataClassFromStdlib.log @@ -1 +1 @@ -Used plain search in whole search scope \ No newline at end of file +Used plain search of kotlin.Pair.component1() in whole search scope \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/dataClassInsideDataClass.log b/idea/testData/findUsages/kotlin/conventions/components/dataClassInsideDataClass.log index 82d6ae316fb..affe792a667 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/dataClassInsideDataClass.log +++ b/idea/testData/findUsages/kotlin/conventions/components/dataClassInsideDataClass.log @@ -11,9 +11,9 @@ Searched references to a1 in Kotlin files Searched references to parameter a in B() in Kotlin files Searched references to parameter b in f() in Kotlin files Searched references to parameter c in f() in Kotlin files -Used plain search in LocalSearchScope: - CLASS:A -Used plain search in LocalSearchScope: - CLASS:B -Used plain search in LocalSearchScope: +Used plain search of C.component1() in LocalSearchScope: CLASS:C +Used plain search of parameter a in B() in LocalSearchScope: + CLASS:B +Used plain search of parameter x in A() in LocalSearchScope: + CLASS:A \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.log b/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.log index b6fb47c42b3..0e2dfbcace3 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.log +++ b/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.log @@ -9,7 +9,7 @@ Searched references to Z2 Searched references to f() in Kotlin files Searched references to parameter z1 in g() in Kotlin files Searched references to parameter z2 in g() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of component2() in LocalSearchScope: CLASS:X CLASS:Y CLASS:Z1 diff --git a/idea/testData/findUsages/kotlin/conventions/components/for.log b/idea/testData/findUsages/kotlin/conventions/components/for.log index 077fd6e5888..54b3e1414fe 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/for.log +++ b/idea/testData/findUsages/kotlin/conventions/components/for.log @@ -3,5 +3,5 @@ Resolved (x, y) Resolved (x, y, z) Searched references to A Searched references to parameter a in FOR in Kotlin files -Used plain search in LocalSearchScope: - CLASS:A +Used plain search of parameter n in A() in LocalSearchScope: + CLASS:A \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/isAndAs.log b/idea/testData/findUsages/kotlin/conventions/components/isAndAs.log index 6eb3be7fde9..2be123b2276 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/isAndAs.log +++ b/idea/testData/findUsages/kotlin/conventions/components/isAndAs.log @@ -3,6 +3,6 @@ Resolved (x, y) Resolved (x1, y1) Searched references to A Searched references to list in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of parameter x in A() in LocalSearchScope: CLASS:A FUN:x diff --git a/idea/testData/findUsages/kotlin/conventions/components/lambdas.log b/idea/testData/findUsages/kotlin/conventions/components/lambdas.log index 8ee03b73f3c..4350a436775 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/lambdas.log +++ b/idea/testData/findUsages/kotlin/conventions/components/lambdas.log @@ -11,7 +11,7 @@ Searched references to takeFun2() in Kotlin files Searched references to takeFun3() in Kotlin files Searched references to takeFuns() in Kotlin files Searched references to v in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of parameter a in A() in LocalSearchScope: CLASS:A { a, n -> val (x, y) = a!! } { val (x, y ) = it } diff --git a/idea/testData/findUsages/kotlin/conventions/components/mayTypeAffectAncestors.log b/idea/testData/findUsages/kotlin/conventions/components/mayTypeAffectAncestors.log index 26fb37ceee6..daed6d55d84 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/mayTypeAffectAncestors.log +++ b/idea/testData/findUsages/kotlin/conventions/components/mayTypeAffectAncestors.log @@ -6,6 +6,6 @@ Searched references to parameter a in x() in Kotlin files Searched references to parameter a in y1() in Kotlin files Searched references to parameter a in y2() in Kotlin files Searched references to parameter a in y3() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of parameter n in A() in LocalSearchScope: CLASS:A { val (x2, y2) = this } \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.log b/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.log index eb92b532538..05dd23197f0 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.log +++ b/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.log @@ -10,7 +10,7 @@ Searched references to Z Searched references to f() in Kotlin files Searched references to g() in Kotlin files Searched references to h() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of X.component1() in LocalSearchScope: CLASS:X CLASS:Y CLASS:Z \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/operators.log b/idea/testData/findUsages/kotlin/conventions/components/operators.log index 94f01ae03e6..9e4e89456ec 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/operators.log +++ b/idea/testData/findUsages/kotlin/conventions/components/operators.log @@ -6,8 +6,8 @@ Searched references to parameter b1 in f() in Kotlin files Searched references to parameter b2 in f() in Kotlin files Searched references to parameter other in plus() in Kotlin files Searched references to plus() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of parameter x in A() in LocalSearchScope: CLASS:A -Used plain search in LocalSearchScope: +Used plain search of plus() in LocalSearchScope: CLASS:B FUN:plus \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/recursiveDataClass1.log b/idea/testData/findUsages/kotlin/conventions/components/recursiveDataClass1.log index 2a27609e23f..769a682554a 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/recursiveDataClass1.log +++ b/idea/testData/findUsages/kotlin/conventions/components/recursiveDataClass1.log @@ -4,5 +4,5 @@ Resolved (a2, n2) Searched references to A Searched references to parameter a in A() in Kotlin files Searched references to parameter a in f() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of parameter a in A() in LocalSearchScope: CLASS:A diff --git a/idea/testData/findUsages/kotlin/conventions/components/recursiveDataClass2.log b/idea/testData/findUsages/kotlin/conventions/components/recursiveDataClass2.log index ce27ef9f6c0..b4b73d87cfe 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/recursiveDataClass2.log +++ b/idea/testData/findUsages/kotlin/conventions/components/recursiveDataClass2.log @@ -7,7 +7,7 @@ Searched references to b in Kotlin files Searched references to parameter a in B() in Kotlin files Searched references to parameter a in f() in Kotlin files Searched references to parameter b in A() in Kotlin files -Used plain search in LocalSearchScope: - CLASS:A -Used plain search in LocalSearchScope: +Used plain search of parameter a in B() in LocalSearchScope: CLASS:B +Used plain search of parameter b in A() in LocalSearchScope: + CLASS:A \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/when.log b/idea/testData/findUsages/kotlin/conventions/components/when.log index 0bc453b5b68..34378521198 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/when.log +++ b/idea/testData/findUsages/kotlin/conventions/components/when.log @@ -1,5 +1,5 @@ Searched references to A -Used plain search in LocalSearchScope: +Used plain search of parameter a in A() in LocalSearchScope: CLASS:A KtWhenEntry "else" KtWhenEntry "is A" diff --git a/idea/testData/findUsages/kotlin/conventions/invoke.log b/idea/testData/findUsages/kotlin/conventions/invoke.log index d77120c7e12..4d00ac21ec6 100644 --- a/idea/testData/findUsages/kotlin/conventions/invoke.log +++ b/idea/testData/findUsages/kotlin/conventions/invoke.log @@ -4,5 +4,5 @@ Resolved f(2) Resolved f(2)(2) Searched references to B Searched references to f() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of B.invoke() in LocalSearchScope: CLASS:B \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/plus.log b/idea/testData/findUsages/kotlin/conventions/plus.log index a468dcb6760..ae62eb62c83 100644 --- a/idea/testData/findUsages/kotlin/conventions/plus.log +++ b/idea/testData/findUsages/kotlin/conventions/plus.log @@ -22,7 +22,7 @@ Searched references to a in Kotlin files Searched references to a in Kotlin files Searched references to parameter a in A.plus() in Kotlin files Searched references to parameter a in A.plus() in Kotlin files -Used plain search in LocalSearchScope: +Used plain search of A.plus() in LocalSearchScope: CLASS:A -Used plain search in LocalSearchScope: +Used plain search of A.plus() in LocalSearchScope: CLASS:A \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.java b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.java index d3a20d9df38..ac1c586c132 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.java @@ -403,14 +403,15 @@ public abstract class AbstractFindUsagesTest extends KotlinLightCodeInsightFixtu Collection usageInfos; String log = null; + ArrayList logList = new ArrayList(); try { - ExpressionsOfTypeProcessor.Companion.setTestLog(new ArrayList()); + if (ExpressionsOfTypeProcessor.Companion.getMode() != ExpressionsOfTypeProcessor.Mode.ALWAYS_PLAIN) { + ExpressionsOfTypeProcessor.Companion.setTestLog(logList); + } usageInfos = findUsages(caretElement, options, highlightingMode); } finally { - List logList = ExpressionsOfTypeProcessor.Companion.getTestLog(); - assert logList != null; ExpressionsOfTypeProcessor.Companion.setTestLog(null); if (logList.size() > 0) { Collections.sort(logList);