supposing I have annotation on primitive type
@Parameter // first data value (0) is default
public /* NOT private */ int fInput;
is there a way to get the type of the element annotated with @Parameter using annotation processing tool?, in this case it is primitive type int. I can get the type if the type is not primitive using the following, but it cannot be applied to primitive type.
MoreTypes.asTypeElement(element.asType()).getQualifiedName().toString()
Thanks
when you call
element.asType()
, you get aTypeMirror
. There are multiple kinds of type-mirrors.TypeElement
may be obtained only forDeclaredType
, which represent an actual declared class somewhere in code.If a type is primitive, the actual interface that you get is
PrimitiveType
, which extendsTypeMirror
.To distinguish between all possible kinds of
TypeMirror
one may check it'sgetKind()
property (instanceof
is discouraged by the API spec). AndTypeKind
enum will tell you the actual type kind; All the primitive types are already included into the enum, e. g.TypeKind.INT
orTypeKind.BYTE
.So that's basically is a way to know whether a type is a primitive, and what kind of primitive.