PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!PsiUtil.isLanguageLevel11OrHigher(holder.getFile())) return PsiElementVisitor.EMPTY_VISITOR; return new JavaElementVisitor() { @Override public void visitForStatement(@NotNull PsiForStatement statement) { PsiMethodCallExpression call = findAppendCall(statement); if (call == null) return; PsiReferenceExpression qualifier = tryCast(PsiUtil.skipParenthesizedExprDown(call.getMethodExpression().getQualifierExpression()), PsiReferenceExpression.class); if (qualifier == null || !ExpressionUtil.isEffectivelyUnqualified(qualifier)) return; CountingLoop loop = CountingLoop.from(statement); if (loop == null) return; PsiLocalVariable var = loop.getCounter(); if (var.getType().equals(PsiTypes.longType()) || VariableAccessUtils.variableIsUsed(var, call)) return; PsiExpression arg = call.getArgumentList().getExpressions()[0]; if (SideEffectChecker.mayHaveSideEffects(arg)) return; holder.registerProblem(statement.getFirstChild(), JavaBundle.message( "inspection.message.can.be.replaced.with.string.repeat"), new StringRepeatCanBeUsedFix(ADD_MATH_MAX)); } }; }