Top Description Inners Fields Constructors Methods
sun.reflect.annotation

pack-priv Class AnnotationInvocationHandler

extends Object
implements InvocationHandler, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.reflect.InvocationHandler
Imports
java.io.ObjectInputStream, .Serializable, java.lang.annotation.*, java.lang.reflect.*, java.util.*, java.util.stream.*, java.security.AccessController, .PrivilegedAction

InvocationHandler for dynamic proxy implementation of Annotation.
Author
Josh Bloch
Since
1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private transient volatile Method[]
private final Map<String, Object>
private static final long
private final Class<? extends Annotation>

Constructor Summary

AccessConstructor and Description
pack-priv
AnnotationInvocationHandler(Class<? extends Annotation> type, Map<String, Object> memberValues)

Method Summary

Modifier and TypeMethod and Description
private AnnotationInvocationHandler
asOneOfUs(Object o)

Returns an object's invocation handler if that object is a dynamic proxy with a handler of type AnnotationInvocationHandler.

private Object
cloneArray(Object array)

This method, which clones its array argument, would not be necessary if Cloneable had a public clone method.

private Method[]
private static Stream<String>
convert(byte[] values)

private static Stream<String>
convert(char[] values)

private static Stream<String>
convert(float[] values)

private static Stream<String>
convert(short[] values)

private static Stream<String>
convert(boolean[] values)

private Boolean
equalsImpl(Object proxy, Object o)

Implementation of dynamicProxy.equals(Object o)

private Method[]
getMemberMethods()

Returns the member methods for our annotation type.

private int
hashCodeImpl()

Implementation of dynamicProxy.hashCode()

public Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.

private static boolean
isPrintableAscii(char ch)

Is a character printable ASCII?

private static boolean
memberValueEquals(Object v1, Object v2)

Returns true iff the two member values in "dynamic proxy return form" are equal using the appropriate equality function depending on the member type.

private static int
memberValueHashCode(Object value)

Computes hashCode of a member value (in "dynamic proxy return form")

pack-priv Map<String, Object>
memberValues()

Gets an unmodifiable view on the member values.

private static String
memberValueToString(Object value)

Translates a member value (in "dynamic proxy return form") into a string.

private static String
quote(char ch)

Escapes a character if it has an escape sequence or is non-printable ASCII.

private void
private static String
private static String
toSourceString(Class<?> clazz)

Translates a Class value to a form suitable for use in the string representation of an annotation.

private static String
toSourceString(float f)

private static String
toSourceString(double d)

private static String
private static String
private static String
toSourceString(long ell)

private static String
toSourceString(Enum<?> enumConstant)

private static String
toSourceString(String s)

Return a string suitable for use in the string representation of an annotation.

private String
toStringImpl()

Implementation of dynamicProxy.toString()

private void
validateAnnotationMethods(Method[] memberMethods)

Validates that a method is structurally appropriate for an annotation type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

memberMethodsback to summary
private transient volatile Method[] memberMethods
memberValuesback to summary
private final Map<String, Object> memberValues
Annotations
@SuppressWarnings:serial
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial
typeback to summary
private final Class<? extends Annotation> type

Constructor Detail

AnnotationInvocationHandlerback to summary
pack-priv AnnotationInvocationHandler(Class<? extends Annotation> type, Map<String, Object> memberValues)

Method Detail

asOneOfUsback to summary
private AnnotationInvocationHandler asOneOfUs(Object o)

Returns an object's invocation handler if that object is a dynamic proxy with a handler of type AnnotationInvocationHandler. Returns null otherwise.

cloneArrayback to summary
private Object cloneArray(Object array)

This method, which clones its array argument, would not be necessary if Cloneable had a public clone method.

computeMemberMethodsback to summary
private Method[] computeMemberMethods()
Annotations
@SuppressWarnings:removal
convertback to summary
private static Stream<String> convert(byte[] values)
convertback to summary
private static Stream<String> convert(char[] values)
convertback to summary
private static Stream<String> convert(float[] values)
convertback to summary
private static Stream<String> convert(short[] values)
convertback to summary
private static Stream<String> convert(boolean[] values)
equalsImplback to summary
private Boolean equalsImpl(Object proxy, Object o)

Implementation of dynamicProxy.equals(Object o)

getMemberMethodsback to summary
private Method[] getMemberMethods()

Returns the member methods for our annotation type. These are obtained lazily and cached, as they're expensive to obtain and we only need them if our equals method is invoked (which should be rare).

hashCodeImplback to summary
private int hashCodeImpl()

Implementation of dynamicProxy.hashCode()

invokeback to summary
public Object invoke(Object proxy, Method method, Object[] args)

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

isPrintableAsciiback to summary
private static boolean isPrintableAscii(char ch)

Is a character printable ASCII?

memberValueEqualsback to summary
private static boolean memberValueEquals(Object v1, Object v2)

Returns true iff the two member values in "dynamic proxy return form" are equal using the appropriate equality function depending on the member type. The two values will be of the same type unless one of the containing annotations is ill-formed. If one of the containing annotations is ill-formed, this method will return false unless the two members are identical object references.

memberValueHashCodeback to summary
private static int memberValueHashCode(Object value)

Computes hashCode of a member value (in "dynamic proxy return form")

memberValuesback to summary
pack-priv Map<String, Object> memberValues()

Gets an unmodifiable view on the member values.

memberValueToStringback to summary
private static String memberValueToString(Object value)

Translates a member value (in "dynamic proxy return form") into a string.

quoteback to summary
private static String quote(char ch)

Escapes a character if it has an escape sequence or is non-printable ASCII. Leaves non-ASCII characters alone.

readObjectback to summary
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
Annotations
@Serial
stringStreamToStringback to summary
private static String stringStreamToString(Stream<String> stream)
toSourceStringback to summary
private static String toSourceString(Class<?> clazz)

Translates a Class value to a form suitable for use in the string representation of an annotation.

toSourceStringback to summary
private static String toSourceString(float f)
toSourceStringback to summary
private static String toSourceString(double d)
toSourceStringback to summary
private static String toSourceString(char c)
toSourceStringback to summary
private static String toSourceString(byte b)
toSourceStringback to summary
private static String toSourceString(long ell)
toSourceStringback to summary
private static String toSourceString(Enum<?> enumConstant)
toSourceStringback to summary
private static String toSourceString(String s)

Return a string suitable for use in the string representation of an annotation.

toStringImplback to summary
private String toStringImpl()

Implementation of dynamicProxy.toString()

validateAnnotationMethodsback to summary
private void validateAnnotationMethods(Method[] memberMethods)

Validates that a method is structurally appropriate for an annotation type. As of Java SE 8, annotation types cannot contain static methods and the declared methods of an annotation type must take zero arguments and there are restrictions on the return type.

sun.reflect.annotation back to summary

private Class AnnotationInvocationHandler.UnsafeAccessor

extends Object
Class Inheritance
  • java.lang.Object
  • sun.reflect.annotation.AnnotationInvocationHandler.UnsafeAccessor

Field Summary

Modifier and TypeField and Description
private static final long
private static final long
private static final Unsafe

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
pack-priv static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

memberValuesOffsetback to summary
private static final long memberValuesOffset
typeOffsetback to summary
private static final long typeOffset
unsafeback to summary
private static final Unsafe unsafe

Constructor Detail

UnsafeAccessorback to summary
private UnsafeAccessor()

Method Detail

setMemberValuesback to summary
pack-priv static void setMemberValues(AnnotationInvocationHandler o, Map<String, Object> memberValues)
setTypeback to summary
pack-priv static void setType(AnnotationInvocationHandler o, Class<? extends Annotation> type)