-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotations with target TYPE_USE are missing from JavaField instances #1382
Comments
JSpecify is getting broad use in the wild and the lack of support for checking http://types.cs.washington.edu/jsr308/specification/java-annotation-design.pdf Is this considered for an upcoming release of ArchUnit? |
In this example, you would be annotating the field's type use, not the field itself. You cannot annotate the field itself because fields aren't declared as a valid target of the annotation. So ArchUnit's behavior is correct in this case. To see the annotation, you would have to query the field for its type, and then query the type for its annotations. Note that type use annotations (allowed by TYPE_USE) are different from annotations present at the class definition that is used in the field's type. A type annotation would be something like The underlying problem, however, is that ArchUnit has |
As a workaround one can use the |
@eskatos do you have an example perhaps? I tried the following, but it didn't yield any result:
|
I did not try on a field but for a method return type I used: JavaMethod method = ... arch unit;
method.reflect().getAnnotatedReturnType().getAnnotation(Foo.class); For fields I expect this to work: JavaClass clazz = ... arch unit;
clazz.reflect().getDeclaredField("myField").getAnnotatedType().getAnnotation(Foo.class); |
Ah, great, thanks, |
Hi,
While working on some ArchUnit checks (I find the tool really useful so far!), I found that annotations with a target of
@Target(TYPE_USE)
are ignored (for example with@Nullable
from Jspecify).To reproduce, I created my own annotation:
Inspecting an ArchUnit
JavaField
resulting from importing a class with a field annotated with this annotation, noJavaAnnotation
s are present.When adding or using
FIELD
as target, theJavaAnnotation
is present on theJavaField
instance.It would be great if these annotations were imported!
The text was updated successfully, but these errors were encountered: