mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-331486 [Java]: check search scope for enum constant declarations when searching constructor references
GitOrigin-RevId: f85d71a8fd56dea17266354c912cb13292083b5a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4045dfeecb
commit
7f0b84b0f2
+4
-3
@@ -56,7 +56,7 @@ class ConstructorReferencesSearchHelper {
|
||||
});
|
||||
|
||||
if (isEnum[0]) {
|
||||
if (!processEnumReferences(processor, constructor, project, containingClass)) return false;
|
||||
if (!processEnumReferences(processor, constructor, project, containingClass, searchScope)) return false;
|
||||
}
|
||||
|
||||
// search usages like "new XXX(..)"
|
||||
@@ -114,10 +114,11 @@ class ConstructorReferencesSearchHelper {
|
||||
private static boolean processEnumReferences(@NotNull Processor<? super PsiReference> processor,
|
||||
@NotNull PsiMethod constructor,
|
||||
@NotNull Project project,
|
||||
@NotNull PsiClass aClass) {
|
||||
@NotNull PsiClass aClass,
|
||||
@NotNull SearchScope searchScope) {
|
||||
return DumbService.getInstance(project).runReadActionInSmartMode(() -> {
|
||||
for (PsiField field : aClass.getFields()) {
|
||||
if (field instanceof PsiEnumConstant) {
|
||||
if (field instanceof PsiEnumConstant && PsiSearchScopeUtil.isInScope(searchScope, field)) {
|
||||
PsiReference reference = field.getReference();
|
||||
if (reference != null && reference.isReferenceTo(constructor) && !processor.process(reference)) {
|
||||
return false;
|
||||
|
||||
+20
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.codeVision
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.JavaInheritorsCodeVisionProvider
|
||||
@@ -91,6 +91,25 @@ class JavaCodeVisionProviderTest : CodeVisionTestCase() {
|
||||
}
|
||||
""".trimIndent(), JavaReferencesCodeVisionProvider().groupId)
|
||||
|
||||
fun testEnumConstructor() = doTest("""
|
||||
enum LocationType {/*<# [no usages] #>*/
|
||||
FOREST("Forest"),/*<# [no usages] #>*/
|
||||
PLAIN("Plain"),/*<# [no usages] #>*/
|
||||
DESERT("Desert"),/*<# [no usages] #>*/
|
||||
HILLS("hills");/*<# [no usages] #>*/
|
||||
|
||||
private final String typeName;/*<# [2 usages] #>*/
|
||||
|
||||
LocationType(String typeName) {/*<# [4 usages] #>*/
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
public String getTypeName() {/*<# [no usages] #>*/
|
||||
return typeName;
|
||||
}
|
||||
}
|
||||
""".trimIndent(), JavaReferencesCodeVisionProvider().groupId)
|
||||
|
||||
fun testClassAtZeroOffset() = doTest("""
|
||||
class A { /*<# [no usages] #>*/
|
||||
enum E { /*<# [6 usages] #>*/
|
||||
|
||||
Reference in New Issue
Block a user