@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
  public void addTypeReference(PsiElement psiElement, PsiType psiType, RefManager refManager) {
    RefClass ownerClass = getOwnerClass(refManager, psiElement);

    if (ownerClass != null) {
      psiType = psiType.getDeepComponentType();

      if (psiType instanceof PsiClassType) {
        PsiClass psiClass = PsiUtil.resolveClassInType(psiType);
        if (psiClass != null && refManager.belongsToScope(psiClass)) {
          RefClassImpl refClass = (RefClassImpl) refManager.getReference(psiClass);
          if (refClass != null) {
            refClass.addTypeReference(ownerClass);
          }
        }
      }
    }
  }