protected boolean queryExternalUsagesRequests(
      final RefManager manager,
      final GlobalJavaInspectionContext globalContext,
      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(RefEntity refEntity) {
            if (refEntity instanceof RefMethod) {
              RefMethod refMethod = (RefMethod) refEntity;
              final PsiModifierListOwner element = refMethod.getElement();
              if (element instanceof PsiMethod) { // implicit construcors 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, true)
                          .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.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() {
                                        public boolean execute(PsiReference element) {
                                          refParameter.parameterReferenced(false);
                                          processor.ignoreElement(refParameter);
                                          found[0] = true;
                                          return false;
                                        }
                                      }));
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        });
    return false;
  }
Exemple #2
0
 @Nullable
 public static RefClass classFromExternalName(RefManager manager, String externalName) {
   return (RefClass)
       manager.getReference(
           ClassUtil.findPsiClass(PsiManager.getInstance(manager.getProject()), externalName));
 }
 @Nullable
 public static RefMethod methodFromExternalName(RefManager manager, String externalName) {
   return (RefMethod)
       manager.getReference(
           findPsiMethod(PsiManager.getInstance(manager.getProject()), externalName));
 }