use of com.intellij.psi.search.PsiReferenceProcessor 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;
}
Aggregations