Top Fields Constructors Methods
org.glassfish.hk2.utilities.reflection

public final Class ReflectionHelper

extends Object
Class Inheritance
Imports
java.io.IOException, java.lang.annotation.Annotation, java.lang.reflect.AccessibleObject, .AnnotatedElement, .Array, .Constructor, .Field, .GenericArrayType, .InvocationTargetException, .Member, .Method, .Modifier, .ParameterizedType, .Type, .TypeVariable, .WildcardType, java.security.AccessController, .PrivilegedAction, java.util.Collection, .Collections, .HashMap, .HashSet, .LinkedHashMap, .LinkedHashSet, .LinkedList, .List, .Map, .Set, jakarta.inject.Named, .Qualifier, .Scope, org.glassfish.hk2.utilities.general.GeneralUtilities, org.glassfish.hk2.utilities.reflection.internal.MethodWrapperImpl

Author
jwells

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static final HashSet<Character>
private static final char[]
private static final String
private static final HashMap<Character, Character>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
addAllGenericInterfaces(Class<?> rawClass, Type type, Set<Type> closures)

Gets all the interfaces on this particular class (but not any superclasses of this class).

private static void
public static void
addMetadata(Map<String, List<String>>
The base metadata object
metadatas
,
String
The key to which to add the value. May not be null
key
,
String
The value to add. May not be null
value
)

Adds a value to the list of values associated with this key

public static boolean

Returns:

true if the candidate set contains the entire required set
annotationContainsAll
(final Set<Annotation>
The candidate annotations
candidateAnnotations
,
final Set<Annotation>
The required annotations
requiredAnnotations
)

This is used to check on the annotation set.

public static <T> T

Returns:

A casted version of o
cast
(Object
The thing to cast
o
)

Casts this thing to the given type

public static MethodWrapper

Returns:

A method wrapper that has a proper equals/hashCode
createMethodWrapper
(Method
The non-null method to wrap
wrapMe
)

Creates a method wrapper for the given method

public static Map<String, List<String>>

Returns:

A deep copy of the metadata
deepCopyMetadata
(Map<String, List<String>>
The guy to copy (if null, null will be returned)
copyMe
)

This method does a deep copy of the incoming meta-data, (which basically means we will also make copies of the value list)

private static String
escapeString(String escapeMe)

private static ParameterizedType
private static Type
fixGenericArrayTypeVariables(GenericArrayType type, Map<String, Type> typeArgumentsMap)

Replace any TypeVariables in the given type's arguments with the actual argument types.

private static Type
fixTypeVariables(ParameterizedType type, Map<String, Type> typeArgumentsMap)

Replace any TypeVariables in the given type's arguments with the actual argument types.

public static Set<Type>

Returns:

The type itself and the contracts it implements
getAdvertisedTypesFromClass
(Type
The outer type to analyze
type
,
Class<? extends Annotation>
The annotation to use to discover the advertised types
markerAnnotation
)

Returns the set of types this class advertises

public static Set<Type>

Returns:

The type itself and the contracts it implements
getAdvertisedTypesFromObject
(Object
the object we are analyzing
t
,
Class<? extends Annotation>
The annotation to use to discover the advertised types
markerAnnotation
)

Returns the set of types this class advertises

private static void
getAllContractsFromInterfaces(Class<?> clazzOrInterface, Class<? extends Annotation> markerAnnotation, Set<Type> addToMe, Set<Class<?>> alreadyHandled)

public static Set<Type>
private static Class<?>
public static Set<String>

Returns:

The type itself and the contracts it implements
getContractsFromClass
(final Class<?>
the class we are analyzing
clazz
,
final Class<? extends Annotation>
The annotation to use to discover annotated types
markerAnnotation
)

Returns the set of types this class advertises

private static ClassLoader

Returns:

The current context class loader
getCurrentContextClassLoader
()

Gets the current context class loader with privs

public static Type

Returns:

If this is a class, Object.class. If this is a parameterized type, the type of the first actual argument
getFirstTypeArgument
(Type
The type to find the first type argument on
type
)

Gets the first type argument if this is a parameterized type, otherwise it returns Object.class

public static String

Returns:

The name this class should have
getName
(Class<?>
The class to evaluate
implClass
)

Returns the name that should be associated with this class

