-
Notifications
You must be signed in to change notification settings - Fork 1
AnnotationProcessing_MutableAPI
Ladislav Gazo edited this page Aug 29, 2015
·
1 revision
Mutable API is used to:
- represent types that is going to be generated (so does not exists on the classpath yet)
- easier modification of the existing types
- manipulate with the objects instead of string representations while generating classes
- handle complex situations when more yet non-existing types should be interconnected
Although TypeMirrors and Elements are not mutable (no setter are available) you still can create types using methods from javax.lang.model.util.Types class:
-
WildcardType getWildcardType(TypeMirror extendsBound, TypeMirror superBound);allows you to create "custom" wildcard type like: ? extends Serializable -
DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs);allows you to use declared type with specified type variablest, like Map<? extends Serializable, String>
Problem is when you reach the world outside of the simple processors and want to handle more complex situations:
- create type variable with defined variable name, like
<T extends Serializable>- you simply can't represent variable 'T' using the standard API - use type variables with the declared types like
PagedResult<T extends List<User>>- you can't also use it in the types - work with classes that does not exists yet because they are going to be generated
Green types from from standard PAP types are mutable.

