PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitField(@NotNull PsiField field) { checkSubClassReferences(field); } @Override public void visitClassInitializer(@NotNull PsiClassInitializer initializer) { checkSubClassReferences(initializer); } private void checkSubClassReferences(PsiMember scope) { if (!scope.hasModifierProperty(PsiModifier.STATIC)) return; PsiClass containingClass = scope.getContainingClass(); Pair<PsiElement, PsiClass> pair = findSubClassReference(scope, containingClass); if (pair != null) { holder.registerProblem(pair.first, InspectionGadgetsBundle .message("referencing.subclass.0.from.superclass.1.initializer.might.lead.to.class.loading.deadlock", pair.second.getName(), containingClass.getName())); } } }; }