public class Factory
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.Byte |
DUMMY_BYTE |
static java.lang.Character |
DUMMY_CHAR |
static java.lang.Double |
DUMMY_DOUBLE |
static java.lang.Float |
DUMMY_FLOAT |
static java.lang.Integer |
DUMMY_INTEGER |
static java.lang.Long |
DUMMY_LONG |
static java.lang.Short |
DUMMY_SHORT |
static java.util.List<? extends javax.lang.model.element.AnnotationMirror> |
EMPTY_ANNOTATION_MIRRORS |
| Constructor and Description |
|---|
Factory(BaseProcessingEnvImpl env)
This object should only be constructed by the BaseProcessingEnvImpl.
|
| Modifier and Type | Method and Description |
|---|---|
<A extends java.lang.annotation.Annotation> |
getAnnotation(AnnotationBinding[] annoInstances,
java.lang.Class<A> annotationClass) |
java.util.List<? extends javax.lang.model.element.AnnotationMirror> |
getAnnotationMirrors(AnnotationBinding[] annotations)
Convert an array of compiler annotation bindings into a list of AnnotationMirror
|
<A extends java.lang.annotation.Annotation> |
getAnnotationsByType(AnnotationBinding[] annoInstances,
java.lang.Class<A> annotationClass) |
javax.lang.model.type.ErrorType |
getErrorType(ReferenceBinding binding) |
static java.lang.Object |
getMatchingDummyValue(java.lang.Class<?> expectedType) |
static java.util.Set<javax.lang.model.element.Modifier> |
getModifiers(int modifiers,
javax.lang.model.element.ElementKind kind) |
static java.util.Set<javax.lang.model.element.Modifier> |
getModifiers(int modifiers,
javax.lang.model.element.ElementKind kind,
boolean isFromBinary)
Convert from the JDT's ClassFileConstants flags to the Modifier enum.
|
javax.lang.model.type.NoType |
getNoType(javax.lang.model.type.TypeKind kind) |
javax.lang.model.type.NullType |
getNullType() |
static AnnotationBinding[] |
getPackedAnnotationBindings(AnnotationBinding[] annotations) |
PrimitiveTypeImpl |
getPrimitiveType(BaseTypeBinding binding) |
PrimitiveTypeImpl |
getPrimitiveType(javax.lang.model.type.TypeKind kind)
Get a type mirror object representing the specified primitive type kind.
|
javax.lang.model.type.TypeMirror |
getReceiverType(MethodBinding binding) |
static AnnotationBinding[] |
getUnpackedAnnotationBindings(AnnotationBinding[] annotations) |
javax.lang.model.element.AnnotationMirror |
newAnnotationMirror(AnnotationBinding binding) |
javax.lang.model.element.Element |
newElement(Binding binding) |
javax.lang.model.element.Element |
newElement(Binding binding,
javax.lang.model.element.ElementKind kindHint)
Create a new element that knows what kind it is even if the binding is unresolved.
|
javax.lang.model.element.PackageElement |
newPackageElement(PackageBinding binding)
Convenience method - equivalent to
(PackageElement)Factory.newElement(binding) |
javax.lang.model.type.TypeMirror |
newTypeMirror(Binding binding)
Given a binding of uncertain type, try to create the right sort of TypeMirror for it.
|
javax.lang.model.element.TypeParameterElement |
newTypeParameterElement(TypeVariableBinding variable,
javax.lang.model.element.Element declaringElement) |
static java.lang.Object |
performNecessaryPrimitiveTypeConversion(java.lang.Class<?> expectedType,
java.lang.Object value,
boolean avoidReflectException)
This method is derived from code in org.aspectj.org.eclipse.jdt.apt.core.
|
static void |
setArrayMatchingDummyValue(java.lang.Object array,
int i,
java.lang.Class<?> expectedLeafType)
Set an element of an array to the appropriate dummy value type
|
public static final java.lang.Byte DUMMY_BYTE
public static final java.lang.Character DUMMY_CHAR
public static final java.lang.Double DUMMY_DOUBLE
public static final java.lang.Float DUMMY_FLOAT
public static final java.lang.Integer DUMMY_INTEGER
public static final java.lang.Long DUMMY_LONG
public static final java.lang.Short DUMMY_SHORT
public static java.util.List<? extends javax.lang.model.element.AnnotationMirror> EMPTY_ANNOTATION_MIRRORS
public Factory(BaseProcessingEnvImpl env)
public java.util.List<? extends javax.lang.model.element.AnnotationMirror> getAnnotationMirrors(AnnotationBinding[] annotations)
public <A extends java.lang.annotation.Annotation> A[] getAnnotationsByType(AnnotationBinding[] annoInstances, java.lang.Class<A> annotationClass)
public <A extends java.lang.annotation.Annotation> A getAnnotation(AnnotationBinding[] annoInstances, java.lang.Class<A> annotationClass)
public static java.lang.Object getMatchingDummyValue(java.lang.Class<?> expectedType)
public javax.lang.model.type.TypeMirror getReceiverType(MethodBinding binding)
public static java.util.Set<javax.lang.model.element.Modifier> getModifiers(int modifiers,
javax.lang.model.element.ElementKind kind)
public static java.util.Set<javax.lang.model.element.Modifier> getModifiers(int modifiers,
javax.lang.model.element.ElementKind kind,
boolean isFromBinary)
public javax.lang.model.element.AnnotationMirror newAnnotationMirror(AnnotationBinding binding)
public javax.lang.model.element.Element newElement(Binding binding, javax.lang.model.element.ElementKind kindHint)
public javax.lang.model.element.Element newElement(Binding binding)
public javax.lang.model.element.PackageElement newPackageElement(PackageBinding binding)
(PackageElement)Factory.newElement(binding)public javax.lang.model.type.NullType getNullType()
public javax.lang.model.type.NoType getNoType(javax.lang.model.type.TypeKind kind)
public PrimitiveTypeImpl getPrimitiveType(javax.lang.model.type.TypeKind kind)
public PrimitiveTypeImpl getPrimitiveType(BaseTypeBinding binding)
public javax.lang.model.type.TypeMirror newTypeMirror(Binding binding)
public javax.lang.model.element.TypeParameterElement newTypeParameterElement(TypeVariableBinding variable, javax.lang.model.element.Element declaringElement)
declaringElement - the class, method, etc. that is parameterized by this parameter.public javax.lang.model.type.ErrorType getErrorType(ReferenceBinding binding)
public static java.lang.Object performNecessaryPrimitiveTypeConversion(java.lang.Class<?> expectedType,
java.lang.Object value,
boolean avoidReflectException)
avoidReflectException is set to true
Return false if the expected type is boolean
Return numeric 0 for all numeric primitive types and '0' for char
Otherwise:
Return the value unchanged.
In the invocation handler case:
The value returned by InvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
will be converted into the expected type by the Proxy.
If the value and the expected type does not agree, and the value is not null,
a ClassCastException will be thrown. A NullPointerException will result if the
expected type is a primitive type and the value is null.
This behavior causes annotation processors a lot of pain and the decision is
to not throw such unchecked exception. In the case where a ClassCastException or
NullPointerException will be thrown return some dummy value. Otherwise, return
the original value.
Chosen dummy values:
Return false if the expected type is boolean
Return numeric 0 for all numeric primitive types and '0' for char
This behavior is triggered by setting avoidReflectException to true
Note: the new behavior deviates from what's documented in
InvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) and also deviates from
Sun's implementation.value - the current value from the annotation instance.expectedType - the expected type of the value.public static void setArrayMatchingDummyValue(java.lang.Object array,
int i,
java.lang.Class<?> expectedLeafType)
array - i - expectedLeafType - public static AnnotationBinding[] getPackedAnnotationBindings(AnnotationBinding[] annotations)
public static AnnotationBinding[] getUnpackedAnnotationBindings(AnnotationBinding[] annotations)