mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: fix bad psi tree when replacing parameter
This commit is contained in:
@@ -284,6 +284,16 @@ public class JavaReplaceHandler extends StructuralReplaceHandler {
|
||||
}
|
||||
else if (statements.length == 1) {
|
||||
PsiElement replacement = getMatchExpr(statements[0], elementToReplace);
|
||||
if (elementToReplace instanceof PsiParameter && replacement instanceof PsiLocalVariable) {
|
||||
final PsiVariable variable = (PsiVariable)replacement;
|
||||
final PsiIdentifier identifier = variable.getNameIdentifier();
|
||||
assert identifier != null;
|
||||
final String text = variable.getText();
|
||||
|
||||
// chop off unneeded semicolons & initializers
|
||||
final String parameterText = text.substring(0, identifier.getStartOffsetInParent() + identifier.getTextLength());
|
||||
replacement = JavaPsiFacade.getElementFactory(variable.getProject()).createParameterFromText(parameterText, variable);
|
||||
}
|
||||
|
||||
copyUnmatchedElements(elementToReplace, replacement);
|
||||
replacement = handleSymbolReplacement(replacement, elementToReplace);
|
||||
|
||||
+11
@@ -2457,4 +2457,15 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase {
|
||||
" abstract void a(int i);\n" +
|
||||
"}", replacer.testReplace(in, what, by, options));
|
||||
}
|
||||
|
||||
public void testReplaceParameterWithComment() {
|
||||
final String in = "class A {\n" +
|
||||
" void a(int b) {}\n" +
|
||||
"}";
|
||||
final String what = "int '_a = '_b{0,1};";
|
||||
final String by = "final long /*!*/ $a$ = $b$;";
|
||||
assertEquals("class A {\n" +
|
||||
" void a(final long /*!*/ b) {}\n" +
|
||||
"}", replacer.testReplace(in, what, by, options));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user