@Override
 public void onInitialize(RefElement refElement) {
   ((RefElementImpl) refElement).setFlag(true, CAN_BE_FINAL_MASK);
   if (refElement instanceof RefClass) {
     final RefClass refClass = (RefClass) refElement;
     final PsiClass psiClass = refClass.getElement();
     if (refClass.isEntry()) {
       ((RefClassImpl) refClass).setFlag(false, CAN_BE_FINAL_MASK);
       return;
     }
     if (refClass.isAbstract() || refClass.isAnonymous() || refClass.isInterface()) {
       ((RefClassImpl) refClass).setFlag(false, CAN_BE_FINAL_MASK);
       return;
     }
     if (!refClass.isSelfInheritor(psiClass)) {
       for (PsiClass psiSuperClass : psiClass.getSupers()) {
         if (myManager.belongsToScope(psiSuperClass)) {
           RefClass refSuperClass = (RefClass) myManager.getReference(psiSuperClass);
           if (refSuperClass != null) {
             ((RefClassImpl) refSuperClass).setFlag(false, CAN_BE_FINAL_MASK);
           }
         }
       }
     }
   } else if (refElement instanceof RefMethod) {
     final RefMethod refMethod = (RefMethod) refElement;
     final PsiElement element = refMethod.getElement();
     if (element instanceof PsiMethod) {
       PsiMethod psiMethod = (PsiMethod) element;
       if (refMethod.isConstructor()
           || refMethod.isAbstract()
           || refMethod.isStatic()
           || PsiModifier.PRIVATE.equals(refMethod.getAccessModifier())
           || refMethod.getOwnerClass().isAnonymous()
           || refMethod.getOwnerClass().isInterface()) {
         ((RefMethodImpl) refMethod).setFlag(false, CAN_BE_FINAL_MASK);
       }
       if (PsiModifier.PRIVATE.equals(refMethod.getAccessModifier())
           && refMethod.getOwner() != null
           && !(refMethod.getOwnerClass().getOwner() instanceof RefElement)) {
         ((RefMethodImpl) refMethod).setFlag(false, CAN_BE_FINAL_MASK);
       }
       for (PsiMethod psiSuperMethod : psiMethod.findSuperMethods()) {
         if (myManager.belongsToScope(psiSuperMethod)) {
           RefMethod refSuperMethod = (RefMethod) myManager.getReference(psiSuperMethod);
           if (refSuperMethod != null) {
             ((RefMethodImpl) refSuperMethod).setFlag(false, CAN_BE_FINAL_MASK);
           }
         }
       }
     }
   }
 }
  private static boolean isAppMain(PsiMethod psiMethod, RefMethod refMethod) {
    if (!refMethod.isStatic()) return false;
    if (!PsiType.VOID.equals(psiMethod.getReturnType())) return false;

    PsiMethod appMainPattern = ((RefMethodImpl) refMethod).getRefJavaManager().getAppMainPattern();
    if (MethodSignatureUtil.areSignaturesEqual(psiMethod, appMainPattern)) return true;

    PsiMethod appPremainPattern =
        ((RefMethodImpl) refMethod).getRefJavaManager().getAppPremainPattern();
    if (MethodSignatureUtil.areSignaturesEqual(psiMethod, appPremainPattern)) return true;

    PsiMethod appAgentmainPattern =
        ((RefMethodImpl) refMethod).getRefJavaManager().getAppAgentmainPattern();
    return MethodSignatureUtil.areSignaturesEqual(psiMethod, appAgentmainPattern);
  }
  @Nullable
  public CommonProblemDescriptor[] checkElement(
      final RefEntity refEntity,
      final AnalysisScope scope,
      final InspectionManager manager,
      final GlobalInspectionContext globalContext,
      final ProblemDescriptionsProcessor processor) {
    if (refEntity instanceof RefMethod) {
      final RefMethod refMethod = (RefMethod) refEntity;

      if (refMethod.isSyntheticJSP()) return null;

      if (refMethod.isExternalOverride()) return null;

      if (!(refMethod.isStatic() || refMethod.isConstructor())
          && !refMethod.getSuperMethods().isEmpty()) return null;

      if ((refMethod.isAbstract() || refMethod.getOwnerClass().isInterface())
          && refMethod.getDerivedMethods().isEmpty()) return null;

      if (RefUtil.isEntryPoint(refMethod)) return null;

      if (refMethod.isAppMain()) return null;

      final ArrayList<RefParameter> unusedParameters = getUnusedParameters(refMethod);

      if (unusedParameters.isEmpty()) return null;

      final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>();
      for (RefParameter refParameter : unusedParameters) {
        final PsiIdentifier psiIdentifier = refParameter.getElement().getNameIdentifier();
        if (psiIdentifier != null) {
          result.add(
              manager.createProblemDescriptor(
                  psiIdentifier,
                  refMethod.isAbstract()
                      ? InspectionsBundle.message("inspection.unused.parameter.composer")
                      : InspectionsBundle.message("inspection.unused.parameter.composer1"),
                  new AcceptSuggested(
                      globalContext.getRefManager(), processor, refParameter.toString()),
                  ProblemHighlightType.LIKE_UNUSED_SYMBOL,
                  false));
        }
      }
      return result.toArray(new CommonProblemDescriptor[result.size()]);
    }
    return null;
  }
  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;
  }