Java: don't suggest to "Replace with text block" a text block (IDEA-358449)

GitOrigin-RevId: 4db08b1a6a9e5bb3c957e23af185e6df1f757c47
This commit is contained in:
Bas Leijdekkers
2024-09-02 21:52:50 +00:00
committed by intellij-monorepo-bot
parent 3c7271ac4e
commit 0c4fc2ab23
2 changed files with 12 additions and 1 deletions
@@ -85,7 +85,7 @@ public final class TextBlockMigrationInspection extends AbstractBaseJavaLocalIns
@Override
public void visitLiteralExpression(@NotNull PsiLiteralExpression expression) {
if (PsiUtil.skipParenthesizedExprUp(expression.getParent()) instanceof PsiPolyadicExpression) return;
if (!ExpressionUtils.hasStringType(expression)) return;
if (!ExpressionUtils.hasStringType(expression) || expression.isTextBlock()) return;
String text = expression.getText();
int newLineIdx = getNewLineIndex(text, 0);
if (mySuggestLiteralReplacement && newLineIdx != -1 && getNewLineIndex(text, newLineIdx + 1) != -1) {
@@ -0,0 +1,11 @@
// "Fix all 'Text block can be used' problems in file" "false"
class NonStringLiteral {
void empty() {
String textBlock = """<caret>
what?
""";
}
}