void (@NotNull final PsiMember member) { if (!myVisibilityInspection.SUGGEST_FOR_CONSTANTS && isConstantField(member)) { return; } final PsiClass memberClass = member.getContainingClass(); PsiModifierList memberModifierList = member.getModifierList(); if (memberModifierList == null) return; int currentLevel = PsiUtil.getAccessLevel(memberModifierList); int suggestedLevel = suggestLevel(member, memberClass, currentLevel); if (memberClass != null) { synchronized (maxSuggestedLevelForChildMembers) { int prevMax = maxSuggestedLevelForChildMembers.getInt(memberClass); maxSuggestedLevelForChildMembers.put(memberClass, Math.max(prevMax, suggestedLevel)); } } if (LOG.isDebugEnabled()) { LOG.debug(member.getName() + ": effective level is '" + PsiUtil.getAccessModifier(suggestedLevel) + "'"); } if (suggestedLevel < currentLevel) { if (member instanceof PsiClass) { int memberMaxLevel; synchronized (maxSuggestedLevelForChildMembers) { memberMaxLevel = maxSuggestedLevelForChildMembers.getInt(member); } if (memberMaxLevel > suggestedLevel) { // a class can't have visibility less than its members return; } } PsiElement toHighlight = currentLevel == PsiUtil.ACCESS_LEVEL_PACKAGE_LOCAL ? ((PsiNameIdentifierOwner)member).getNameIdentifier() : ContainerUtil.find(memberModifierList.getChildren(), element -> element instanceof PsiKeyword && element.getText().equals(PsiUtil.getAccessModifier(currentLevel))); // can be null in some strange cases of malbuilt PSI, like in EA-95877 if (toHighlight != null) { String suggestedModifier = PsiUtil.getAccessModifier(suggestedLevel); String message = PsiModifier.PACKAGE_LOCAL.equals(suggestedModifier) ? JavaAnalysisBundle.message("access.can.be.package.private") : JavaAnalysisBundle.message("access.can.be.0", suggestedModifier); myHolder.registerProblem(toHighlight, message, new ChangeModifierFix(suggestedModifier)); } } }