String (@NotNull RefJavaElement refElement, int minLevel) { @PsiModifier.ModifierConstant String curAccess = refElement.getAccessModifier(); String weakestAccess = PsiUtil.getAccessModifier(minLevel); if (isTopLevelClass(refElement) || isCalledOnSubClasses(refElement)) { weakestAccess = PsiModifier.PACKAGE_LOCAL; } if (isAbstractMethod(refElement)) { weakestAccess = PsiModifier.PROTECTED; } if (refElement instanceof RefMethod refMethod && refMethod.isConstructor()) { final RefClass ownerClass = refMethod.getOwnerClass(); if (ownerClass != null && ownerClass.isRecord()) { weakestAccess = ownerClass.getAccessModifier(); } } if (curAccess.equals(weakestAccess)) return curAccess; while (true) { String weakerAccess = getWeakerAccess(curAccess, refElement); if (weakerAccess == null || RefJavaUtil.getInstance().compareAccess(weakerAccess, weakestAccess) < 0) break; if (isAccessible(refElement, weakerAccess)) { curAccess = weakerAccess; } else { break; } } return curAccess; }