From 0c4fc2ab23ccd5e6e05c3c27f281bf242d1122d2 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 29 Aug 2024 18:29:59 +0200 Subject: [PATCH] Java: don't suggest to "Replace with text block" a text block (IDEA-358449) GitOrigin-RevId: 4db08b1a6a9e5bb3c957e23af185e6df1f757c47 --- .../codeInspection/TextBlockMigrationInspection.java | 2 +- .../textBlockMigration/beforeTextBlockLiteral.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/inspection/textBlockMigration/beforeTextBlockLiteral.java diff --git a/java/java-impl-inspections/src/com/intellij/codeInspection/TextBlockMigrationInspection.java b/java/java-impl-inspections/src/com/intellij/codeInspection/TextBlockMigrationInspection.java index 88ed0c6ccfa9..e103a5b14aec 100644 --- a/java/java-impl-inspections/src/com/intellij/codeInspection/TextBlockMigrationInspection.java +++ b/java/java-impl-inspections/src/com/intellij/codeInspection/TextBlockMigrationInspection.java @@ -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) { diff --git a/java/java-tests/testData/inspection/textBlockMigration/beforeTextBlockLiteral.java b/java/java-tests/testData/inspection/textBlockMigration/beforeTextBlockLiteral.java new file mode 100644 index 000000000000..f2e3f40699bf --- /dev/null +++ b/java/java-tests/testData/inspection/textBlockMigration/beforeTextBlockLiteral.java @@ -0,0 +1,11 @@ +// "Fix all 'Text block can be used' problems in file" "false" + +class NonStringLiteral { + + void empty() { + String textBlock = """ + what? + """; + } + +} \ No newline at end of file