PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!PsiUtil.getLanguageLevel(holder.getFile()).isAtLeast(LanguageLevel.JDK_1_4)) { return PsiElementVisitor.EMPTY_VISITOR; } return new JavaElementVisitor() { @Override public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) { CompareInfo info = fromCall(call); PsiElement nameElement = call.getMethodExpression().getReferenceNameElement(); if (info != null && nameElement != null) { register(info, nameElement); } } @Override public void visitIfStatement(@NotNull PsiIfStatement statement) { CompareInfo info = fromIf(statement); PsiElement keyword = statement.getFirstChild(); if (info != null && keyword != null) { register(info, keyword); } } @Override public void visitConditionalExpression(@NotNull PsiConditionalExpression expression) { CompareInfo info = fromTernary(expression); if (info != null) { register(info, expression); } } private void register(CompareInfo info, PsiElement nameElement) { if (!suggestFloatingCompare && info.myMayChangeSemantics) return; LocalQuickFix turnOffFloating = info.myMayChangeSemantics ? LocalQuickFix.from(new UpdateInspectionOptionFix( UseCompareMethodInspection.this, "suggestFloatingCompare", JavaAnalysisBundle.message("inspection.use.compare.method.turn.off.double"), false)) : null; holder.registerProblem(nameElement, JavaAnalysisBundle.message("inspection.expression.can.be.replaced.with.message", info.myClass.getClassName() + ".compare"), LocalQuickFix.notNullElements(new ReplaceWithPrimitiveCompareFix(info.getReplacementText()), turnOffFloating)); } }; }