-
Notifications
You must be signed in to change notification settings - Fork 120
Description
I am trying to create a plugin which adds JSpecify annotations like org.jspecify.annotations.NonNull
and @link org.jspecify.annotations.Nullable
.
These annotations are more precise than the JSR 305 annotations about where they may be placed.
The vanilla code generated by JAXB 4.0.5 in my ObjectFactory looks like:
public Catalog.TestSet createCatalogTestSet() {
return new Catalog.TestSet();
}
Previously, with JSR 305 you could write:
@javax.annotation.Nonnull
public Catalog.TestSet createCatalogTestSet() {
return new Catalog.TestSet();
}
I could generate that just fine in my JAXB plugin by calling: method.annotate(javax.annotation.Nonnull.class)
where method
is an instance of com.sun.codemodel.JMethod
.
However, with JSpecify you need to write:
public Catalog.@org.jspecify.annotations.NonNull TestSet createCatalogTestSet() {
return new Catalog.TestSet();
}
Calling method.annotate(org.jspecify.annotations.NonNull.class)
from my plugin generates the incorrect code:
@org.jspecify.annotations.NonNull
public Catalog.TestSet createCatalogTestSet() {
return new Catalog.TestSet();
}
Instead of method.annotate(org.jspecify.annotations.NonNull.class)
, I tried calling the following in my plugin:
final JType returnType = method.type();
((JDefinedClass) returnType).annotate(org.jspecify.annotations.NonNull.class)
but when I do, I get no annotation at all in the generated code. I can't figure out how to call the appropriate codemodel method to get the annotation into the correct place. How can I do that please?