use of com.intellij.psi.search.PsiReferenceProcessorAdapter in project intellij-community by JetBrains.
the class UnusedParametersInspection method queryExternalUsagesRequests.
protected boolean queryExternalUsagesRequests(@NotNull final RefManager manager, @NotNull final GlobalJavaInspectionContext globalContext, @NotNull final ProblemDescriptionsProcessor processor) {
final Project project = manager.getProject();
for (RefElement entryPoint : globalContext.getEntryPointsManager(manager).getEntryPoints()) {
processor.ignoreElement(entryPoint);
}
final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(project);
final AnalysisScope scope = manager.getScope();
manager.iterate(new RefJavaVisitor() {
@Override
public void visitElement(@NotNull RefEntity refEntity) {
if (refEntity instanceof RefMethod) {
RefMethod refMethod = (RefMethod) refEntity;
final PsiModifierListOwner element = refMethod.getElement();
if (element instanceof PsiMethod) {
//implicit constructors are invisible
PsiMethod psiMethod = (PsiMethod) element;
if (!refMethod.isStatic() && !refMethod.isConstructor() && !PsiModifier.PRIVATE.equals(refMethod.getAccessModifier())) {
final ArrayList<RefParameter> unusedParameters = getUnusedParameters(refMethod);
if (unusedParameters.isEmpty())
return;
PsiMethod[] derived = OverridingMethodsSearch.search(psiMethod).toArray(PsiMethod.EMPTY_ARRAY);
for (final RefParameter refParameter : unusedParameters) {
if (refMethod.isAbstract() && derived.length == 0) {
refParameter.parameterReferenced(false);
processor.ignoreElement(refParameter);
} else {
int idx = refParameter.getIndex();
final boolean[] found = { false };
for (int i = 0; i < derived.length && !found[0]; i++) {
if (scope == null || !scope.contains(derived[i])) {
final PsiParameter[] parameters = derived[i].getParameterList().getParameters();
if (parameters.length >= idx)
continue;
PsiParameter psiParameter = parameters[idx];
ReferencesSearch.search(psiParameter, helper.getUseScope(psiParameter), false).forEach(new PsiReferenceProcessorAdapter(new PsiReferenceProcessor() {
@Override
public boolean execute(PsiReference element) {
refParameter.parameterReferenced(false);
processor.ignoreElement(refParameter);
found[0] = true;
return false;
}
}));
}
}
}
}
}
}
}
}
});
return false;
}
use of com.intellij.psi.search.PsiReferenceProcessorAdapter in project intellij-community by JetBrains.
the class JavaFindUsagesHelper method addMethodsUsages.
private static boolean addMethodsUsages(@NotNull final PsiClass aClass, @NotNull final PsiManager manager, @NotNull final JavaClassFindUsagesOptions options, @NotNull final Processor<UsageInfo> processor) {
if (options.isIncludeInherited) {
final PsiMethod[] methods = ReadAction.compute(aClass::getAllMethods);
for (int i = 0; i < methods.length; i++) {
final PsiMethod method = methods[i];
// filter overridden methods
final int finalI = i;
final PsiClass methodClass = ReadAction.compute(() -> {
MethodSignature methodSignature = method.getSignature(PsiSubstitutor.EMPTY);
for (int j = 0; j < finalI; j++) {
if (methodSignature.equals(methods[j].getSignature(PsiSubstitutor.EMPTY)))
return null;
}
return method.getContainingClass();
});
if (methodClass == null)
continue;
boolean equivalent = ReadAction.compute(() -> manager.areElementsEquivalent(methodClass, aClass));
if (equivalent) {
if (!addElementUsages(method, options, processor))
return false;
} else {
MethodReferencesSearch.SearchParameters parameters = new MethodReferencesSearch.SearchParameters(method, options.searchScope, true, options.fastTrack);
boolean success = MethodReferencesSearch.search(parameters).forEach(new PsiReferenceProcessorAdapter(reference -> {
addResultFromReference(reference, methodClass, manager, aClass, options, processor);
return true;
}));
if (!success)
return false;
}
}
} else {
PsiMethod[] methods = ReadAction.compute(aClass::getMethods);
for (PsiMethod method : methods) {
if (!addElementUsages(method, options, processor))
return false;
}
}
return true;
}
Aggregations