mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
Restricting search scope with codeUsageScope
Relates to #KTIJ-16709 GitOrigin-RevId: d6e2783673aee658f0e8cc016371ef76f47613eb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c475753b88
commit
c8e3d7d0c2
@@ -163,7 +163,7 @@ public final class ClassInheritorsSearch extends ExtensibleQueryFactory<PsiClass
|
||||
throw new ProcessCanceledException();
|
||||
}
|
||||
PsiFile file = aClass.getContainingFile();
|
||||
return PsiSearchHelper.getInstance(aClass.getProject()).getUseScope(file != null ? file : aClass);
|
||||
return PsiSearchHelper.getInstance(aClass.getProject()).getCodeUsageScope(file != null ? file : aClass);
|
||||
}), checkDeep);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.search.PsiSearchHelper
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions
|
||||
import org.jetbrains.kotlin.idea.util.application.getServiceSafe
|
||||
@@ -67,7 +68,7 @@ interface KotlinSearchUsagesSupport {
|
||||
): Boolean = getInstance(ktClass.project).forEachKotlinOverride(ktClass, members, scope, searchDeeply, processor)
|
||||
|
||||
fun PsiMethod.forEachOverridingMethod(
|
||||
scope: SearchScope = runReadAction { useScope },
|
||||
scope: SearchScope = runReadAction { PsiSearchHelper.getInstance(project).getCodeUsageScope(this) },
|
||||
processor: (PsiMethod) -> Boolean
|
||||
): Boolean = getInstance(project).forEachOverridingMethod(this, scope, processor)
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.ide.highlighter.JavaFileType
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiReferenceExpression
|
||||
import com.intellij.psi.search.PsiSearchHelper
|
||||
import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightElement
|
||||
@@ -63,7 +64,7 @@ class AddJvmStaticIntention : SelfTargetingRangeIntention<KtNamedDeclaration>(
|
||||
val expressionsToReplaceWithQualifier =
|
||||
project.runSynchronouslyWithProgress(KotlinBundle.message("looking.for.usages.in.java.files"), true) {
|
||||
runReadAction {
|
||||
val searchScope = element.useScope.restrictByFileType(JavaFileType.INSTANCE)
|
||||
val searchScope = PsiSearchHelper.getInstance(project).getCodeUsageScope(element).restrictByFileType(JavaFileType.INSTANCE)
|
||||
ReferencesSearch
|
||||
.search(element, searchScope)
|
||||
.mapNotNull {
|
||||
|
||||
@@ -4,6 +4,7 @@ package org.jetbrains.kotlin.idea.intentions.loopToCallChain
|
||||
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.psi.search.LocalSearchScope
|
||||
import com.intellij.psi.search.PsiSearchHelper
|
||||
import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
@@ -68,7 +69,7 @@ fun KtCallableDeclaration.hasUsages(inElements: Collection<KtElement>): Boolean
|
||||
fun KtVariableDeclaration.hasWriteUsages(): Boolean {
|
||||
assert(this.isPhysical)
|
||||
if (!isVar) return false
|
||||
return ReferencesSearch.search(this, useScope).any {
|
||||
return ReferencesSearch.search(this, PsiSearchHelper.getInstance(project).getCodeUsageScope(this)).any {
|
||||
(it as? KtSimpleNameReference)?.element?.readWriteAccess(useResolveForReadWrite = true)?.isWrite == true
|
||||
}
|
||||
}
|
||||
@@ -86,13 +87,13 @@ fun KtCallableDeclaration.countUsages(inElements: Collection<KtElement>): Int {
|
||||
|
||||
fun KtCallableDeclaration.countUsages(): Int {
|
||||
assert(this.isPhysical)
|
||||
return ReferencesSearch.search(this, useScope).count()
|
||||
return ReferencesSearch.search(this, PsiSearchHelper.getInstance(project).getCodeUsageScope(this)).count()
|
||||
}
|
||||
|
||||
fun KtVariableDeclaration.countWriteUsages(): Int {
|
||||
assert(this.isPhysical)
|
||||
if (!isVar) return 0
|
||||
return ReferencesSearch.search(this, useScope).count {
|
||||
return ReferencesSearch.search(this, PsiSearchHelper.getInstance(project).getCodeUsageScope(this)).count {
|
||||
(it as? KtSimpleNameReference)?.element?.readWriteAccess(useResolveForReadWrite = true)?.isWrite == true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
|
||||
val propagationTarget = functionUsageInfo is CallerUsageInfo ||
|
||||
(functionUsageInfo is OverriderUsageInfo && !functionUsageInfo.isOriginalOverrider)
|
||||
|
||||
for (reference in ReferencesSearch.search(callee, callee.useScope.restrictToKotlinSources())) {
|
||||
for (reference in ReferencesSearch.search(callee, PsiSearchHelper.getInstance(callee.project).getCodeUsageScope(callee).restrictToKotlinSources())) {
|
||||
val callElement = reference.element.getParentOfTypeAndBranch<KtCallElement> { calleeExpression } ?: continue
|
||||
val usage = if (propagationTarget) {
|
||||
KotlinCallerCallUsage(callElement)
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiNamedElement
|
||||
import com.intellij.psi.search.PsiSearchHelper
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch
|
||||
@@ -72,7 +73,7 @@ fun forEachKotlinOverride(
|
||||
}
|
||||
|
||||
fun PsiMethod.forEachOverridingMethod(
|
||||
scope: SearchScope = runReadAction { useScope },
|
||||
scope: SearchScope = runReadAction { PsiSearchHelper.getInstance(project).getCodeUsageScope(this) },
|
||||
processor: (PsiMethod) -> Boolean
|
||||
): Boolean {
|
||||
if (this !is KtFakeLightMethod) {
|
||||
|
||||
Reference in New Issue
Block a user