java: track java usages of annotation methods in Unused Declaration inspection (IDEA-256632)

psi hack because UAST lacks annotation property references

GitOrigin-RevId: 9d5f2fd8e9d55584be60ca529512dd0714fb551d
This commit is contained in:
Bas Leijdekkers
2024-04-25 13:49:49 +00:00
committed by intellij-monorepo-bot
parent 45cb0ab7d0
commit 57b1788fa5
3 changed files with 31 additions and 1 deletions
@@ -51,6 +51,23 @@ public final class RefJavaUtilImpl extends RefJavaUtil {
return false;
}
@Override
public boolean visitNamedExpression(@NotNull UNamedExpression node) {
PsiElement source = node.getSourcePsi();
if (source instanceof PsiNameValuePair pair) {
PsiReference reference = pair.getReference();
if (reference != null) {
PsiElement target = reference.resolve();
final RefElement refElement = refManager.getReference(target);
if (refElement != null) {
refElement.initializeIfNeeded();
refFrom.addReference(refElement, target, decl, false, true, node);
}
}
}
return false;
}
@Override
public boolean visitAnnotation(@NotNull UAnnotation node) {
PsiClass javaClass = node.resolve();
@@ -25,5 +25,10 @@
<line>25</line>
<description>Interface is not implemented.</description>
</problem>
<problem>
<file>RepeatableAnnotation.java</file>
<line>41</line>
<description>Method is never used.</description>
</problem>
</problems>
@@ -36,5 +36,13 @@ class Annotated1 {
public static void main(String[] args) {
}
}
@interface TestAnn {
String str();
int digit() default 2;
}
class Test {
@TestAnn(str = "test")
public static void main(String[] args) {
}
}