mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
[for java caller hierarchy] when occurrence in anonymous class search for usages of containing method (IDEA-73312), also search occurrences past constructors of anonymous classes (IDEA-56615)
This commit is contained in:
@@ -46,8 +46,15 @@ public final class CallerMethodsTreeStructure extends HierarchyTreeStructure {
|
||||
@NotNull
|
||||
@Override
|
||||
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
|
||||
final PsiMember enclosingElement = ((CallHierarchyNodeDescriptor)descriptor).getEnclosingElement();
|
||||
PsiMember enclosingElement = ((CallHierarchyNodeDescriptor)descriptor).getEnclosingElement();
|
||||
HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
|
||||
PsiClass clazz;
|
||||
|
||||
if (isAnonymousClass(enclosingElement)) {
|
||||
enclosingElement = CallHierarchyNodeDescriptor.getEnclosingElement(enclosingElement.getParent());
|
||||
} else if (enclosingElement instanceof PsiMethod && isAnonymousClass(clazz = enclosingElement.getContainingClass())) {
|
||||
enclosingElement = CallHierarchyNodeDescriptor.getEnclosingElement(clazz.getParent());
|
||||
}
|
||||
if (!(enclosingElement instanceof PsiMethod) || nodeDescriptor == null) {
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
@@ -80,6 +87,10 @@ public final class CallerMethodsTreeStructure extends HierarchyTreeStructure {
|
||||
return methodToDescriptorMap.values().toArray(new Object[methodToDescriptorMap.size()]);
|
||||
}
|
||||
|
||||
private static boolean isAnonymousClass(PsiMember enclosingElement) {
|
||||
return enclosingElement instanceof PsiClass && ((PsiClass)enclosingElement).getQualifiedName() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlwaysShowPlus() {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
interface Runnable {
|
||||
void run() {}
|
||||
}
|
||||
|
||||
class A {
|
||||
void foo() {
|
||||
action(new Runnable() {
|
||||
public void run() {
|
||||
doIt();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void doIt() {}
|
||||
|
||||
static void action(Runnable action) {
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
|
||||
class Bar extends Runnable {
|
||||
Bar() {
|
||||
run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<node text="A.doIt() ()" base="true">
|
||||
<node text="Anonymous in foo() in A.run() ()"/>
|
||||
</node>
|
||||
15
java/java-tests/testData/ide/hierarchy/call/anonymous/A.java
Normal file
15
java/java-tests/testData/ide/hierarchy/call/anonymous/A.java
Normal file
@@ -0,0 +1,15 @@
|
||||
abstract class A {
|
||||
A(int a) {}
|
||||
|
||||
abstract void g();
|
||||
|
||||
void h() {
|
||||
f();
|
||||
}
|
||||
|
||||
void f() {
|
||||
A x = new A(42) {
|
||||
void g() {}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<node text="A.A(int) ()" base="true">
|
||||
<node text="Anonymous in f() in A ()">
|
||||
<node text="A.h() ()"/>
|
||||
</node>
|
||||
</node>
|
||||
@@ -57,6 +57,14 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
|
||||
doJavaCallTypeHierarchyTest("A", "main", "B.java", "A.java");
|
||||
}
|
||||
|
||||
public void testAnonymous() throws Exception {
|
||||
doJavaCallTypeHierarchyTest("A", "A", "A.java");
|
||||
}
|
||||
|
||||
public void testAnonymous2() throws Exception {
|
||||
doJavaCallTypeHierarchyTest("A", "doIt", "A.java");
|
||||
}
|
||||
|
||||
public void testActionAvailableInXml() throws Exception {
|
||||
configureByText(XmlFileType.INSTANCE, "<foo>java.lang.Str<caret>ing</foo>");
|
||||
BrowseTypeHierarchyAction action = new BrowseTypeHierarchyAction();
|
||||
|
||||
Reference in New Issue
Block a user