mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: fix replacing array initializer removes semicolon (IDEA-192548)
This commit is contained in:
+9
-9
@@ -803,17 +803,17 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile {
|
||||
private static int removeExtraSemicolon(ParameterInfo info, int offset, StringBuilder result, MatchResult match) {
|
||||
if (info.isStatementContext()) {
|
||||
final int index = offset + info.getStartIndex();
|
||||
if (result.charAt(index)==';' &&
|
||||
( match == null ||
|
||||
final PsiElement matchElement = (match == null) ? null : match.getMatch();
|
||||
if (result.charAt(index) == ';' &&
|
||||
( matchElement == null ||
|
||||
( result.charAt(index-1)=='}' &&
|
||||
!(match.getMatch() instanceof PsiDeclarationStatement) && // array init in dcl
|
||||
!(match.getMatch() instanceof PsiNewExpression) // array initializer
|
||||
!(matchElement instanceof PsiDeclarationStatement) && // array init in dcl
|
||||
!(matchElement instanceof PsiNewExpression) && // array initializer
|
||||
!(matchElement instanceof PsiArrayInitializerExpression)
|
||||
) ||
|
||||
( !match.isMultipleMatch() && // ; in comment
|
||||
match.getMatch() instanceof PsiComment
|
||||
) ||
|
||||
( match.isMultipleMatch() && // ; in comment
|
||||
match.getChildren().get( match.getChildren().size() - 1 ).getMatch() instanceof PsiComment
|
||||
( match.isMultipleMatch() // ; in comment
|
||||
? match.getChildren().get(match.getChildren().size() - 1).getMatch() instanceof PsiComment
|
||||
: matchElement instanceof PsiComment
|
||||
)
|
||||
)
|
||||
) {
|
||||
|
||||
+9
@@ -2460,5 +2460,14 @@ public class StructuralReplaceTest extends StructuralReplaceTestCase {
|
||||
"}",
|
||||
replace(in, "'_ReturnType '_Method('_ParameterType '_Parameter*);",
|
||||
"$ReturnType$ $Method$ ($ParameterType$ $Parameter$);", true));
|
||||
|
||||
String in2 = "class X {" +
|
||||
" public final X[] EMPTY_ARRAY = {};" +
|
||||
"}";
|
||||
assertEquals("shouldn't delete semicolon",
|
||||
"class X {" +
|
||||
" public final X[] EMPTY_ARRAY = {};" +
|
||||
"}",
|
||||
replace(in2, "'_FieldType 'Field = '_Init?;", "$FieldType$ $Field$ = $Init$;", true));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user