You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In reality ECJ does not appear to recognize type annotations as anything, but opaque source code tokens, and so does Javac.
Current situation
There is a way to make introspection on type annotations "work" in Javac:
Postpone your compilation until type analysis completes using Oracle-proprietary JavacTask API
Obtain the annotated type using Oracle proprietary Trees.getTypeMirror API.
Unfortunately, as of Javac 1.8.0_112 doing this requires significant effort (manually walking trees using tree API) and does not really work for any types, only for simple, non-composite types. The following TreePath will have no annotations:
List<@NonNull ? extends CustomParcelable>
You will have to cast it to parametrized tree and walk down to
@NonNull ? extends CustomParcelable
For which Trees.getTypeMirror will finally produce correctly annotated WildcardType.
The alternative is to use non-documented Javac classes, which will likely become unavailable in Java 9. And that still does not guarantee correct outcome.
Oncoming improvements
Javac have had a major injection of code to actually support type annotations. That code isn't included in Java 8 and will be available in Java 9 only.
The text was updated successfully, but these errors were encountered:
In ideal world the following snippet would both compile and be inspectable from annotation processors:
In reality ECJ does not appear to recognize type annotations as anything, but opaque source code tokens, and so does Javac.
Current situation
There is a way to make introspection on type annotations "work" in Javac:
JavacTask
APITrees.getTypeMirror
API.Unfortunately, as of Javac 1.8.0_112 doing this requires significant effort (manually walking trees using tree API) and does not really work for any types, only for simple, non-composite types. The following TreePath will have no annotations:
You will have to cast it to parametrized tree and walk down to
For which
Trees.getTypeMirror
will finally produce correctly annotated WildcardType.The alternative is to use non-documented Javac classes, which will likely become unavailable in Java 9. And that still does not guarantee correct outcome.
Oncoming improvements
Javac have had a major injection of code to actually support type annotations. That code isn't included in Java 8 and will be available in Java 9 only.
The text was updated successfully, but these errors were encountered: