boolean (RefElement from, RefJavaElement to, String accessModifier) { if (PsiModifier.PUBLIC.equals(accessModifier)) return true; final RefJavaUtil refUtil = RefJavaUtil.getInstance(); if (PsiModifier.PACKAGE_LOCAL.equals(accessModifier)) { return RefJavaUtil.getPackage(from) == RefJavaUtil.getPackage(to); } RefClass fromTopLevel = refUtil.getTopLevelClass(from); RefClass toTopLevel = refUtil.getTopLevelClass(to); RefClass fromOwner = refUtil.getOwnerClass(from); RefClass toOwner = refUtil.getOwnerClass(to); if (PsiModifier.PROTECTED.equals(accessModifier)) { if (to instanceof RefJavaElementImpl && ((RefJavaElementImpl)to).isProtectedAccessForbidden()) { return false; } return fromTopLevel != null && refUtil.isInheritor(fromTopLevel, toOwner) || fromOwner != null && refUtil.isInheritor(fromOwner, toTopLevel) || toTopLevel != null && toTopLevel == fromTopLevel; } if (PsiModifier.PRIVATE.equals(accessModifier)) { if (SUGGEST_PRIVATE_FOR_INNERS) { //TODO final PsiClass fromTopLevelElement = fromTopLevel != null ? (PsiClass)fromTopLevel.getPsiElement() : null; final PsiElement target = to.getPsiElement(); if (fromTopLevelElement != null) { if (containsReferenceTo(fromTopLevelElement.getExtendsList(), target)) return false; if (containsReferenceTo(fromTopLevelElement.getImplementsList(), target)) return false; if (containsReferenceTo(fromTopLevelElement.getModifierList(), target)) return false; } return fromTopLevel == toOwner || fromOwner == toTopLevel || toOwner != null && ( refUtil.getOwnerClass(toOwner) == from || from instanceof RefMethod && toOwner == ((RefMethod)from).getOwnerClass() || from instanceof RefField && toOwner == ((RefField)from).getOwnerClass()); } if (fromOwner != null && fromOwner.isStatic() && !to.isStatic() && refUtil.isInheritor(fromOwner, toOwner)) return false; if (fromTopLevel == toOwner) { if (from instanceof RefClass) { PsiClass fromClass = ((RefClass)from).getUastElement().getJavaPsi(); final PsiElement target = to.getPsiElement(); if ((to instanceof RefClass || to instanceof RefField) && containsReferenceTo(fromClass.getModifierList(), target)) return false; if (to instanceof RefClass) { if (containsReferenceTo(fromClass.getExtendsList(), target)) return false; if (containsReferenceTo(fromClass.getImplementsList(), target)) return false; } } return true; } } return false; }