use of com.intellij.psi.impl.light.LightMemberReference in project intellij-community by JetBrains.
the class JavaCallReferenceProcessor 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 myProject = data.getProject();
if (reference instanceof PsiReferenceExpression) {
final PsiExpression qualifier = ((PsiReferenceExpression) reference).getQualifierExpression();
if (qualifier instanceof PsiSuperExpression) {
// filter super.foo() call inside foo() and similar cases (bug 8411)
final PsiClass superClass = PsiUtil.resolveClassInType(qualifier.getType());
if (superClass == 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 PsiAnonymousClass) {
if (((PsiAnonymousClass) parent).getBaseClassReference() != reference) {
return true;
}
} else if (!(reference instanceof LightMemberReference)) {
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(myProject, (CallHierarchyNodeDescriptor) data.getNodeDescriptor(), element, false, true);
methodToDescriptorMap.put(key, d);
} else if (!d.hasReference(reference)) {
d.incrementUsageCount();
}
d.addReference(reference);
}
return false;
}
use of com.intellij.psi.impl.light.LightMemberReference in project intellij-community by JetBrains.
the class GroovyConstructorUsagesSearcher method processImplicitConstructorCall.
private static void processImplicitConstructorCall(@NotNull final PsiMember usage, final Processor<PsiReference> processor, final PsiMethod constructor) {
if (constructor instanceof GrMethod) {
GrParameter[] grParameters = (GrParameter[]) constructor.getParameterList().getParameters();
if (grParameters.length > 0 && !grParameters[0].isOptional())
return;
} else if (constructor.getParameterList().getParameters().length > 0)
return;
PsiManager manager = constructor.getManager();
if (manager.areElementsEquivalent(usage, constructor) || manager.areElementsEquivalent(constructor.getContainingClass(), usage.getContainingClass()))
return;
processor.process(new LightMemberReference(manager, usage, PsiSubstitutor.EMPTY) {
@Override
public PsiElement getElement() {
return usage;
}
@Override
public TextRange getRangeInElement() {
if (usage instanceof PsiClass) {
PsiIdentifier identifier = ((PsiClass) usage).getNameIdentifier();
if (identifier != null)
return TextRange.from(identifier.getStartOffsetInParent(), identifier.getTextLength());
} else if (usage instanceof PsiMethod) {
PsiIdentifier identifier = ((PsiMethod) usage).getNameIdentifier();
if (identifier != null)
return TextRange.from(identifier.getStartOffsetInParent(), identifier.getTextLength());
}
return super.getRangeInElement();
}
});
}
use of com.intellij.psi.impl.light.LightMemberReference in project intellij-community by JetBrains.
the class ConstructorReferencesSearchHelper method processImplicitConstructorCall.
private boolean processImplicitConstructorCall(@NotNull final PsiMember usage, @NotNull final Processor<PsiReference> processor, @NotNull final PsiMethod constructor, @NotNull final Project project, @NotNull final PsiClass containingClass) {
if (containingClass instanceof PsiAnonymousClass)
return true;
PsiClass ctrClass = constructor.getContainingClass();
if (ctrClass == null)
return true;
boolean isImplicitSuper = DumbService.getInstance(project).runReadActionInSmartMode(() -> myManager.areElementsEquivalent(ctrClass, containingClass.getSuperClass()));
if (!isImplicitSuper) {
return true;
}
PsiElement resolved = JavaResolveUtil.resolveImaginarySuperCallInThisPlace(usage, project, ctrClass);
boolean resolvesToThisConstructor = DumbService.getInstance(project).runReadActionInSmartMode(() -> myManager.areElementsEquivalent(constructor, resolved));
if (!resolvesToThisConstructor) {
return true;
}
return processor.process(new LightMemberReference(myManager, usage, PsiSubstitutor.EMPTY) {
@Override
public PsiElement getElement() {
return usage;
}
@Override
public TextRange getRangeInElement() {
if (usage instanceof PsiNameIdentifierOwner) {
PsiElement identifier = ((PsiNameIdentifierOwner) usage).getNameIdentifier();
if (identifier != null) {
final int startOffsetInParent = identifier.getStartOffsetInParent();
if (startOffsetInParent >= 0) {
// -1 for light elements generated e.g. by lombok
return TextRange.from(startOffsetInParent, identifier.getTextLength());
}
}
}
return super.getRangeInElement();
}
});
}
Aggregations