void (@NotNull PsiMethod method) { final PsiClass aClass = method.getContainingClass(); if (aClass == null) { return; } if (method.getNameIdentifier() == null) { return; } if (JavaHighlightUtil.isSerializationRelatedMethod(method, aClass)) { return; } PsiClass ancestorClass = aClass.getSuperClass(); final Set<PsiClass> visitedClasses = new HashSet<>(); while (ancestorClass != null) { if (!visitedClasses.add(ancestorClass)) { break; } final PsiSubstitutor classSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(ancestorClass, aClass, PsiSubstitutor.EMPTY); final PsiMethod overridingMethod = MethodSignatureUtil.findMethodInSuperClassBySignatureInDerived(aClass, ancestorClass, method.getSignature(classSubstitutor), false); if (overridingMethod != null) { if (overridingMethod.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) { final PsiJavaFile file = PsiTreeUtil.getParentOfType(aClass, PsiJavaFile.class); if (file == null) { break; } final PsiJavaFile ancestorFile = PsiTreeUtil.getParentOfType(ancestorClass, PsiJavaFile.class); if (ancestorFile == null) { break; } final String packageName = file.getPackageName(); final String ancestorPackageName = ancestorFile.getPackageName(); if (!packageName.equals(ancestorPackageName)) { registerMethodError(method, PsiModifier.PACKAGE_LOCAL); break; } } else if (overridingMethod.hasModifierProperty(PsiModifier.PRIVATE)) { registerMethodError(method, PsiModifier.PRIVATE); break; } } ancestorClass = ancestorClass.getSuperClass(); } }