mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 13:20:53 +07:00
SSR: keep formatting when complete modifier list is reused in replacement
GitOrigin-RevId: 27cc6d2e2054d8b5914fff4f90e987128ec40a37
This commit is contained in:
committed by
intellij-monorepo-bot
parent
63099cb981
commit
83a67cdaa9
@@ -353,6 +353,10 @@ public class JavaReplaceHandler extends StructuralReplaceHandler {
|
||||
if (originalModifierList == null || queryModifierList == null || replacementModifierList == null) {
|
||||
return;
|
||||
}
|
||||
if (queryModifierList.getTextLength() == 0 && replacementModifierList.getTextLength() == 0) {
|
||||
replacementModifierList.replace(originalModifierList);
|
||||
return;
|
||||
}
|
||||
final List<? extends PsiElement> unmatchedAnnotations = originalModifierList.getUserData(GlobalMatchingVisitor.UNMATCHED_ELEMENTS_KEY);
|
||||
final PsiElement anchor = replacementModifierList.getFirstChild();
|
||||
boolean append = (anchor == null);
|
||||
|
||||
@@ -2767,4 +2767,17 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase {
|
||||
"}",
|
||||
replace(in, "'_Instance?.'_MethodCall('_arguments*)", "$Instance$.$MethodCall$($arguments$)", true));
|
||||
}
|
||||
|
||||
public void testKeepModifierFormatting() {
|
||||
String in = "@Deprecated\n" +
|
||||
"public class X {}";
|
||||
final String what = "class '_X {}";
|
||||
final String replacement = "/** comment */\n" +
|
||||
"class $X$ {}";
|
||||
final String expected = "/** comment */\n" +
|
||||
"@Deprecated\n" +
|
||||
"public class X {}";
|
||||
assertEquals("keep newline in modifier list",
|
||||
expected, replace(in, what, replacement, true));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user