@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);
           }
         }
       }
     }
   }
 }
  @Override
  @Nullable
  public CommonProblemDescriptor[] checkElement(
      @NotNull final RefEntity refEntity,
      @NotNull final AnalysisScope scope,
      @NotNull final InspectionManager manager,
      @NotNull final GlobalInspectionContext globalContext,
      @NotNull final ProblemDescriptionsProcessor processor) {
    if (refEntity instanceof RefJavaElement) {
      final RefJavaElement refElement = (RefJavaElement) refEntity;

      if (refElement instanceof RefParameter) return null;
      if (refElement.isSyntheticJSP()) return null;

      // ignore entry points.
      if (refElement.isEntry()) return null;

      // ignore implicit constructors. User should not be able to see them.
      if (refElement instanceof RefImplicitConstructor) return null;

      if (refElement instanceof RefField
          && ((RefField) refElement).getElement() instanceof PsiEnumConstant) return null;

      // ignore library override methods.
      if (refElement instanceof RefMethod) {
        RefMethod refMethod = (RefMethod) refElement;
        if (refMethod.isExternalOverride()) return null;
        if (refMethod.isEntry()) return null;
      }

      // ignore anonymous classes. They do not have access modifiers.
      if (refElement instanceof RefClass) {
        RefClass refClass = (RefClass) refElement;
        if (refClass.isAnonymous()
            || refClass.isEntry()
            || refClass.isTestCase()
            || refClass.isServlet()
            || refClass.isApplet()
            || refClass.isLocalClass()) return null;
        if (isTopLevelClass(refClass) && !SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES) return null;
      }

      // ignore unreferenced code. They could be a potential entry points.
      if (refElement.getInReferences().isEmpty()) return null;

      // ignore interface members. They always have public access modifier.
      if (refElement.getOwner() instanceof RefClass) {
        RefClass refClass = (RefClass) refElement.getOwner();
        if (refClass.isInterface()) return null;
      }
      String access = getPossibleAccess(refElement);
      if (access != refElement.getAccessModifier() && access != null) {
        final PsiElement element = refElement.getElement();
        final PsiElement nameIdentifier =
            element != null ? HighlightUsagesHandler.getNameIdentifier(element) : null;
        if (nameIdentifier != null) {
          return new ProblemDescriptor[] {
            manager.createProblemDescriptor(
                nameIdentifier,
                access.equals(PsiModifier.PRIVATE)
                    ? CAN_BE_PRIVATE
                    : access.equals(PsiModifier.PACKAGE_LOCAL)
                        ? CAN_BE_PACKAGE_LOCAL
                        : CAN_BE_PROTECTED,
                new AcceptSuggestedAccess(globalContext.getRefManager(), access),
                ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                false)
          };
        }
      }
    }
    return null;
  }