mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SSR: match multiple fields declared in single declaration correctly in incomplete code (IDEA-CR-4531)
This commit is contained in:
+3
-1
@@ -22,6 +22,7 @@ import java.util.List;
|
||||
public class DeclarationStatementHandler extends MatchingHandler {
|
||||
private MatchingHandler myCommentHandler;
|
||||
|
||||
@Override
|
||||
public boolean match(PsiElement patternNode, PsiElement matchedNode, MatchContext context) {
|
||||
if (patternNode instanceof PsiComment) {
|
||||
return myCommentHandler.match(patternNode, matchedNode, context);
|
||||
@@ -59,7 +60,7 @@ public class DeclarationStatementHandler extends MatchingHandler {
|
||||
node = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class);
|
||||
while (PsiUtil.isJavaToken(node, JavaTokenType.COMMA)) {
|
||||
node = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class);
|
||||
if (node != null) {
|
||||
if (node instanceof PsiField) {
|
||||
matchNodes.add(node);
|
||||
}
|
||||
node = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class);
|
||||
@@ -89,6 +90,7 @@ public class DeclarationStatementHandler extends MatchingHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldAdvanceTheMatchFor(PsiElement patternElement, PsiElement matchedElement) {
|
||||
if (patternElement instanceof PsiComment &&
|
||||
( matchedElement instanceof PsiField ||
|
||||
|
||||
+7
@@ -3291,5 +3291,12 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
|
||||
assertEquals("find declarations with only one field", 1, findMatchesCount(source, "int '_a;"));
|
||||
assertEquals("find all declarations", 4, findMatchesCount(source, "int '_a+;"));
|
||||
assertEquals("find all fields", 9, findMatchesCount(source, "int 'a+;"));
|
||||
|
||||
String source2 = "class ABC {" +
|
||||
" String u;" +
|
||||
" String s,t," +
|
||||
" void m() {}" +
|
||||
"}";
|
||||
assertEquals("find incomplete code", 1, findMatchesCount(source2, "'_a '_b{2,100};"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user