Using error-types in annotation processors
Victor Nazarov
asviraspossible at gmail.com
Fri Nov 27 13:36:35 UTC 2015
Hello,
I hope that this is an appropriate place to write my question.
To add some context, I'm a developer of [adt4j](
https://github.com/sviperll/adt4j) project.
Java compiler pass every reference to unknown classes as an "error" type.
But it can be useful to inspect such error-types in annotation processor to
actually generate missing classes. This somewhat works in latest JDK8, but
not in the special case interesting for adt4j project.
The way to inspect error type is to use methods provided by
ErrorType-class. There are only two interesting ways to inspect error type:
errorType.asElement().getSimpleName() --- to get the name of missing class
errorType.getTypeArguments() --- to get type-arguments applied to
type-to-be.
The problem is that sometimes these methods provide no useful information.
In such situation getSimpleName method returns useless "<any>" string and
no feather processing is possible.
Suppose that we want to generate class MyClassToGenerate and it is
currently missing. Below are some code snippets. With Example1, Example2
and Example3 error-type processing works as expected. Example4 doesn't work
as expected and always returns "<any>" string. This looks inconsistent and
I'd be glad if it can be fixed in future versions of Java...
Example1
--------------
class MyClass extends MyClassToGenerate {
}
Example2
--------------
class MyClass extends MyClassToGenerate<T> {
}
Example3
--------------
class MyClass {
void method1(MyClassToGenerate argument) {
}
}
Example4
--------------
class MyClass {
void method1(MyClassToGenerate<T> argument) {
}
}
--
Victor Nazarov
More information about the anno-pipeline-dev
mailing list