mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
JavaTextBlockMigrationPropertyTest: fixed escape sequences parsing
1. expect '\040' sequence not to be replaced with space if it is escaped 2. handle text block content that ends with backslashes correctly GitOrigin-RevId: e2bdcdd21e1e043992d62626df725a85981f26d7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
67b3c48e4f
commit
8635d354aa
+5
-5
@@ -88,10 +88,14 @@ public class TextBlockBackwardMigrationInspection extends AbstractBaseJavaLocalI
|
||||
while (i < length) {
|
||||
int nSlashes = 0;
|
||||
int next = i;
|
||||
while ((next = PsiLiteralUtil.parseBackSlash(text, next)) != -1) {
|
||||
while (next < length && (next = PsiLiteralUtil.parseBackSlash(text, next)) != -1) {
|
||||
nSlashes++;
|
||||
i = next;
|
||||
}
|
||||
if (i >= length) {
|
||||
result.append(StringUtil.repeatSymbol('\\', nSlashes));
|
||||
break;
|
||||
}
|
||||
next = parseQuote(i, text, nSlashes, result);
|
||||
if (next != -1) {
|
||||
i = next;
|
||||
@@ -109,10 +113,6 @@ public class TextBlockBackwardMigrationInspection extends AbstractBaseJavaLocalI
|
||||
}
|
||||
|
||||
private static int parseEscapedChar(int i, @NotNull String text, int nSlashes, @NotNull StringBuilder result) {
|
||||
if (i > text.length()) {
|
||||
result.append(StringUtil.repeatSymbol('\\', nSlashes));
|
||||
return i;
|
||||
}
|
||||
int next = parseEscapedSpace(i, text, nSlashes, result);
|
||||
if (next != -1) return next;
|
||||
next = parseEscapedLineBreak(i, text, nSlashes, result);
|
||||
|
||||
+29
-1
@@ -100,7 +100,7 @@ public class JavaTextBlockMigrationPropertyTest extends LightJavaCodeInsightFixt
|
||||
if (injected != null && !injected.isEmpty()) continue;
|
||||
String expected = getConcatenationText(operands);
|
||||
if (expected == null || countNewLines(expected) < 2) continue;
|
||||
expected = expected.replaceAll("\\\\040", " ");
|
||||
expected = replaceUnescapedSpaces(expected);
|
||||
|
||||
Computable<PsiElement> replaceAction = () -> {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
@@ -122,6 +122,34 @@ public class JavaTextBlockMigrationPropertyTest extends LightJavaCodeInsightFixt
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String replaceUnescapedSpaces(@NotNull String text) {
|
||||
if (!text.contains("040")) return text;
|
||||
StringBuilder result = new StringBuilder();
|
||||
int i = 0;
|
||||
int length = text.length();
|
||||
while (i < length) {
|
||||
int nSlashes = 0;
|
||||
int next;
|
||||
while (i < length && (next = PsiLiteralUtil.parseBackSlash(text, i)) != -1) {
|
||||
nSlashes++;
|
||||
i = next;
|
||||
}
|
||||
if (i >= length) {
|
||||
result.append(StringUtil.repeatSymbol('\\', nSlashes));
|
||||
break;
|
||||
}
|
||||
if (nSlashes % 2 != 0 && StringUtil.startsWith(text, i, "040")) {
|
||||
result.append(StringUtil.repeatSymbol('\\', nSlashes - 1)).append(" ");
|
||||
i += 3;
|
||||
continue;
|
||||
}
|
||||
result.append(StringUtil.repeatSymbol('\\', nSlashes)).append(text.charAt(i));
|
||||
i++;
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getConcatenationText(PsiExpression @NotNull [] operands) {
|
||||
String[] lines = new String[operands.length];
|
||||
|
||||
Reference in New Issue
Block a user