Class Factory
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.compiler.apt.model.Factory
Creates javax.lang.model wrappers around JDT internal compiler bindings.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFactory(BaseProcessingEnvImpl env)
This object should only be constructed by the BaseProcessingEnvImpl. -
Method Summary
Modifier and TypeMethodDescription<A extends Annotation>
AgetAnnotation(AnnotationBinding[] annoInstances, Class<A> annotationClass)
List<? extends AnnotationMirror>
getAnnotationMirrors(AnnotationBinding[] annotations)
Convert an array of compiler annotation bindings into a list of AnnotationMirror<A extends Annotation>
A[]getAnnotationsByType(AnnotationBinding[] annoInstances, Class<A> annotationClass)
getErrorType(ReferenceBinding binding)
static Object
getMatchingDummyValue(Class<?> expectedType)
getModifiers(int modifiers, ElementKind kind)
getModifiers(int modifiers, ElementKind kind, boolean isFromBinary)
Convert from the JDT's ClassFileConstants flags to the Modifier enum.static AnnotationBinding[]
getPackedAnnotationBindings(AnnotationBinding[] annotations)
getPrimitiveType(TypeKind kind)
Get a type mirror object representing the specified primitive type kind.getPrimitiveType(BaseTypeBinding binding)
getReceiverType(MethodBinding binding)
static AnnotationBinding[]
getUnpackedAnnotationBindings(AnnotationBinding[] annotations)
newAnnotationMirror(AnnotationBinding binding)
newElement(Binding binding)
newElement(Binding binding, ElementKind kindHint)
Create a new element that knows what kind it is even if the binding is unresolved.newPackageElement(PackageBinding binding)
Convenience method - equivalent to(PackageElement)Factory.newElement(binding)
newTypeMirror(Binding binding)
Given a binding of uncertain type, try to create the right sort of TypeMirror for it.newTypeParameterElement(TypeVariableBinding variable, Element declaringElement)
static Object
performNecessaryPrimitiveTypeConversion(Class<?> expectedType, Object value, boolean avoidReflectException)
This method is derived from code in org.aspectj.org.eclipse.jdt.apt.core.static void
setArrayMatchingDummyValue(Object array, int i, Class<?> expectedLeafType)
Set an element of an array to the appropriate dummy value type
-
Field Details
-
DUMMY_BYTE
-
DUMMY_CHAR
-
DUMMY_DOUBLE
-
DUMMY_FLOAT
-
DUMMY_INTEGER
-
DUMMY_LONG
-
DUMMY_SHORT
-
EMPTY_ANNOTATION_MIRRORS
-
-
Constructor Details
-
Factory
This object should only be constructed by the BaseProcessingEnvImpl.
-
-
Method Details
-
getAnnotationMirrors
Convert an array of compiler annotation bindings into a list of AnnotationMirror- Returns:
- a non-null, possibly empty, unmodifiable list.
-
getAnnotationsByType
public <A extends Annotation> A[] getAnnotationsByType(AnnotationBinding[] annoInstances, Class<A> annotationClass) -
getAnnotation
public <A extends Annotation> A getAnnotation(AnnotationBinding[] annoInstances, Class<A> annotationClass) -
getMatchingDummyValue
-
getReceiverType
-
getModifiers
-
getModifiers
Convert from the JDT's ClassFileConstants flags to the Modifier enum. -
newAnnotationMirror
-
newElement
Create a new element that knows what kind it is even if the binding is unresolved. -
newElement
-
newPackageElement
Convenience method - equivalent to(PackageElement)Factory.newElement(binding)
-
getNullType
-
getNoType
-
getPrimitiveType
Get a type mirror object representing the specified primitive type kind. -
getPrimitiveType
-
newTypeMirror
Given a binding of uncertain type, try to create the right sort of TypeMirror for it. -
newTypeParameterElement
public TypeParameterElement newTypeParameterElement(TypeVariableBinding variable, Element declaringElement)- Parameters:
declaringElement
- the class, method, etc. that is parameterized by this parameter.
-
getErrorType
-
performNecessaryPrimitiveTypeConversion
public static Object performNecessaryPrimitiveTypeConversion(Class<?> expectedType, Object value, boolean avoidReflectException)This method is derived from code in org.aspectj.org.eclipse.jdt.apt.core. This method is designed to be invoked by the invocation handler and anywhere that requires a AnnotationValue (AnnotationMirror member values and default values from annotation member). Regardless of the path, there are common primitive type conversion that needs to take place. The type conversions respect the type widening and narrowing rules from JLS 5.1.2 and 5.1.2. The only question remains is what is the type of the return value when the type conversion fails? WhenavoidReflectException
is set totrue
Returnfalse
if the expected type isboolean
Return numeric 0 for all numeric primitive types and '0' forchar
Otherwise: Return the value unchanged. In the invocation handler case: The value returned byInvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
will be converted into the expected type by theProxy
. 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: Returnfalse
if the expected type isboolean
Return numeric 0 for all numeric primitive types and '0' forchar
This behavior is triggered by settingavoidReflectException
totrue
Note: the new behavior deviates from what's documented inInvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
and also deviates from Sun's implementation.- Parameters:
value
- the current value from the annotation instance.expectedType
- the expected type of the value.
-
setArrayMatchingDummyValue
Set an element of an array to the appropriate dummy value type- Parameters:
array
-i
-expectedLeafType
-
-
getPackedAnnotationBindings
-
getUnpackedAnnotationBindings
-