public class ClassInspector
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
BIGDECIMAL_TYPE_NAME |
private ClassFactory |
cf |
private static java.lang.String[] |
nonPrimTypeNames |
private static java.lang.String |
OBJECT_TYPE_NAME |
private static java.lang.String[] |
primTypeNames |
private static java.lang.String |
STRING_TYPE_NAME |
Constructor and Description |
---|
ClassInspector(ClassFactory cf)
DO NOT USE!
|
Modifier and Type | Method and Description |
---|---|
boolean |
accessible(java.lang.String className)
Does the named class exist, and is it accessible?
|
private void |
addResolvedTypes(java.util.HashMap<java.lang.reflect.Type,java.lang.reflect.Type> resolvedTypes,
java.lang.reflect.Type genericType)
Given a generic type, add its parameter types to an evolving
map of resolved types.
|
boolean |
assignableTo(java.lang.String fromClassName,
java.lang.String toClassName)
Is one named class assignable to another named class or interface?
|
private java.lang.Class[] |
boundType(java.lang.reflect.Type type)
Get the bounds for a single type variable.
|
protected boolean |
classConvertableFromTo(java.lang.Class fromClass,
java.lang.Class toClass,
boolean mixTypes)
Can we convert a fromClass to toClass.
|
java.lang.reflect.Member |
findPublicConstructor(java.lang.String receiverType,
java.lang.String[] parmTypes,
java.lang.String[] primParmTypes,
boolean[] isParam)
Find a public constructor that implements a given signature.
|
java.lang.reflect.Member |
findPublicField(java.lang.String receiverType,
java.lang.String fieldName,
boolean staticField)
Find a public field for a class.
|
java.lang.reflect.Member |
findPublicMethod(java.lang.String receiverType,
java.lang.String methodName,
java.lang.String[] parmTypes,
java.lang.String[] primParmTypes,
boolean[] isParam,
boolean staticMethod,
boolean repeatLastParameter,
boolean hasVarargs)
Find a public method that implements a given signature.
|
private java.lang.Class[][] |
findTypeBounds(java.lang.reflect.ParameterizedType pt)
Get the type bounds for all of the type variables of the given
parameterized type.
|
java.lang.Class<?> |
getClass(java.lang.String className)
Get (load) the class for the given class name.
|
java.lang.String |
getDeclaringClass(java.lang.reflect.Member method)
Get the declaring class for a method.
|
java.lang.Class<?>[] |
getGenericParameterTypes(java.lang.Class parameterizedType,
java.lang.Class implementation)
Given an implementation of a parameterized interface, return
the actual types of the interface type variables.
|
private java.util.ArrayList<java.lang.Class<?>> |
getParameterTypes(java.lang.Class<?> parameterizedType,
java.util.HashMap<java.lang.reflect.Type,java.lang.reflect.Type> resolvedTypes)
Given a map of resolved types, compose them together in order
to resolve the actual concrete types that are plugged into the
parameterized type.
|
java.lang.String[] |
getParameterTypes(java.lang.reflect.Member method)
Get the parameter types for a method described by a Member as a String[].
|
private java.lang.Class |
getRawType(java.lang.reflect.Type bound)
Get the raw type of a type bound.
|
private java.util.HashMap<java.lang.reflect.Type,java.lang.reflect.Type> |
getResolvedTypes(java.util.ArrayList<java.lang.Class<?>> chain)
Given an inheritance chain of types, stretching from a superclass down
to a terminal concrete class, construct a map of generic types to their
resolved types.
|
java.lang.String |
getType(java.lang.reflect.Member member)
Get the Java name of the return type from a Member representing
a method or the type of a Member representing a field.
|
java.lang.Class[][] |
getTypeBounds(java.lang.Class parameterizedInterface,
java.lang.Class implementation)
Given an implementation of a parameterized interface, return
the bounds on the type variables.
|
private java.util.ArrayList<java.lang.Class<?>> |
getTypeChain(java.lang.Class<?> chainEnd,
java.lang.Class<?> start)
Construct an inheritance chain of types stretching from a supertype down
to a concrete implementation.
|
boolean |
instanceOf(java.lang.String className,
java.lang.Object obj)
Is the given object an instance of the named class?
|
boolean |
isVarArgsMethod(java.lang.reflect.Member member)
Return true if the method or constructor supports varargs.
|
static boolean |
primitiveType(java.lang.String typeName)
Determine whether a type is a Java primitive, like int or boolean
|
static java.lang.String |
readableClassName(java.lang.Class clazz)
Translate a JVM-style type descriptor to a Java-language-style type
name.
|
private java.lang.reflect.Member |
resolveMethod(java.lang.Class receiverClass,
java.lang.String methodName,
java.lang.Class[] paramClasses,
java.lang.Class[] primParamClasses,
boolean[] isParam,
boolean staticMethod,
boolean repeatLastParameter,
java.lang.reflect.Member[] methods,
boolean hasVarargs)
Tricky function to resolve a method.
|
private boolean |
signatureConvertableFromTo(java.lang.Class[] fromTypes,
java.lang.Class[] primFromTypes,
java.lang.Class[] toTypes,
boolean[] isParam,
boolean mixTypes)
Can we convert a signature from fromTypes(primFromTypes) to toTypes.
|
private static final java.lang.String[] primTypeNames
private static final java.lang.String[] nonPrimTypeNames
private static final java.lang.String OBJECT_TYPE_NAME
private static final java.lang.String STRING_TYPE_NAME
private static final java.lang.String BIGDECIMAL_TYPE_NAME
private final ClassFactory cf
public ClassInspector(ClassFactory cf)
public boolean instanceOf(java.lang.String className, java.lang.Object obj) throws java.lang.ClassNotFoundException
className
- The name of the classobj
- The object to test to see if it's an instance
of the named classjava.lang.ClassNotFoundException
public boolean assignableTo(java.lang.String fromClassName, java.lang.String toClassName)
fromClassName
- The name of the class to be assignedtoClassName
- The name of the class to be assigned topublic boolean accessible(java.lang.String className) throws java.lang.ClassNotFoundException
className
- The name of the class to test for existencejava.lang.ClassNotFoundException
public java.lang.String getType(java.lang.reflect.Member member)
member
- A Member representing the method for
which we want the return type.public java.lang.reflect.Member findPublicMethod(java.lang.String receiverType, java.lang.String methodName, java.lang.String[] parmTypes, java.lang.String[] primParmTypes, boolean[] isParam, boolean staticMethod, boolean repeatLastParameter, boolean hasVarargs) throws java.lang.ClassNotFoundException, StandardException
receiverType
- The class name of the receivermethodName
- The name of the methodparmTypes
- An array of class names representing the
parameter types. Pass a zero-element array if
there are no parameters. Pass a null if it is
okay to match any signature.primParmTypes
- This is used in the second pass of the two-pass
method resolution algorithm. Use primitive type
if it has one, otherwise use same object typeisParam
- Array of booleans telling whether parameter is a ?.staticMethod
- Find a static method.repeatLastParameter
- If true the last parameter may be repeated any number of times (total count must be greater than one).
If false the last parameter is matched as usual. This also requires an exact match on the last parameter type.java.lang.ClassNotFoundException
- One or more of the classes does
not exist.StandardException
- Thrown on ambiguous method invocation.Member
,
Modifier
public java.lang.reflect.Member findPublicField(java.lang.String receiverType, java.lang.String fieldName, boolean staticField) throws StandardException
receiverType
- The class name of the receiverfieldName
- The name of the fieldstaticField
- Find a static fieldStandardException
- Class or field does not exist or is not public or a security exception.Member
,
Modifier
public java.lang.reflect.Member findPublicConstructor(java.lang.String receiverType, java.lang.String[] parmTypes, java.lang.String[] primParmTypes, boolean[] isParam) throws java.lang.ClassNotFoundException, StandardException
receiverType
- The class name of the receiverparmTypes
- An array of class names representing the
parameter types. Pass a zero-element array if
there are no parameters.primParmTypes
- This is used in the second pass of the two-pass
method resolution algorithm. Use primitive type
if it has one, otherwise use same object typeisParam
- Array of booleans telling whether parameter is a ?.java.lang.ClassNotFoundException
- One or more of the classes does
not exist.StandardException
- Thrown on ambiguous constructor invocation.Member
,
Modifier
public java.lang.Class[][] getTypeBounds(java.lang.Class parameterizedInterface, java.lang.Class implementation) throws StandardException
StandardException
public boolean isVarArgsMethod(java.lang.reflect.Member member)
public java.lang.Class<?>[] getGenericParameterTypes(java.lang.Class parameterizedType, java.lang.Class implementation) throws StandardException
StandardException
public java.lang.String[] getParameterTypes(java.lang.reflect.Member method)
method
- A Member describing a methodpublic static boolean primitiveType(java.lang.String typeName)
typeName
- The name of the Java typeprivate java.lang.reflect.Member resolveMethod(java.lang.Class receiverClass, java.lang.String methodName, java.lang.Class[] paramClasses, java.lang.Class[] primParamClasses, boolean[] isParam, boolean staticMethod, boolean repeatLastParameter, java.lang.reflect.Member[] methods, boolean hasVarargs) throws StandardException
receiverClass
- the class who holds the methodsmethodName
- the name of methodparamClasses
- object type classes of input parametersprimParamClasses
- primitive type classes or nullisParam
- isParam (for ?) arraystaticMethod
- static method or notmethods
- method stackStandardException
public java.lang.Class<?> getClass(java.lang.String className) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
- Class cannot be found, or
a SecurityException or LinkageException was thrown loading the class.private boolean signatureConvertableFromTo(java.lang.Class[] fromTypes, java.lang.Class[] primFromTypes, java.lang.Class[] toTypes, boolean[] isParam, boolean mixTypes)
fromTypes
- from types' classesprimFromTypes
- primitive from types or nulltoTypes
- to types' classesisParam
- is parameter (?) or notmixTypes
- mixing object/primitive types for comparisonprotected boolean classConvertableFromTo(java.lang.Class fromClass, java.lang.Class toClass, boolean mixTypes)
fromClass
- from classtoClass
- to classmixTypes
- mixing object/primitive types for comparisonpublic static java.lang.String readableClassName(java.lang.Class clazz)
clazz
- The String that contains the JVM type namepublic java.lang.String getDeclaringClass(java.lang.reflect.Member method)
method
- A Member describing a methodMember.getDeclaringClass()
private java.lang.Class[][] findTypeBounds(java.lang.reflect.ParameterizedType pt)
private java.lang.Class[] boundType(java.lang.reflect.Type type)
private java.lang.Class getRawType(java.lang.reflect.Type bound)
private java.util.ArrayList<java.lang.Class<?>> getTypeChain(java.lang.Class<?> chainEnd, java.lang.Class<?> start)
private java.util.HashMap<java.lang.reflect.Type,java.lang.reflect.Type> getResolvedTypes(java.util.ArrayList<java.lang.Class<?>> chain)
private void addResolvedTypes(java.util.HashMap<java.lang.reflect.Type,java.lang.reflect.Type> resolvedTypes, java.lang.reflect.Type genericType)
private java.util.ArrayList<java.lang.Class<?>> getParameterTypes(java.lang.Class<?> parameterizedType, java.util.HashMap<java.lang.reflect.Type,java.lang.reflect.Type> resolvedTypes)
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.