more on IDEA-160274 Field Call Hierarchy

When a field is used in a method, the hierarchy takes you to the line of the method definition
instead of the line in the method where the field is used.

GitOrigin-RevId: 47e9df4670e20c4cd07c3ca64f68ba1bdb826a50
This commit is contained in:
Sergey Ignatov
2019-10-12 10:18:08 +00:00
committed by intellij-monorepo-bot
parent 7e258c1dc0
commit 060b465fff
3 changed files with 8 additions and 11 deletions
@@ -9,11 +9,9 @@ import com.intellij.psi.*;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.MethodReferencesSearch;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.JBIterable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@@ -98,15 +96,10 @@ public final class CallerMethodsTreeStructure extends HierarchyTreeStructure {
assert enclosingElement instanceof PsiField;
Set<PsiMethod> methodsToFindForField = new HashSet<>();
ReferencesSearch.search(enclosingElement, enclosingElement.getUseScope()).forEach(reference -> {
PsiMethod method = PsiTreeUtil.getParentOfType(reference.getElement(), PsiMethod.class);
if (method != null) methodsToFindForField.add(method);
});
return JBIterable.from(methodsToFindForField)
.map(method -> new CallHierarchyNodeDescriptor(myProject, nodeDescriptor, method, false, false))
.toArray(new CallHierarchyNodeDescriptor[]{});
return ReferencesSearch
.search(enclosingElement, enclosingElement.getUseScope()).findAll().stream()
.map(PsiReference::getElement).distinct()
.map(e -> new CallHierarchyNodeDescriptor(myProject, nodeDescriptor, e, false, false)).toArray();
}
private static boolean isLocalOrAnonymousClass(PsiMember enclosingElement) {
@@ -7,6 +7,7 @@ public class A {
public static void main2(String[] args) {
testField += "";
testField += "b";
}
public static void main3(String[] args) {
@@ -5,6 +5,9 @@
<node text="A.main2(String[]) ()">
<node text="A.superMain(String[]) ()"/>
</node>
<node text="A.main2(String[]) ()">
<node text="A.superMain(String[]) ()"/>
</node>
<node text="A.main3(String[]) ()">
<node text="A.superMain(String[]) ()"/>
</node>