mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-64816 Groovy: "Find Usages" doesn't find usages of class members accesses as Groovy properties
This commit is contained in:
+20
-11
@@ -57,33 +57,35 @@ public class GroovyFindUsagesHandlerFactory extends JavaFindUsagesHandlerFactory
|
||||
@Override
|
||||
public PsiElement[] getSecondaryElements() {
|
||||
PsiElement element = getPsiElement();
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return PsiElement.EMPTY_ARRAY;
|
||||
final PsiField field = (PsiField)element;
|
||||
PsiClass containingClass = field.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
PsiMethod getter = GroovyPropertyUtils.findGetterForField(field);
|
||||
PsiMethod setter = GroovyPropertyUtils.findSetterForField(field);
|
||||
if (getter != null || setter != null) {
|
||||
PsiMethod[] getters = GroovyPropertyUtils.getAllGettersByField(field);
|
||||
PsiMethod[] setters = GroovyPropertyUtils.getAllSettersByField(field);
|
||||
if (getters.length + setters.length > 0) {
|
||||
final boolean doSearch;
|
||||
if ((getter == null || !getter.isPhysical()) && (setter == null || !setter.isPhysical())) {
|
||||
doSearch = true;
|
||||
}
|
||||
else {
|
||||
if (arePhysical(getters) || arePhysical(setters)) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return PsiElement.EMPTY_ARRAY;
|
||||
doSearch = Messages.showDialog(FindBundle.message("find.field.accessors.prompt", field.getName()),
|
||||
FindBundle.message("find.field.accessors.title"),
|
||||
new String[]{CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText()}, 0,
|
||||
Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE;
|
||||
}
|
||||
else {
|
||||
doSearch = true;
|
||||
}
|
||||
if (doSearch) {
|
||||
final List<PsiElement> elements = new ArrayList<PsiElement>();
|
||||
if (getter != null) {
|
||||
for (PsiMethod getter : getters) {
|
||||
ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(getter, ACTION_STRING));
|
||||
}
|
||||
if (setter != null) {
|
||||
|
||||
for (PsiMethod setter : setters) {
|
||||
ContainerUtil.addAll(elements, SuperMethodWarningUtil.checkSuperMethods(setter, ACTION_STRING));
|
||||
}
|
||||
return elements.toArray(new PsiElement[elements.size()]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return PsiElement.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
@@ -92,4 +94,11 @@ public class GroovyFindUsagesHandlerFactory extends JavaFindUsagesHandlerFactory
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean arePhysical(PsiMethod[] methods) {
|
||||
for (PsiMethod method : methods) {
|
||||
if (method.isPhysical()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+44
-10
@@ -42,6 +42,15 @@ public class GroovyPropertyUtils {
|
||||
private GroovyPropertyUtils() {
|
||||
}
|
||||
|
||||
public static PsiMethod[] getAllSettersByField(PsiField field) {
|
||||
return getAllSetters(field.getContainingClass(), field.getName(), field.hasModifierProperty(GrModifier.STATIC), false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PsiMethod[] getAllGettersByField(PsiField field) {
|
||||
return getAllGetters(field.getContainingClass(), field.getName(), field.hasModifierProperty(GrModifier.STATIC), false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiMethod findSetterForField(PsiField field) {
|
||||
final PsiClass containingClass = field.getContainingClass();
|
||||
@@ -84,11 +93,9 @@ public class GroovyPropertyUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use PropertyUtil.getAllProperties() instead.
|
||||
*/
|
||||
@Deprecated()
|
||||
public static List<PsiMethod> getAllPropertyGetters(@NotNull PsiClass aClass, @Nullable Boolean isStatic, boolean checkSuperClasses) {
|
||||
@NotNull
|
||||
public static PsiMethod[] getAllGetters(PsiClass aClass, String propertyName, boolean isStatic, boolean checkSuperClasses) {
|
||||
if (aClass == null) return PsiMethod.EMPTY_ARRAY;
|
||||
PsiMethod[] methods;
|
||||
if (checkSuperClasses) {
|
||||
methods = aClass.getAllMethods();
|
||||
@@ -97,19 +104,46 @@ public class GroovyPropertyUtils {
|
||||
methods = aClass.getMethods();
|
||||
}
|
||||
|
||||
List<PsiMethod> res = new ArrayList<PsiMethod>(methods.length);
|
||||
|
||||
List<PsiMethod> result = new ArrayList<PsiMethod>();
|
||||
for (PsiMethod method : methods) {
|
||||
if (isStatic != null && method.hasModifierProperty(PsiModifier.STATIC) != isStatic) continue;
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC) != isStatic) continue;
|
||||
|
||||
if (isSimplePropertyGetter(method)) {
|
||||
res.add(method);
|
||||
if (propertyName.equals(getPropertyNameByGetter(method))) {
|
||||
result.add(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return result.toArray(new PsiMethod[result.size()]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PsiMethod[] getAllSetters(PsiClass aClass, String propertyName, boolean isStatic, boolean checkSuperClasses) {
|
||||
if (aClass == null) return PsiMethod.EMPTY_ARRAY;
|
||||
PsiMethod[] methods;
|
||||
if (checkSuperClasses) {
|
||||
methods = aClass.getAllMethods();
|
||||
}
|
||||
else {
|
||||
methods = aClass.getMethods();
|
||||
}
|
||||
|
||||
List<PsiMethod> result = new ArrayList<PsiMethod>();
|
||||
for (PsiMethod method : methods) {
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC) != isStatic) continue;
|
||||
|
||||
if (isSimplePropertySetter(method)) {
|
||||
if (propertyName.equals(getPropertyNameBySetter(method))) {
|
||||
result.add(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.toArray(new PsiMethod[result.size()]);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static PsiMethod findPropertyGetter(@Nullable PsiClass aClass,
|
||||
String propertyName,
|
||||
|
||||
Reference in New Issue
Block a user