SSR: match multiple fields declared in single declaration correctly in incomplete code (IDEA-CR-4531)

This commit is contained in:
Bas Leijdekkers
2015-09-29 12:03:07 +02:00
parent ff6559e242
commit f5c8a63044
2 changed files with 10 additions and 1 deletions
@@ -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 ||
@@ -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};"));
}
}