PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!HighlightingFeature.TEXT_BLOCKS.isAvailable(holder.getFile())) return PsiElementVisitor.EMPTY_VISITOR; return new JavaElementVisitor() { @Override public void visitPolyadicExpression(@NotNull PsiPolyadicExpression expression) { if (!ExpressionUtils.hasStringType(expression)) return; int nNewLines = 0; TextRange firstNewLineTextRange = null; for (PsiExpression operand : expression.getOperands()) { PsiLiteralExpression literal = getLiteralExpression(operand); if (literal == null) return; if (nNewLines > 1) continue; String text = literal.getText(); int newLineIdx = getNewLineIndex(text, 0); if (newLineIdx == -1) continue; if (firstNewLineTextRange == null) { int operandOffset = literal.getTextOffset() - expression.getTextOffset(); firstNewLineTextRange = new TextRange(operandOffset + newLineIdx, operandOffset + newLineIdx + 2); } while (nNewLines <= 1 && newLineIdx != -1) { nNewLines++; newLineIdx = getNewLineIndex(text, newLineIdx + 1); } } boolean hasComments = ContainerUtil.exists(expression.getChildren(), child -> child instanceof PsiComment); boolean reportWarning = nNewLines > 1 && !hasComments; if (reportWarning) { boolean quickFixOnly = isOnTheFly && InspectionProjectProfileManager.isInformationLevel(getShortName(), expression); holder.registerProblem(expression, quickFixOnly ? null : firstNewLineTextRange, JavaBundle.message("inspection.text.block.migration.concatenation.message"), new ReplaceWithTextBlockFix()); } else if (isOnTheFly) { holder.registerProblem(expression, JavaBundle.message("inspection.text.block.migration.string.message"), ProblemHighlightType.INFORMATION, new ReplaceWithTextBlockFix()); } } @Override public void visitLiteralExpression(@NotNull PsiLiteralExpression expression) { if (PsiUtil.skipParenthesizedExprUp(expression.getParent()) instanceof PsiPolyadicExpression) return; boolean quickFixOnly = isOnTheFly && InspectionProjectProfileManager.isInformationLevel(getShortName(), expression); if (!mySuggestLiteralReplacement && !quickFixOnly) return; PsiLiteralExpression literal = getLiteralExpression(expression); if (literal == null) return; String text = literal.getText(); int newLineIdx = getNewLineIndex(text, 0); if (newLineIdx != -1 && getNewLineIndex(text, newLineIdx + 1) != -1) { holder.registerProblem(expression, quickFixOnly ? null : new TextRange(newLineIdx, newLineIdx + 2), JavaBundle.message("inspection.text.block.migration.string.message"), new ReplaceWithTextBlockFix()); } else if (isOnTheFly && getQuoteIndex(text) != -1) { holder.registerProblem(expression, JavaBundle.message("inspection.text.block.migration.string.message"), ProblemHighlightType.INFORMATION, new ReplaceWithTextBlockFix()); } } }; }