private static String
getNamedName(Named named, Class<?> implClass)

public static String

Returns:

null if no Named was found, or the appropriate name otherwise
getNameFromAllQualifiers
(Set<Annotation>
The set of qualifiers that may or may not have Named in it
qualifiers
,
AnnotatedElement
The parent element for which we are searching
parent
)

Gets the name from the &46;Named qualifier in this set of qualifiers

private static Type[]
getNewTypeArguments(final ParameterizedType type, final Map<String, Type> typeArgumentsMap)

Get a new array of type arguments for the given ParameterizedType, replacing any TypeVariables with actual types.

private static Type
getNewTypeArrayArguments(final GenericArrayType gat, final Map<String, Type> typeArgumentsMap)

Get a new Type for a GenericArrayType, replacing any TypeVariables with actual types.

public static Set<Annotation>

Returns:

The set of qualifiers. Will not return null but may return an empty set
getQualifierAnnotations
(final AnnotatedElement
The thing to analyze
annotatedGuy
)

Gets all the qualifier annotations from the object

A strange behavior of this method is that if the annotatedGuy is a field and that field has the Named annotation on it with no value, then that Named annotation will NOT be added to the return list.

public static Set<String>

Returns:

The set of qualifiers. Will not return null but may return an empty set
getQualifiersFromClass
(Class<?>
The class to analyze
clazz
)

Gets all the qualifiers from the object

public static Set<Annotation>

Returns:

The set of qualifiers. Will not return null but may return an empty set
getQualifiersFromObject
(Object
The object to analyze
t
)

Gets all the qualifiers from the object

public static Class<?>

Returns:

The raw class associated with this type
getRawClass
(Type
The type to find the raw class on
type
)

Given the type parameter gets the raw type represented by the type, or null if this has no associated raw class

public static Annotation

Returns:

The class of the scope annotation
getScopeAnnotationFromClass
(Class<?>
The class to analyze
clazz
)

Gets the scope annotation from the object

public static Annotation

Returns:

The class of the scope annotation
getScopeAnnotationFromObject
(Object
The object to analyze
t
)

Gets the scope annotation from the object

public static Annotation

Returns:

The class of the scope annotation
getScopeFromClass
(Class<?>
The class to analyze
clazz
,
Annotation
The scope that should be returned if no scope could be found
annoDefault
)

Gets the scope annotation from the object

public static Annotation

Returns:

The class of the scope annotation
getScopeFromObject
(Object
The object to analyze
t
,
Annotation
The default that this should have if no scope could be found
annoDefault
)

Gets the scope annotation from the object

private static Map<String, Type>
getTypeArguments(Class<?> rawClass, ParameterizedType type)

Gets a mapping of type variable names of the raw class to type arguments of the parameterized type.

private static Set<Type>

Returns:

The non-null (and never empty) set of classes that this class can be assigned to
getTypeClosure
(Type
The full type closure of the given class with nothing omitted (normal case). May not be null
ofType
)

Returns the type closure of the given class

public static Set<Type>

Returns:

The type closure restricted to the contracts
getTypeClosure
(Type
The type to check
ofType
,
Set<String>
The contracts this type is allowed to handle
contracts
)

Returns the type closure, as restricted by the classes listed in the set of contracts implemented

private static Set<Annotation>
private static int

Returns:

The number of characters read until the end of the set
internalReadSet
(char[]
The line to read
asChars
,
int startIndex, Collection<String>
The set to add the strings to
addToMe
)

Writes a set in a way that can be read from an input stream as well.

public static Object

Returns:

The return from the invocation
invoke
(Object
the object on which to invoke it
o
,
Method
the method to invoke
m
,
Object[]
The arguments to invoke (may not be null)
args
,
boolean
true if the ContextClassLoader shoult remain null with this call
neutralCCL
)

This version of invoke is CCL neutral (it will return with the same CCL as what it went in with)

public static boolean

Returns:

true if this is an annotation
isAnnotationAQualifier
(Annotation
The annotation to check
anno
)

Returns true if the given annotation is a qualifier

private static boolean
private static boolean
public static boolean

Returns:

true if the member is private
isPrivate
(Member
The non-null member to test
member
)

Returns true if the underlying member is private

public static boolean

Returns:

true if the member is static
isStatic
(Member
The non-null member to test
member
)

