SSR: find annotated method references correctly

This commit is contained in:
Bas Leijdekkers
2014-12-27 20:25:55 +01:00
parent 13d2e73bd4
commit 21cf4b5407
2 changed files with 7 additions and 2 deletions
@@ -8,6 +8,7 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiShortNamesCache;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.structuralsearch.*;
import com.intellij.structuralsearch.impl.matcher.CompiledPattern;
import com.intellij.structuralsearch.impl.matcher.JavaCompiledPattern;
@@ -211,7 +212,7 @@ public class JavaCompilingVisitor extends JavaRecursiveElementWalkingVisitor {
}
currentReference = (PsiReferenceExpression)qualifier;
}
if (!hasNoNestedSubstitutionHandlers) {
if (!hasNoNestedSubstitutionHandlers && PsiTreeUtil.getChildOfType(reference, PsiAnnotation.class) == null) {
createAndSetSubstitutionHandlerFromReference(
reference,
resolve != null ? ((PsiClass)resolve).getQualifiedName() : reference.getText(),
@@ -2938,6 +2938,7 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
" Runnable r = System.out::println;" +
" Runnable s = this::hashCode;" +
" Runnable t = this::new;" +
" Runnable u = @AA A::new;" +
" static {" +
" System.out.println();" +
" }" +
@@ -2950,7 +2951,10 @@ public class StructuralSearchTest extends StructuralSearchTestCase {
assertEquals("should find method reference 2", 2, findMatchesCount(source, pattern2));
String pattern3 = "'_a::'_b";
assertEquals("should find all method references", 3, findMatchesCount(source, pattern3));
assertEquals("should find all method references", 4, findMatchesCount(source, pattern3));
String pattern4 = "@AA A::new";
assertEquals("should find annotated method references", 1, findMatchesCount(source, pattern4));
}
public void testNoUnexpectedException() {