Java: replace with text block should not be available on non-string literals (IDEA-354921)

GitOrigin-RevId: b86751e38c0349fcafd72ed04b39ed5283c2c06a
This commit is contained in:
Bas Leijdekkers
2024-06-14 09:27:18 +02:00
committed by intellij-monorepo-bot
parent 2415769d5c
commit dd0e596d3d
2 changed files with 11 additions and 7 deletions

View File

@@ -85,9 +85,8 @@ public final class TextBlockMigrationInspection extends AbstractBaseJavaLocalIns
@Override
public void visitLiteralExpression(@NotNull PsiLiteralExpression expression) {
if (PsiUtil.skipParenthesizedExprUp(expression.getParent()) instanceof PsiPolyadicExpression) return;
PsiLiteralExpression literal = getLiteralExpression(expression);
if (literal == null) return;
String text = literal.getText();
if (!ExpressionUtils.hasStringType(expression)) return;
String text = expression.getText();
int newLineIdx = getNewLineIndex(text, 0);
if (mySuggestLiteralReplacement && newLineIdx != -1 && getNewLineIndex(text, newLineIdx + 1) != -1) {
boolean quickFixOnly = isOnTheFly && InspectionProjectProfileManager.isInformationLevel(getShortName(), expression);
@@ -189,10 +188,6 @@ public final class TextBlockMigrationInspection extends AbstractBaseJavaLocalIns
return getEscapedCharIndex(text, start, 'n');
}
private static int getQuoteIndex(@NotNull String text) {
return getEscapedCharIndex(text, 0, '"');
}
private static int getEscapedCharIndex(@NotNull String text, int start, char escapedChar) {
int i = start;
while (i < text.length()) {

View File

@@ -0,0 +1,9 @@
// "Replace with text block" "false"
class NonStringLiteral {
void empty() {
String empty = <caret>null;
}
}