[kotlin] find usages: cleanup

- refactoring
- remove K2_IGNORE_LOG after 734ecff5131d387c1bcb176f7905285f5e994b26 which ignores log in k2 case anyway

GitOrigin-RevId: f35cc8b40c388d91a4039cee6c2291975878e265
This commit is contained in:
Anna Kozlova
2024-05-09 06:48:47 +00:00
committed by intellij-monorepo-bot
parent 4c22f7dbf9
commit 7fb3e939a4
53 changed files with 41 additions and 70 deletions
@@ -2,10 +2,13 @@
package org.jetbrains.kotlin.idea.search
import com.intellij.openapi.module.Module
import com.intellij.psi.PsiNamedElement
import org.jetbrains.kotlin.idea.base.psi.isExpectDeclaration
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions
import org.jetbrains.kotlin.psi.KtCallableDeclaration
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
object ExpectActualUtils {
fun KtDeclaration.expectedDeclarationIfAny(): KtDeclaration? =
@@ -30,4 +33,13 @@ object ExpectActualUtils {
val actuals = expect.actualsForExpected()
return listOf(expect) + actuals
}
fun getElementToSearch(
kotlinOptions: KotlinReferencesSearchOptions,
unwrappedElement: PsiNamedElement
): PsiNamedElement = if (kotlinOptions.searchForExpectedUsages && unwrappedElement is KtDeclaration && unwrappedElement.hasActualModifier()) {
unwrappedElement.expectedDeclarationIfAny() as? PsiNamedElement
} else {
null
} ?: unwrappedElement
}
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.idea.base.util.restrictToKotlinSources
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.search.ExpectActualSupport
import org.jetbrains.kotlin.idea.search.ExpectActualUtils.expectedDeclarationIfAny
import org.jetbrains.kotlin.idea.search.ExpectActualUtils.getElementToSearch
import org.jetbrains.kotlin.idea.search.KOTLIN_NAMED_ARGUMENT_SEARCH_CONTEXT
import org.jetbrains.kotlin.idea.search.KotlinSearchUsagesSupport.SearchUtils.dataClassComponentMethodName
import org.jetbrains.kotlin.idea.search.KotlinSearchUsagesSupport.SearchUtils.filterDataClassComponentsIfDisabled
@@ -47,7 +47,6 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.operators.OperatorReference
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
import org.jetbrains.kotlin.psi.psiUtil.parameterIndex
import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -101,12 +100,7 @@ class KotlinAliasedImportedElementSearcher : QueryExecutorBase<PsiReference, Ref
if (!element.isValid) return@Callable null
val unwrappedElement = element.namedUnwrappedElement ?: return@Callable null
val elementToSearch =
if (kotlinOptions.searchForExpectedUsages && unwrappedElement is KtDeclaration && unwrappedElement.hasActualModifier()) {
unwrappedElement.expectedDeclarationIfAny() as? PsiNamedElement
} else {
null
} ?: unwrappedElement
val elementToSearch = getElementToSearch(kotlinOptions, unwrappedElement)
val name = elementToSearch.name
if (name.isNullOrBlank()) return@Callable null
@@ -183,12 +177,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
val unwrappedElement = psiElement.namedUnwrappedElement ?: return@Callable null
val elementToSearch =
if (kotlinOptions.searchForExpectedUsages && unwrappedElement is KtDeclaration && unwrappedElement.hasActualModifier()) {
unwrappedElement.expectedDeclarationIfAny() as? PsiNamedElement
} else {
null
} ?: unwrappedElement
val elementToSearch = getElementToSearch(kotlinOptions, unwrappedElement)
val effectiveSearchScope = queryParameters.effectiveSearchScope(elementToSearch)
@@ -302,7 +291,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
}
is KtConstructor<*> -> {
val psiMethods = findAllRelatedActuals(element)
val psiMethods = findAllRelatedActualsOrSelf(element)
.filterIsInstance<KtConstructor<*>>()
.flatMap { getLightClassMethods(it) }
@@ -324,7 +313,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
}
is KtProperty -> {
val propertyAccessors = findAllRelatedActuals(element)
val propertyAccessors = findAllRelatedActualsOrSelf(element)
.filterIsInstance<KtProperty>()
.map { getLightClassPropertyMethods(it) }
propertyAccessors.forEach { propertyAccessor ->
@@ -367,7 +356,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
@RequiresReadLock
private fun searchPropertyAccessorMethods(origin: KtParameter) {
val lightMethods = findAllRelatedActuals(origin)
val lightMethods = findAllRelatedActualsOrSelf(origin)
.filterIsInstance<KtParameter>()
.flatMap { it.toLightElements() }
.toList()
@@ -390,7 +379,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
* return self if [element] is not expect nor actual
*/
@RequiresReadLock
private fun findAllRelatedActuals(element: KtDeclaration): Set<KtDeclaration> {
private fun findAllRelatedActualsOrSelf(element: KtDeclaration): Set<KtDeclaration> {
val expectActualSupport = ExpectActualSupport.getInstance(element.project)
return when {
element.isExpectDeclaration() -> expectActualSupport.actualsForExpected(element)
@@ -409,7 +398,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
private fun processKtClassOrObject(element: KtClassOrObject) {
if (element.name == null) return
val lightClasses = findAllRelatedActuals(element).mapNotNull { (it as? KtClassOrObject)?.toLightClass() }
val lightClasses = findAllRelatedActualsOrSelf(element).mapNotNull { (it as? KtClassOrObject)?.toLightClass() }
lightClasses.forEach(::searchNamedElement)
@@ -271,7 +271,6 @@ object IgnoreTests {
const val IGNORE_K2: String = "// IGNORE_K2"
const val IGNORE_K2_MULTILINE_COMMENT: String = "/* IGNORE_K2 */"
const val IGNORE_K2_LOG: String = "// IGNORE_K2_LOG"
@Deprecated(message = "use IGNORE_K2 instead")
const val IGNORE_FIR: String = "// IGNORE_FIR"
@@ -6,4 +6,3 @@ public class Small {
}
}
// IGNORE_K2_LOG
@@ -12,4 +12,3 @@ public class JavaWithGroovyInvoke_0 {
// CRI_IGNORE
// IGNORE_K2_LOG
@@ -11,4 +11,3 @@ public class Bar {
}
// IGNORE_K2_LOG
@@ -11,4 +11,3 @@ public class JavaClass {
}
}
// IGNORE_K2_LOG
@@ -25,4 +25,3 @@ public class JavaClassInvoke {
}
}
// IGNORE_K2_LOG
@@ -11,4 +11,3 @@ public class JavaClassWI {
}
}
// IGNORE_K2_LOG
@@ -21,4 +21,3 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -8,6 +8,6 @@ data class A(val <caret>a: Int, val b: String)
// IGNORE_K2_LOG
// IGNORE_PLATFORM_JS: Java-specific code
// IGNORE_PLATFORM_NATIVE: Java-specific code
@@ -28,6 +28,6 @@ fun foo(x: X) {
// IGNORE_K2_LOG
// IGNORE_PLATFORM_JS: Java-specific code
// IGNORE_PLATFORM_NATIVE: Java-specific code
@@ -16,4 +16,3 @@ fun foo() {
// IGNORE_K2_LOG
@@ -15,4 +15,4 @@ fun test() {
// IGNORE_K2_LOG
@@ -22,4 +22,4 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -30,6 +30,6 @@ fun <T> T.getThis(): T = this
// IGNORE_K2_LOG
// IGNORE_PLATFORM_JS: Java-specific code
// IGNORE_PLATFORM_NATIVE: Java-specific code
@@ -13,4 +13,4 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -12,4 +12,4 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -19,4 +19,4 @@ fun f(b: B, c: C) {
}
// IGNORE_K2_LOG
@@ -32,4 +32,4 @@ fun g(z1: Z1, z2: Z2) {
}
// IGNORE_K2_LOG
@@ -14,4 +14,4 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -17,4 +17,4 @@ fun y(o: Any) {
}
// IGNORE_K2_LOG
@@ -43,4 +43,4 @@ fun f() {
// IGNORE_K2_LOG
@@ -35,4 +35,4 @@ fun y3(a: A) {
// IGNORE_K2_LOG
@@ -30,4 +30,4 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -18,4 +18,4 @@ fun f(b1: B, b2: B) {
}
// IGNORE_K2_LOG
@@ -22,4 +22,4 @@ class Key<Value> {
fun get(): Value = null as Value
}
// IGNORE_K2_LOG
@@ -12,4 +12,4 @@ fun f(a: A) {
// IGNORE_K2_LOG
@@ -11,4 +11,4 @@ fun f(a: A) {
val (a1, s) = b
}
// IGNORE_K2_LOG
@@ -28,4 +28,4 @@ fun when2(o: Any) {
}
}
// IGNORE_K2_LOG
@@ -17,4 +17,3 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -22,4 +22,3 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -20,4 +20,3 @@ typealias DescriptorData = C<B.Key>
class C<T>
// IGNORE_K2_LOG
@@ -11,4 +11,3 @@ class Delegate() {
val p: String by Delegate()
// IGNORE_K2_LOG
@@ -14,4 +14,3 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -15,4 +15,3 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -13,4 +13,4 @@ fun test() {
Foo()
}
// IGNORE_K2_LOG
@@ -11,4 +11,4 @@ suspend fun main() {
a.invoke()
}
// IGNORE_K2_LOG
@@ -13,4 +13,3 @@ fun f(p: P) {
}
// IGNORE_K2_LOG
@@ -16,4 +16,3 @@ fun f(p: P) {
}
// IGNORE_K2_LOG
@@ -24,4 +24,3 @@ fun test(array: Array<A>) {
}
// IGNORE_K2_LOG
@@ -20,4 +20,3 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -15,4 +15,3 @@ class Delegate() {
var p: String by Delegate()
// IGNORE_K2_LOG
@@ -41,4 +41,3 @@ fun test4() {
}
// IGNORE_K2_LOG
@@ -12,4 +12,3 @@ fun test() {
}
// IGNORE_K2_LOG
@@ -10,4 +10,3 @@ package test
public data class KotlinDataClass(val <caret>foo: Int, val bar: String)
// IGNORE_K2_LOG
@@ -2,4 +2,3 @@
// OPTIONS: constructorUsages, expected
actual open class Cla<caret>zz004 actual constructor()
val a1 = Clazz004()
// IGNORE_K2_LOG
@@ -2,4 +2,3 @@
// OPTIONS: usages, expected
actual open class Cla<caret>zz004 actual constructor()
val a1 = Clazz004()
// IGNORE_K2_LOG
@@ -8,4 +8,3 @@ fun m(d: D) {
d.a
}
// IGNORE_K2_LOG
@@ -3,4 +3,3 @@
package foo
actual interface OnlyInCommonI<caret>nterface014
// IGNORE_K2_LOG
@@ -1,4 +1,3 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtClass
// OPTIONS: usages, expected
actual interface OnlyInCommonInterface<caret>001
// IGNORE_K2_LOG
@@ -14,4 +14,3 @@ class E: D() {
}
}
// IGNORE_K2_LOG