mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
search for default annotation method (IDEA-70739)
This commit is contained in:
@@ -19,7 +19,7 @@ public class MethodUsagesSearcher extends QueryExecutorBase<PsiReference, Method
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
|
||||
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
|
||||
final PsiMethod method = p.getMethod();
|
||||
final SearchRequestCollector collector = p.getOptimizer();
|
||||
|
||||
@@ -37,6 +37,13 @@ public class MethodUsagesSearcher extends QueryExecutorBase<PsiReference, Method
|
||||
processConstructorReferences(consumer, method, searchScope, !strictSignatureSearch, strictSignatureSearch, collector);
|
||||
}
|
||||
|
||||
if (method instanceof PsiAnnotationMethod &&
|
||||
PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(method.getName()) &&
|
||||
method.getParameterList().getParametersCount() == 0) {
|
||||
ReferencesSearch.search(method.getContainingClass(), p.getScope()).forEach(PsiAnnotationMethodReferencesSearcher.createImplicitDefaultAnnotationMethodConsumer(
|
||||
consumer));
|
||||
}
|
||||
|
||||
boolean needStrictSignatureSearch = strictSignatureSearch && (aClass instanceof PsiAnonymousClass
|
||||
|| aClass.hasModifierProperty(PsiModifier.FINAL)
|
||||
|| method.hasModifierProperty(PsiModifier.STATIC)
|
||||
|
||||
+19
-15
@@ -18,24 +18,28 @@ public class PsiAnnotationMethodReferencesSearcher implements QueryExecutor<PsiR
|
||||
PsiMethod method = (PsiMethod)refElement;
|
||||
if (PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(method.getName()) && method.getParameterList().getParametersCount() == 0) {
|
||||
final Query<PsiReference> query = ReferencesSearch.search(method.getContainingClass(), p.getScope(), p.isIgnoreAccessScope());
|
||||
return query.forEach(new ReadActionProcessor<PsiReference>() {
|
||||
public boolean processInReadAction(final PsiReference reference) {
|
||||
if (reference instanceof PsiJavaCodeReferenceElement) {
|
||||
PsiJavaCodeReferenceElement javaReference = (PsiJavaCodeReferenceElement)reference;
|
||||
if (javaReference.getParent() instanceof PsiAnnotation) {
|
||||
PsiNameValuePair[] members = ((PsiAnnotation)javaReference.getParent()).getParameterList().getAttributes();
|
||||
if (members.length == 1 && members[0].getNameIdentifier() == null) {
|
||||
PsiReference t = members[0].getReference();
|
||||
if (t != null && !consumer.process(t)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return query.forEach(createImplicitDefaultAnnotationMethodConsumer(consumer));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ReadActionProcessor<PsiReference> createImplicitDefaultAnnotationMethodConsumer(final Processor<PsiReference> consumer) {
|
||||
return new ReadActionProcessor<PsiReference>() {
|
||||
public boolean processInReadAction(final PsiReference reference) {
|
||||
if (reference instanceof PsiJavaCodeReferenceElement) {
|
||||
PsiJavaCodeReferenceElement javaReference = (PsiJavaCodeReferenceElement)reference;
|
||||
if (javaReference.getParent() instanceof PsiAnnotation) {
|
||||
PsiNameValuePair[] members = ((PsiAnnotation)javaReference.getParent()).getParameterList().getAttributes();
|
||||
if (members.length == 1 && members[0].getNameIdentifier() == null) {
|
||||
PsiReference t = members[0].getReference();
|
||||
if (t != null && !consumer.process(t)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package pack1;
|
||||
|
||||
public @interface A {
|
||||
int intValue();
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package pack1;
|
||||
|
||||
class Usage {
|
||||
@A(intValue = 11)
|
||||
void foo() {
|
||||
}
|
||||
|
||||
@A(intValue = 42)
|
||||
void bar() {
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package pack1;
|
||||
|
||||
public @interface A {
|
||||
int value();
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package pack1;
|
||||
|
||||
class Usage {
|
||||
@A(11)
|
||||
void foo() {
|
||||
}
|
||||
|
||||
@A(value = 42)
|
||||
void bar() {
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,10 @@ public class RenameMethodMultiTest extends MultiFileTestCase {
|
||||
doTest("pack1.A", "void staticMethod(int i)", "renamedStaticMethod");
|
||||
}
|
||||
|
||||
public void testDefaultAnnotationMethod() throws Exception {
|
||||
doTest("pack1.A", "int value()", "intValue");
|
||||
}
|
||||
|
||||
public void testRename2OverrideFinal() throws Exception {
|
||||
try {
|
||||
doTest("p.B", "void method()", "finalMethod");
|
||||
|
||||
Reference in New Issue
Block a user