Deprecate AbstractStubIndex::get and migrate usages

In this commit we implement a logical implication of the fact
that StubIndex::get is deprecated, combined with the fact that
AbstractStubIndex::get is not deprecated but calls
StubIndex::get with the exact same arguments it received. The
absence of deprecation of AbstractStubIndex::get obfuscates
the fact that we want to phase out StubIndex::get calls.

Apart from deprecating said method, we add some convenience
methods in AbstractStubIndex inheritors that ensure a few things:
- The not-deprecated and preferred StubIndex::getElements is
  called with appropriate arguments, including a properly
  specialised requiredClass argument.
- Shorter syntax and DRY: only 3 arguments are required to pass
  into the convenience method, whereas getElements requires 2
  more. These 2 arguments are fields of the AbstractStubIndex
  inheritor, so it makes little sense to get them from there
  and pass them into StubIndex::getElements everywhere.

Wherever we can, these convenience methods are now used.

If you have access to JetBrains internal resources, also see:
https://jetbrains.team/p/ij/reviews/112930/timeline
https://jetbrains.slack.com/archives/CMDBCUBGE/p1691509451975689

GitOrigin-RevId: c51ef4de44aa85841799640b1ece9d291208dc69
This commit is contained in:
Izmar Verhage
2023-08-09 16:34:49 +02:00
committed by intellij-monorepo-bot
parent 4f5b0b8e58
commit 06190372c4
64 changed files with 173 additions and 45 deletions

View File

@@ -46,7 +46,7 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@Override
public @NotNull PsiClass @NotNull [] getClassesByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
Collection<PsiClass> classes = JavaShortClassNameIndex.getInstance().get(name, myProject, scope);
Collection<PsiClass> classes = JavaShortClassNameIndex.getInstance().getClasses(name, myProject, scope);
if (classes.isEmpty()) return PsiClass.EMPTY_ARRAY;
List<PsiClass> result = new ArrayList<>(classes.size());
@@ -125,7 +125,7 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@Override
public @NotNull PsiMethod @NotNull [] getMethodsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
Collection<PsiMethod> methods = JavaMethodNameIndex.getInstance().get(name, myProject, scope);
Collection<PsiMethod> methods = JavaMethodNameIndex.getInstance().getMethods(name, myProject, scope);
return filterMembers(methods, scope, PsiMethod.EMPTY_ARRAY);
}
@@ -167,7 +167,7 @@ public class PsiShortNamesCacheImpl extends PsiShortNamesCache {
@Override
public @NotNull PsiField @NotNull [] getFieldsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
Collection<PsiField> fields = JavaFieldNameIndex.getInstance().get(name, myProject, scope);
Collection<PsiField> fields = JavaFieldNameIndex.getInstance().getFields(name, myProject, scope);
return filterMembers(fields, scope, PsiField.EMPTY_ARRAY);
}

View File

@@ -25,8 +25,16 @@ public class JavaAnnotationIndex extends StringStubIndexExtension<PsiAnnotation>
return JavaStubIndexKeys.ANNOTATIONS;
}
/**
* @deprecated Deprecated base method, please use {@link #getAnnotations(String, Project, GlobalSearchScope)}
*/
@Deprecated
@Override
public Collection<PsiAnnotation> get(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return getAnnotations(s, project, scope);
}
public Collection<PsiAnnotation> getAnnotations(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return StubIndex.getElements(getKey(), s, project, new JavaSourceFilterScope(scope), PsiAnnotation.class);
}
}

View File

@@ -25,8 +25,16 @@ public class JavaAnonymousClassBaseRefOccurenceIndex extends StringStubIndexExte
return JavaStubIndexKeys.ANONYMOUS_BASEREF;
}
/**
* @deprecated Deprecated base method, please use {@link #getOccurences(String, Project, GlobalSearchScope)}
*/
@Deprecated
@Override
public Collection<PsiAnonymousClass> get(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return getOccurences(s, project, scope);
}
public Collection<PsiAnonymousClass> getOccurences(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return StubIndex.getElements(getKey(), s, project, new JavaSourceFilterScope(scope), PsiAnonymousClass.class);
}
}

View File

@@ -25,8 +25,16 @@ public class JavaFieldNameIndex extends StringStubIndexExtension<PsiField> {
return JavaStubIndexKeys.FIELDS;
}
/**
* @deprecated Deprecated base method, please use {@link #getFields(String, Project, GlobalSearchScope)}
*/
@Deprecated
@Override
public Collection<PsiField> get(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return getFields(s, project, scope);
}
public Collection<PsiField> getFields(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return StubIndex.getElements(getKey(), s, project, new JavaSourceFilterScope(scope), PsiField.class);
}
}

View File

@@ -29,8 +29,16 @@ public class JavaFullClassNameIndex extends CharSequenceHashStubIndexExtension<P
return JavaStubIndexKeys.CLASS_FQN;
}
/**
* @deprecated Deprecated base method, please use {@link #getClasses(CharSequence, Project, GlobalSearchScope)}
*/
@Deprecated
@Override
public Collection<PsiClass> get(@NotNull CharSequence name, @NotNull Project project, @NotNull GlobalSearchScope scope) {
return getClasses(name, project, scope);
}
public Collection<PsiClass> getClasses(@NotNull CharSequence name, @NotNull Project project, @NotNull GlobalSearchScope scope) {
return StubIndex.getElements(getKey(), name, project, new JavaSourceFilterScope(scope), PsiClass.class);
}

View File

