コード例 #1
0
  private static void clearUsedParameters(
      @NotNull RefMethod refMethod, RefParameter[] params, boolean checkDeep) {
    RefParameter[] methodParms = refMethod.getParameters();

    for (int i = 0; i < methodParms.length; i++) {
      if (methodParms[i].isUsedForReading()) params[i] = null;
    }

    if (checkDeep) {
      for (RefMethod refOverride : refMethod.getDerivedMethods()) {
        clearUsedParameters(refOverride, params, checkDeep);
      }
    }
  }
コード例 #2
0
  public static ArrayList<RefParameter> getUnusedParameters(RefMethod refMethod) {
    boolean checkDeep = !refMethod.isStatic() && !refMethod.isConstructor();
    ArrayList<RefParameter> res = new ArrayList<RefParameter>();
    RefParameter[] methodParameters = refMethod.getParameters();
    RefParameter[] result = new RefParameter[methodParameters.length];
    System.arraycopy(methodParameters, 0, result, 0, methodParameters.length);

    clearUsedParameters(refMethod, result, checkDeep);

    for (RefParameter parameter : result) {
      if (parameter != null) {
        res.add(parameter);
      }
    }

    return res;
  }
コード例 #3
0
  @Nullable
  public CommonProblemDescriptor[] checkElement(
      RefEntity refEntity,
      AnalysisScope scope,
      InspectionManager manager,
      GlobalInspectionContext globalContext,
      ProblemDescriptionsProcessor processor) {
    ArrayList<ProblemDescriptor> problems = null;
    if (refEntity instanceof RefMethod) {
      final RefMethod refMethod = (RefMethod) refEntity;

      if (refMethod.hasSuperMethods()) return null;

      if (refMethod.isEntry()) return null;

      RefParameter[] parameters = refMethod.getParameters();
      for (RefParameter refParameter : parameters) {
        String value = refParameter.getActualValueIfSame();
        if (value != null) {
          if (problems == null) problems = new ArrayList<ProblemDescriptor>(1);
          final String paramName = refParameter.getName();
          problems.add(
              manager.createProblemDescriptor(
                  refParameter.getElement(),
                  InspectionsBundle.message(
                      "inspection.same.parameter.problem.descriptor",
                      "<code>" + paramName + "</code>",
                      "<code>" + value + "</code>"),
                  new InlineParameterValueFix(paramName, value),
                  ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                  false));
        }
      }
    }

    return problems == null ? null : problems.toArray(new CommonProblemDescriptor[problems.size()]);
  }