final class AttributeMethods
extends java.lang.Object
Annotation
with consistent ordering as well as a few useful utility methods.Modifier and Type | Field and Description |
---|---|
private java.lang.Class<? extends java.lang.annotation.Annotation> |
annotationType |
private java.lang.reflect.Method[] |
attributeMethods |
private static java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,AttributeMethods> |
cache |
private boolean[] |
canThrowTypeNotPresentException |
private boolean |
hasDefaultValueMethod |
private boolean |
hasNestedAnnotation |
private static java.util.Comparator<java.lang.reflect.Method> |
methodComparator |
(package private) static AttributeMethods |
NONE |
Modifier | Constructor and Description |
---|---|
private |
AttributeMethods(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.reflect.Method[] attributeMethods) |
Modifier and Type | Method and Description |
---|---|
private void |
assertAnnotation(java.lang.annotation.Annotation annotation) |
(package private) boolean |
canThrowTypeNotPresentException(int index)
Determine if the attribute at the specified index could throw a
TypeNotPresentException when accessed. |
private static AttributeMethods |
compute(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType) |
(package private) static java.lang.String |
describe(java.lang.Class<?> annotationType,
java.lang.String attributeName)
Create a description for the given attribute method suitable to use in
exception messages and logs.
|
(package private) static java.lang.String |
describe(java.lang.reflect.Method attribute)
Create a description for the given attribute method suitable to use in
exception messages and logs.
|
(package private) static AttributeMethods |
forAnnotationType(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Get the attribute methods for the given annotation type.
|
(package private) java.lang.reflect.Method |
get(int index)
Get the attribute at the specified index.
|
(package private) java.lang.reflect.Method |
get(java.lang.String name)
Get the attribute with the specified name or
null if no
matching attribute exists. |
(package private) boolean |
hasDefaultValueMethod()
Determine if at least one of the attribute methods has a default value.
|
(package private) boolean |
hasNestedAnnotation()
Determine if at least one of the attribute methods is a nested annotation.
|
(package private) int |
indexOf(java.lang.reflect.Method attribute)
Get the index of the specified attribute, or
-1 if the
attribute is not in this collection. |
(package private) int |
indexOf(java.lang.String name)
Get the index of the attribute with the specified name, or
-1
if there is no attribute with the name. |
private static boolean |
isAttributeMethod(java.lang.reflect.Method method) |
(package private) boolean |
isOnlyValueAttribute()
Determine if this instance only contains only a single attribute named
value . |
(package private) boolean |
isValid(java.lang.annotation.Annotation annotation)
Determine if values from the given annotation can be safely accessed without
causing any
TypeNotPresentExceptions . |
(package private) int |
size()
Get the number of attributes in this collection.
|
(package private) void |
validate(java.lang.annotation.Annotation annotation)
Check if values from the given annotation can be safely accessed without causing
any
TypeNotPresentExceptions . |
static final AttributeMethods NONE
private static final java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,AttributeMethods> cache
private static final java.util.Comparator<java.lang.reflect.Method> methodComparator
@Nullable private final java.lang.Class<? extends java.lang.annotation.Annotation> annotationType
private final java.lang.reflect.Method[] attributeMethods
private final boolean[] canThrowTypeNotPresentException
private final boolean hasDefaultValueMethod
private final boolean hasNestedAnnotation
private AttributeMethods(@Nullable java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, java.lang.reflect.Method[] attributeMethods)
boolean isOnlyValueAttribute()
value
.true
if this is only a value attributeboolean isValid(java.lang.annotation.Annotation annotation)
TypeNotPresentExceptions
.annotation
- the annotation to checktrue
if all values are presentvalidate(Annotation)
void validate(java.lang.annotation.Annotation annotation)
TypeNotPresentExceptions
. In particular,
this method is designed to cover Google App Engine's late arrival of such
exceptions for Class
values (instead of the more typical early
Class.getAnnotations() failure
.annotation
- the annotation to validatejava.lang.IllegalStateException
- if a declared Class
attribute could not be readisValid(Annotation)
private void assertAnnotation(java.lang.annotation.Annotation annotation)
@Nullable java.lang.reflect.Method get(java.lang.String name)
null
if no
matching attribute exists.name
- the attribute name to findnull
java.lang.reflect.Method get(int index)
index
- the index of the attribute to returnjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())boolean canThrowTypeNotPresentException(int index)
TypeNotPresentException
when accessed.index
- the index of the attribute to checktrue
if the attribute can throw a
TypeNotPresentException
int indexOf(java.lang.String name)
-1
if there is no attribute with the name.name
- the name to find-1
int indexOf(java.lang.reflect.Method attribute)
-1
if the
attribute is not in this collection.attribute
- the attribute to find-1
int size()
boolean hasDefaultValueMethod()
true
if there is at least one attribute method with a default valueboolean hasNestedAnnotation()
true
if there is at least one attribute method with a nested
annotation typestatic AttributeMethods forAnnotationType(@Nullable java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
annotationType
- the annotation typeprivate static AttributeMethods compute(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
private static boolean isAttributeMethod(java.lang.reflect.Method method)
static java.lang.String describe(@Nullable java.lang.reflect.Method attribute)
attribute
- the attribute to describestatic java.lang.String describe(@Nullable java.lang.Class<?> annotationType, @Nullable java.lang.String attributeName)
annotationType
- the annotation typeattributeName
- the attribute name