Java: exclude static imports from Call Hierarchy (IJPL-157063)

GitOrigin-RevId: bef636c45bc6e88682ab00e10398e00b5355fdbf
This commit is contained in:
Bas Leijdekkers
2024-11-29 16:15:15 +00:00
committed by intellij-monorepo-bot
parent a39d8c3e31
commit 0e1e34768f
4 changed files with 23 additions and 6 deletions
@@ -130,7 +130,9 @@ public final class CallerMethodsTreeStructure extends HierarchyTreeStructure {
.search(enclosingElement, searchScope).findAll().stream()
.map(PsiReference::getElement)
.distinct()
.map(e -> new CallHierarchyNodeDescriptor(myProject, nodeDescriptor, e, false, false)).toArray();
.map(e -> new CallHierarchyNodeDescriptor(myProject, nodeDescriptor, e, false, false))
.filter(n -> n.getEnclosingElement() != null)
.toArray();
}
private static boolean areClassesRelated(@NotNull PsiClass expectedQualifierClass, @NotNull PsiClass receiverClass) {
@@ -0,0 +1,8 @@
import static java.util.Collections.EMPTY_LIST;
public class A {
public static void main(String[] args) {
System.out.println(EMPTY_LIST);
}
}
@@ -0,0 +1,3 @@
<node text="Collections.EMPTY_LIST (java.util)" base="true">
<node text="A.main(String[]) ()"/>
</node>
@@ -96,11 +96,7 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
}
public void testMethodRef() throws Exception {
doHierarchyTest(() -> {
PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass("A", ProjectScope.getProjectScope(getProject()));
PsiMember method = psiClass.findMethodsByName("testMethod", false) [0];
return new CalleeMethodsTreeStructure(getProject(), method, HierarchyBrowserBaseEx.SCOPE_PROJECT);
}, JavaHierarchyUtil.getComparator(myProject),"A.java");
doJavaCalleeTypeHierarchyTest("A", "testMethod", "A.java");
}
public void testField() throws Exception {
@@ -111,6 +107,14 @@ public class JavaCallHierarchyTest extends HierarchyViewTestBase {
}, JavaHierarchyUtil.getComparator(myProject),"A.java");
}
public void testStaticallyImportedField() throws Exception {
doHierarchyTest(() -> {
PsiClass psiClass = JavaPsiFacade.getInstance(getProject()).findClass("java.util.Collections", ProjectScope.getAllScope(getProject()));
PsiMember field = psiClass.findFieldByName("EMPTY_LIST", false);
return new CallerMethodsTreeStructure(getProject(), field, HierarchyBrowserBaseEx.SCOPE_PROJECT);
}, JavaHierarchyUtil.getComparator(myProject), "A.java");
}
public void testAnonymous() throws Exception {
doJavaCallerTypeHierarchyTest("A", "A", "A.java"); // IDEA-56615
}