mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
SSR: don't loose comma when replacing array elements (IDEA-319000)
GitOrigin-RevId: 47e3fd4fdadaab66075c37732891af09e3167974
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d2bdcf661d
commit
d54705b1f1
@@ -453,7 +453,11 @@ public class JavaReplaceHandler extends StructuralReplaceHandler {
|
||||
return;
|
||||
}
|
||||
if (listContext) {
|
||||
if (replacements.length > 1) {
|
||||
if (replacements.length == 1 && replacements[0] instanceof PsiExpressionListStatement statement) {
|
||||
PsiElement[] children = statement.getExpressionList().getChildren();
|
||||
elementParent.addRangeBefore(children[0], children[children.length - 1], elementToReplace);
|
||||
}
|
||||
else if (replacements.length > 1) {
|
||||
final PsiElement replacement = elementParent.addRangeBefore(replacements[0], replacements[replacements.length - 1], elementToReplace);
|
||||
copyUnmatchedElements(elementToReplace, replacement, info);
|
||||
}
|
||||
|
||||
@@ -736,7 +736,10 @@ public final class JavaStructuralSearchProfile extends StructuralSearchProfile {
|
||||
addSeparatorTextMatchedInAnyOrder(currentElement,
|
||||
parent instanceof PsiClass ? PsiMember.class : PsiJavaCodeReferenceElement.class, buf);
|
||||
}
|
||||
else if (info.isStatementContext() || info.isArgumentContext() || parent instanceof PsiPolyadicExpression) {
|
||||
else if (info.isStatementContext() ||
|
||||
info.isArgumentContext() ||
|
||||
parent instanceof PsiPolyadicExpression ||
|
||||
parent instanceof PsiArrayInitializerExpression) {
|
||||
addSeparatorText(previous, currentElement, buf);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -3082,6 +3082,38 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase {
|
||||
" public final X[] EMPTY_ARRAY = {};" +
|
||||
"}",
|
||||
replace(in2, "'_FieldType 'Field = '_Init?;", "$FieldType$ $Field$ = $Init$;", true));
|
||||
|
||||
String in3 = """
|
||||
class X {
|
||||
void x(int... ss) {}
|
||||
|
||||
void y() {
|
||||
x(new int[] {1, 2});\s
|
||||
}
|
||||
}
|
||||
""";
|
||||
assertEquals("Should keep commas",
|
||||
"""
|
||||
class X {
|
||||
void x(int... ss) {}
|
||||
|
||||
void y() {
|
||||
x(1, 2);\s
|
||||
}
|
||||
}
|
||||
""",
|
||||
replace(in3, "new int[] {'_a*}", "$a$", true));
|
||||
assertEquals("Should keep commas 2",
|
||||
"""
|
||||
class X {
|
||||
void x(int... ss) {}
|
||||
|
||||
void y() {
|
||||
x(new long[] {1, 2});\s
|
||||
}
|
||||
}
|
||||
""",
|
||||
replace(in3, "new int[] {'_a*}", "new long[] {$a$}"));
|
||||
}
|
||||
|
||||
public void testMethodCall() {
|
||||
|
||||
Reference in New Issue
Block a user