Skip to content
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

Proper support for type annotations #2

Open
Alexander-- opened this issue Nov 7, 2016 · 0 comments
Open

Proper support for type annotations #2

Alexander-- opened this issue Nov 7, 2016 · 0 comments
Labels

Comments

@Alexander--
Copy link
Contributor

Alexander-- commented Nov 7, 2016

In ideal world the following snippet would both compile and be inspectable from annotation processors:

void methodWithListParameter(List<@NonNull ? extends CustomParcelable>);

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:

  1. Postpone your compilation until type analysis completes using Oracle-proprietary JavacTask API
  2. 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.

@Alexander-- Alexander-- added the bug label Nov 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant