void (final RefElement refElement, @NotNull StringBuilder buf) { refElement.accept(new RefJavaVisitor() { @Override public void visitField(@NotNull RefField field) { if (field.isUsedForReading() && !field.isUsedForWriting()) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis")); return; } if (!field.isUsedForReading() && field.isUsedForWriting()) { if (field.isOnlyAssignedInInitializer()) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis1")); return; } buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis2")); return; } int nUsages = field.getInReferences().size(); if (nUsages == 0) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis1")); } else if (nUsages == 1) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis3")); } else { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis4", nUsages)); } } @Override public void visitClass(@NotNull RefClass refClass) { if (refClass.isAnonymous()) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis10")); } else if (refClass.isInterface() || refClass.isAbstract()) { String classOrInterface = HTMLJavaHTMLComposer.getClassOrInterface(refClass, true); buf.append("&nbsp;"); int nDerived = getImplementationsCount(refClass); if (nDerived == 0) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis23", classOrInterface)); } else if (nDerived == 1) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis24", classOrInterface)); } else { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis25", classOrInterface, nDerived)); } } else if (refClass.isUtilityClass()) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis11")); } else { int nInstantiationsCount = getInstantiationsCount(refClass); if (nInstantiationsCount == 0) { int nImplementations = getImplementationsCount(refClass); if (nImplementations != 0) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis19", nImplementations)); } else { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis13")); } } else if (nInstantiationsCount == 1) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis12")); } else { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis20", nInstantiationsCount)); } } } @Override public void visitMethod(@NotNull RefMethod method) { RefClass refClass = method.getOwnerClass(); if (method.isExternalOverride()) { String classOrInterface = HTMLJavaHTMLComposer.getClassOrInterface(Objects.requireNonNull(refClass), false); buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis22", classOrInterface)); } else if (method.isStatic() || method.isConstructor()) { int nRefs = method.getInReferences().size(); if (method.isConstructor()) { if (nRefs == 0) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis26.constructor")); } else if (method.isConstructor() && ((RefMethodImpl)method).isSuspiciousRecursive()) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis27.constructor")); } else if (nRefs == 1) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis28.constructor")); } else { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis29.constructor", nRefs) ); } } else { if (nRefs == 0) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis26.method")); } else if (method.isConstructor() && ((RefMethodImpl)method).isSuspiciousRecursive()) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis27.method")); } else if (nRefs == 1) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis28.method")); } else { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis29.method", nRefs) ); } } } else if (refClass instanceof RefClassImpl && ((RefClassImpl)refClass).isSuspicious()) { if (method.isAbstract() && !refClass.isInterface()) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis14")); } else { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis15")); } } else { int nOwnRefs = method.getInReferences().size(); int nSuperRefs = getSuperRefsCount(method); int nDerivedRefs = getDerivedRefsCount(method); if (nOwnRefs == 0 && nSuperRefs == 0 && nDerivedRefs == 0) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis16")); } else if (nDerivedRefs > 0 && nSuperRefs == 0 && nOwnRefs == 0) { String classOrInterface = refClass == null ? "" : HTMLJavaHTMLComposer.getClassOrInterface(refClass, false); buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis21", classOrInterface)); } else if (((RefMethodImpl)method).isSuspiciousRecursive()) { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis17")); } else { buf.append(AnalysisBundle.message("inspection.dead.code.problem.synopsis18")); } } } }); }