use of com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor in project intellij-community by JetBrains.
the class GrCallReferenceProcessor method process.
@Override
public boolean process(@NotNull PsiReference reference, @NotNull JavaCallHierarchyData data) {
PsiClass originalClass = data.getOriginalClass();
PsiMethod method = data.getMethod();
Set<PsiMethod> methodsToFind = data.getMethodsToFind();
PsiMethod methodToFind = data.getMethodToFind();
PsiClassType originalType = data.getOriginalType();
Map<PsiMember, NodeDescriptor> methodToDescriptorMap = data.getResultMap();
Project project = data.getProject();
if (reference instanceof GrReferenceExpression) {
final GrExpression qualifier = ((GrReferenceExpression) reference).getQualifierExpression();
if (org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isSuperReference(qualifier)) {
// filter super.foo() call inside foo() and similar cases (bug 8411)
assert qualifier != null;
final PsiClass superClass = PsiUtil.resolveClassInType(qualifier.getType());
if (originalClass == null || originalClass.isInheritor(superClass, true)) {
return true;
}
}
if (qualifier != null && !methodToFind.hasModifierProperty(PsiModifier.STATIC)) {
final PsiType qualifierType = qualifier.getType();
if (qualifierType instanceof PsiClassType && !TypeConversionUtil.isAssignable(qualifierType, originalType) && methodToFind != method) {
final PsiClass psiClass = ((PsiClassType) qualifierType).resolve();
if (psiClass != null) {
final PsiMethod callee = psiClass.findMethodBySignature(methodToFind, true);
if (callee != null && !methodsToFind.contains(callee)) {
// skip sibling methods
return true;
}
}
}
}
} else {
if (!(reference instanceof PsiElement)) {
return true;
}
final PsiElement parent = ((PsiElement) reference).getParent();
if (parent instanceof PsiNewExpression) {
if (((PsiNewExpression) parent).getClassReference() != reference) {
return true;
}
} else if (parent instanceof GrAnonymousClassDefinition) {
if (((GrAnonymousClassDefinition) parent).getBaseClassReferenceGroovy() != reference) {
return true;
}
} else {
return true;
}
}
final PsiElement element = reference.getElement();
final PsiMember key = CallHierarchyNodeDescriptor.getEnclosingElement(element);
synchronized (methodToDescriptorMap) {
CallHierarchyNodeDescriptor d = (CallHierarchyNodeDescriptor) methodToDescriptorMap.get(key);
if (d == null) {
d = new CallHierarchyNodeDescriptor(project, (CallHierarchyNodeDescriptor) data.getNodeDescriptor(), element, false, true);
methodToDescriptorMap.put(key, d);
} else if (!d.hasReference(reference)) {
d.incrementUsageCount();
}
d.addReference(reference);
}
return true;
}
use of com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor in project kotlin by JetBrains.
the class KotlinCallTreeStructure method createNodeDescriptor.
@Nullable
private static HierarchyNodeDescriptor createNodeDescriptor(Project project, PsiElement element, HierarchyNodeDescriptor parent, boolean navigateToReference, boolean wrapAsLightElements) {
PsiElement nodeElement = element;
if (wrapAsLightElements && element instanceof KtElement) {
nodeElement = CollectionsKt.firstOrNull(LightClassUtilsKt.toLightElements((KtElement) element));
}
if (nodeElement == null)
return null;
boolean root = (parent == null);
return nodeElement instanceof KtElement ? new KotlinCallHierarchyNodeDescriptor(project, parent, nodeElement, root, navigateToReference) : new CallHierarchyNodeDescriptor(project, parent, nodeElement, root, navigateToReference);
}
use of com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor in project kotlin by JetBrains.
the class KotlinCallTreeStructure method addNodeDescriptorForElement.
protected static void addNodeDescriptorForElement(PsiReference reference, PsiElement element, Map<PsiElement, HierarchyNodeDescriptor> declarationToDescriptorMap, HierarchyNodeDescriptor descriptor, boolean wrapAsLightElements) {
HierarchyNodeDescriptor d = declarationToDescriptorMap.get(element);
if (d == null) {
d = createNodeDescriptor(element.getProject(), element, descriptor, true, wrapAsLightElements);
if (d == null)
return;
declarationToDescriptorMap.put(element, d);
} else if (d instanceof CallHierarchyNodeDescriptor) {
((CallHierarchyNodeDescriptor) d).incrementUsageCount();
}
if (d instanceof CallHierarchyNodeDescriptor) {
((CallHierarchyNodeDescriptor) d).addReference(reference);
} else if (d instanceof KotlinCallHierarchyNodeDescriptor) {
((KotlinCallHierarchyNodeDescriptor) d).addReference(reference);
}
}
use of com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor in project kotlin by JetBrains.
the class KotlinCalleeMethodsTreeStructure method buildChildren.
@NotNull
@Override
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
PsiElement targetElement = getTargetElement(descriptor);
// Kotlin class constructor invoked from Java code
if (targetElement instanceof PsiMethod) {
PsiMethod psiMethod = (PsiMethod) targetElement;
if (psiMethod.isConstructor()) {
PsiClass psiClass = psiMethod.getContainingClass();
PsiElement navigationElement = psiClass != null ? psiClass.getNavigationElement() : null;
if (navigationElement instanceof KtClass) {
return buildChildrenByKotlinTarget(descriptor, (KtElement) navigationElement);
}
}
}
// Kotlin function or property invoked from Java code
if (targetElement instanceof KtLightMethod) {
return buildChildrenByKotlinTarget(descriptor, ((KtLightMethod) targetElement).getKotlinOrigin());
}
if (targetElement instanceof KtElement) {
return buildChildrenByKotlinTarget(descriptor, (KtElement) targetElement);
}
CallHierarchyNodeDescriptor javaDescriptor = descriptor instanceof CallHierarchyNodeDescriptor ? (CallHierarchyNodeDescriptor) descriptor : ((KotlinCallHierarchyNodeDescriptor) descriptor).getJavaDelegate();
return javaTreeStructure.getChildElements(javaDescriptor);
}
Aggregations