@@ -25,8 +25,16 @@ public class JavaMethodNameIndex extends StringStubIndexExtension<PsiMethod> {
return JavaStubIndexKeys.METHODS;
}
/**
* @deprecated Deprecated base method, please use {@link #getMethods(String, Project, GlobalSearchScope)}
*/
@Deprecated
@Override
public Collection<PsiMethod> get(@NotNull final String methodName, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return getMethods(methodName, project, scope);
}
public Collection<PsiMethod> getMethods(@NotNull final String methodName, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return StubIndex.getElements(getKey(), methodName, project, new JavaSourceFilterScope(scope), PsiMethod.class);
}
}

View File

@@ -30,8 +30,16 @@ public class JavaMethodParameterTypesIndex extends StringStubIndexExtension<PsiM
return JavaStubIndexKeys.METHOD_TYPES;
}
/**
* @deprecated Deprecated base method, please use {@link #getMethodParameterTypes(String, Project, GlobalSearchScope)}
*/
@Deprecated
@Override
public Collection<PsiMethod> get(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return getMethodParameterTypes(s, project, scope);
}
public Collection<PsiMethod> getMethodParameterTypes(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return StubIndex.getElements(getKey(), s, project, new JavaSourceFilterScope(scope), PsiMethod.class);
}
}

View File

@@ -45,8 +45,16 @@ public class JavaModuleNameIndex extends StringStubIndexExtension<PsiJavaModule>
return JavaStubIndexKeys.MODULE_NAMES;
}
/**
* @deprecated Deprecated base method, please use {@link #getModules(String, Project, GlobalSearchScope)}
*/
@Deprecated
@Override
public Collection<PsiJavaModule> get(@NotNull String name, @NotNull Project project, @NotNull GlobalSearchScope scope) {
return getModules(name, project, scope);
}
public Collection<PsiJavaModule> getModules(@NotNull String name, @NotNull Project project, @NotNull GlobalSearchScope scope) {
Collection<PsiJavaModule> modules = StubIndex.getElements(getKey(), name, project, new JavaSourceFilterScope(scope, true), PsiJavaModule.class);
if (modules.size() > 1) {
modules = filterVersions(project, modules);

View File

@@ -30,8 +30,16 @@ public class JavaShortClassNameIndex extends StringStubIndexExtension<PsiClass>
return JavaStubIndexKeys.CLASS_SHORT_NAMES;
}
/**
* @deprecated Deprecated base method, please use {@link #getClasses(String, Project, GlobalSearchScope)}
*/
@Deprecated
@Override
public Collection<PsiClass> get(@NotNull final String shortName, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return getClasses(shortName, project, scope);
}
public Collection<PsiClass> getClasses(@NotNull final String shortName, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return StubIndex.getElements(getKey(), shortName, project, new JavaSourceFilterScope(scope), PsiClass.class);
}

View File

@@ -26,8 +26,16 @@ public class JavaSuperClassNameOccurenceIndex extends StringStubIndexExtension<P
return JavaStubIndexKeys.SUPER_CLASSES;
}
/**
* @deprecated Deprecated base method, please use {@link #getOccurrences(String, Project, GlobalSearchScope)}
*/
@Deprecated
@Override
public Collection<PsiReferenceList> get(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return getOccurrences(s, project, scope);
}
public Collection<PsiReferenceList> getOccurrences(@NotNull final String s, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
return StubIndex.getElements(getKey(), s, project, new JavaSourceFilterScope(scope), PsiReferenceList.class);
}

View File

@@ -69,7 +69,7 @@ public class AnnotatedElementsSearcher implements QueryExecutor<PsiModifierListO
@NotNull SearchScope useScope, @NotNull Project project) {
return ReadAction.compute(() -> {
if (useScope instanceof GlobalSearchScope) {
return JavaAnnotationIndex.getInstance().get(annClass.getName(), project, (GlobalSearchScope)useScope);
return JavaAnnotationIndex.getInstance().getAnnotations(annClass.getName(), project, (GlobalSearchScope)useScope);
}
List<PsiAnnotation> result = new ArrayList<>();

View File

@@ -34,7 +34,7 @@ public class AnnotatedPackagesSearcher implements QueryExecutor<PsiPackage, Anno
final String annotationShortName = ReadAction.compute(() -> annClass.getName());
assert annotationShortName != null;
final Collection<PsiAnnotation> annotations = JavaAnnotationIndex.getInstance().get(annotationShortName, psiManager.getProject(),
final Collection<PsiAnnotation> annotations = JavaAnnotationIndex.getInstance().getAnnotations(annotationShortName, psiManager.getProject(),
useScope);
for (final PsiAnnotation annotation : annotations) {

View File

@@ -198,7 +198,7 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
GlobalSearchScope globalUseScope = ReadAction.compute(
() -> new JavaSourceFilterScope(GlobalSearchScopeUtil.toGlobalSearchScope(useScope, project)));
Collection<PsiReferenceList> candidates =
dumbService.runReadActionInSmartMode(() -> JavaSuperClassNameOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
dumbService.runReadActionInSmartMode(() -> JavaSuperClassNameOccurenceIndex.getInstance().getOccurrences(baseClassName, project, globalUseScope));
RelaxedDirectInheritorChecker checker = dumbService.runReadActionInSmartMode(() -> new RelaxedDirectInheritorChecker(baseClass));
// memory/speed optimisation: it really is a map(string -> PsiClass or List<PsiClass>)
@@ -258,7 +258,8 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
}
Collection<PsiAnonymousClass> anonymousCandidates =
dumbService.runReadActionInSmartMode(() -> JavaAnonymousClassBaseRefOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
dumbService.runReadActionInSmartMode(() -> JavaAnonymousClassBaseRefOccurenceIndex.getInstance()
.getOccurences(baseClassName, project, globalUseScope));
processConcurrentlyIfTooMany(anonymousCandidates, candidate-> {
if (dumbService.runReadActionInSmartMode(() -> checker.checkInheritance(candidate))) {