Returns true if the underlying member is static

public static Object

Returns:

The return from the invocation
makeMe
(Constructor<?>
the constructor to call
c
,
Object[]
The arguments to invoke (may not be null)
args
,
boolean
true if the context class loader should remain null through this call
neutralCCL
)

This version of invoke is CCL neutral (it will return with the same CCL as what it went in with)

public static void
parseServiceMetadataString(String
A non-null metadata field that normally comes from the Service metadata field
metadataField
,
Map<String, List<String>>
The metadata field to add to
metadata
)

This method parses the string that is found in the VService metadata field.

private static int
readKeyStringListLine(char[] asChars, int startIndex, Map<String, List<String>> addToMe)

public static void
readMetadataMap(String
The line to read
line
,
Map<String, List<String>>
The set to add the strings to
addToMe
)

Writes a set in a way that can be read from an input stream as well

public static void
readSet(String
The line to read
line
,
Collection<String>
The set to add the strings to
addToMe
)

Writes a set in a way that can be read from an input stream as well.

private static void
recursiveAddContractsFromInterfacesToMap(final Class<T>[] interfaces, final Set<String> contractSet, final Class<? extends Annotation> markerAnnotation)

public static boolean

Returns:

true if any value was removed
removeAllMetadata
(Map<String, List<String>>
The base metadata object
metadatas
,
String
The key of the metadata values to remove
key
)

Removes all the metadata values associated with key

public static boolean

Returns:

true if the value was removed
removeMetadata
(Map<String, List<String>>
The base metadata object
metadatas
,
String
The key of the value to remove. May not be null
key
,
String
The value to remove. May not be null
value
)

Removes the given value from the given key

public static Type

Returns:

The resolved field type by way of its subclasses. Will not return null, but may return the original fields generic type
resolveField
(Class<?>
The instantiation class. Must not be null
topclass
,
Field
The non-null field whose type to resolve
field
)

Resolves the generic type of a field given the actual class being instantiated

public static Type

Returns:

null if userType is not related, or the given hardened parameterized type from the knownType list
resolveKnownType
(TypeVariable<?>
The user type to replace. May not be null
userType
,
ParameterizedType
The user defined known final type of the knownDeclaringClass. May not be null
knownType
,
Class<?>
The declaringClass for which knownType is the resolved ParameterizedType for it. May not be null
knownDeclaringClass
)

If you have a class that declares type variables (knownDeclaringClass) and the type the user has told us it should be (knownType) then return the replaced type for the given userType.

public static Type

Returns:

The resolved type by way of its subclasses. Will not return null but may return lookingForType if it could not be further resolved
resolveMember
(Class<?>
The instantiation class. Must not be null
topclass
,
Type
The type to resolve. Must not be null
lookingForType
,
Class<?>
The class of the entity declaring the lookingForType. Must not be null
declaringClass
)

Resolves the generic type of a type and declaring class given the actual class being instantiated

private static void
setAccessible(final AccessibleObject
The object to change
ao
)

Sets this accessible object to be accessible using the permissions of the hk2-locator bundle (which will need the required grant)

private static void
setContextClassLoader(final Thread
The thread on which to set the classloader
t
,
final ClassLoader
The classloader to set
l
)

Sets the context classloader under the privileged of this class

public static void
setField(Field
The non-null field to set
field
,
Object
The non-null instance to set into
instance
,
Object
The value to which the field should be set
value
)

Sets the given field to the given value

public static Class<?>

Returns:

The translated type or the type itself
translatePrimitiveType
(Class<?>
The type to convert
type
)

Converts the type to its java form, or returns the original

private static Map<String, Type>
typesFromSubClassToDeclaringClass(Class<?> topClass, Class<?> declaringClass)

private static String
public static String

Returns:

The metadata in an externalizable format
writeMetadata
(Map<String, List<String>>
The metadata to externalize
metadata
)

Used to write the metadata out

public static String

Returns:

a representation of a list
writeSet
(Set<?>
The set to write
set
)

Writes a set in a way that can be read from an input stream as well

public static String

Returns:

a representation of a list
writeSet
(Set<?>
The set to write
set
,
Object
An object to exclude from the list of things written
excludeMe
)

Writes a set in a way that can be read from an input stream as well

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait