Top Description Fields Constructors Methods
org.apache.derby.iapi.services.loader

public Class ClassInspector

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, java.lang.reflect.*, java.util.ArrayList, .HashMap

Methods to find out relationships between classes and methods within a class. All class names within this interface are treated as java language class names, e.g. int, COM.foo.Myclass, int[], java.lang.Object[]. That is java internal class names as defined in the class file format are not understood.

Field Summary

Modifier and TypeField and Description
private static final String
private final ClassFactory
private static final String[]
private static final String
private static final String[]
private static final String

Constructor Summary

AccessConstructor and Description
public
ClassInspector(ClassFactory
The class factory
cf
)

DO NOT USE!

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the class exists and is accessible, false if not
accessible
(String
The name of the class to test for existence
className
)

Does the named class exist, and is it accessible?

private void
addResolvedTypes(HashMap<Type, Type> resolvedTypes, Type genericType)

Given a generic type, add its parameter types to an evolving map of resolved types.

public boolean

Returns:

true if an object of type fromClass can be assigned to an object of type toClass, false if not.
assignableTo
(String
The name of the class to be assigned
fromClassName
,
String
The name of the class to be assigned to
toClassName
)

Is one named class assignable to another named class or interface?

private Class<T>[]
boundType(Type type)

Get the bounds for a single type variable.

protected boolean

Returns:

true if the conversion is possible
classConvertableFromTo
(Class<T>
from class
fromClass
,
Class<T>
to class
toClass
,
boolean
mixing object/primitive types for comparison
mixTypes
)

Can we convert a fromClass to toClass.

public Member

Returns:

A Member representing the matching constructor. Returns null if no such constructor.
findPublicConstructor
(String
The class name of the receiver
receiverType
,
String[]
An array of class names representing the parameter types. Pass a zero-element array if there are no parameters.
parmTypes
,
String[]
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 type
primParmTypes
,
boolean[]
Array of booleans telling whether parameter is a ?.
isParam
)

Find a public constructor that implements a given signature.

public Member

Returns:

A Member representing the matching field.
findPublicField
(String
The class name of the receiver
receiverType
,
String
The name of the field
fieldName
,
boolean
Find a static field
staticField
)

Find a public field for a class.

public Member

Returns:

A Member representing the matching method. Returns null if no such method.
findPublicMethod
(String
The class name of the receiver
receiverType
,
String
The name of the method
methodName
,
String[]
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.
parmTypes
,
String[]
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 type
primParmTypes
,
boolean[]
Array of booleans telling whether parameter is a ?.
isParam
,
boolean
Find a static method.
staticMethod
,
boolean
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.
repeatLastParameter
,
boolean
True if a varargs marker is expected
hasVarargs
)

Find a public method that implements a given signature.

private Class<T>[][]
findTypeBounds(ParameterizedType pt)

Get the type bounds for all of the type variables of the given parameterized type.

public Class<?>

Returns:

the class
getClass
(String
Name of class
className
)

Get (load) the class for the given class name.

public String

Returns:

A String with the declaring class
getDeclaringClass
(Member
A Member describing a method
method
)

Get the declaring class for a method.

public Class<?>[]

Returns:

the actual types of the interface type variables
getGenericParameterTypes
(Class<T>
A parameterized type
parameterizedType
,
Class<T>
An implementation of that type
implementation
)

Given an implementation of a parameterized interface, return the actual types of the interface type variables.

public String[]

Returns:

A String[] describing the parameters of the method
getParameterTypes
(Member
A Member describing a method
method
)

Get the parameter types for a method described by a Member as a String[].

private ArrayList<Class<?>>
getParameterTypes(Class<?> parameterizedType, HashMap<Type, 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.

private Class<T>
getRawType(Type bound)

Get the raw type of a type bound.

private HashMap<Type, Type>
getResolvedTypes(ArrayList<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.

public String

Returns:

A Java-language-style string describing the return type of the method (for example, it returns "int" instead of "I".
getType
(Member
A Member representing the method for which we want the return type.
member
)

Get the Java name of the return type from a Member representing a method or the type of a Member representing a field.

public Class<T>[][]

Returns:

the bounds on the type variable
getTypeBounds
(Class<T>
A generic interface
parameterizedInterface
,
Class<T>
An implementation of the interface
implementation
)

Given an implementation of a parameterized interface, return the bounds on the type variables.

private ArrayList<Class<?>>
getTypeChain(Class<?> chainEnd, Class<?> start)

Construct an inheritance chain of types stretching from a supertype down to a concrete implementation.

public boolean

Returns:

true if obj is an instanceof className, false if not
instanceOf
(String
The name of the class
className
,
Object
The object to test to see if it's an instance of the named class
obj
)

Is the given object an instance of the named class?

public boolean

Returns:

true if it is a varargs method
isVarArgsMethod
(Member
A member method
member
)

Return true if the method or constructor supports varargs.

public static boolean

Returns:

true if it's a primitive type
primitiveType
(String
The name of the Java type
typeName
)

Determine whether a type is a Java primitive, like int or boolean

public static String

Returns:

The Java-language-style type name
readableClassName
(Class<T>
The String that contains the JVM type name
clazz
)

Translate a JVM-style type descriptor to a Java-language-style type name.

private Member

Returns:

the matched method
resolveMethod
(Class<T>
the class who holds the methods
receiverClass
,
String
the name of method
methodName
,
Class<T>[]
object type classes of input parameters
paramClasses
,
Class<T>[]
primitive type classes or null
primParamClasses
,
boolean[]
isParam (for ?) array
isParam
,
boolean
static method or not
staticMethod
,
boolean repeatLastParameter, Member[]
method stack
methods
,
boolean hasVarargs)

Tricky function to resolve a method.

private boolean
signatureConvertableFromTo(Class<T>[]
from types' classes
fromTypes
,
Class<T>[]
primitive from types or null
primFromTypes
,
Class<T>[]
to types' classes
toTypes
,
boolean[]
is parameter (?) or not
isParam
,
boolean
mixing object/primitive types for comparison
mixTypes
)

Can we convert a signature from fromTypes(primFromTypes) to toTypes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BIGDECIMAL_TYPE_NAMEback to summary
private static final String BIGDECIMAL_TYPE_NAME
cfback to summary
private final ClassFactory cf
nonPrimTypeNamesback to summary
private static final String[] nonPrimTypeNames
OBJECT_TYPE_NAMEback to summary
private static final String OBJECT_TYPE_NAME
primTypeNamesback to summary
private static final String[] primTypeNames
STRING_TYPE_NAMEback to summary
private static final String STRING_TYPE_NAME

Constructor Detail

ClassInspectorback to summary
public ClassInspector(ClassFactory cf)

DO NOT USE! use the method in ClassFactory.

Parameters
cf:ClassFactory

The class factory

Method Detail

accessibleback to summary
public boolean accessible(String className) throws ClassNotFoundException

Does the named class exist, and is it accessible?

Parameters
className:String

The name of the class to test for existence

Returns:boolean

true if the class exists and is accessible, false if not

Exceptions
ClassNotFoundException:
on error
addResolvedTypesback to summary
private void addResolvedTypes(HashMap<Type, Type> resolvedTypes, Type genericType)

Given a generic type, add its parameter types to an evolving map of resolved types. Some of the resolved types may be generic type variables which will need further resolution from other generic types.

assignableToback to summary
public boolean assignableTo(String fromClassName, String toClassName)

Is one named class assignable to another named class or interface?

Parameters
fromClassName:String

The name of the class to be assigned

toClassName:String

The name of the class to be assigned to

Returns:boolean

true if an object of type fromClass can be assigned to an object of type toClass, false if not.

boundTypeback to summary
private Class<T>[] boundType(Type type)

Get the bounds for a single type variable.

classConvertableFromToback to summary
protected boolean classConvertableFromTo(Class<T> fromClass, Class<T> toClass, boolean mixTypes)

Can we convert a fromClass to toClass. "mixTypes" is a flag to show if object/primitive type conversion is possible; this is used for comparing two candidate methods in the second pass of the two pass method resolution.

Parameters
fromClass:Class<T>

from class

toClass:Class<T>

to class

mixTypes:boolean

mixing object/primitive types for comparison

Returns:boolean

true if the conversion is possible

findPublicConstructorback to summary
public Member findPublicConstructor(String receiverType, String[] parmTypes, String[] primParmTypes, boolean[] isParam) throws ClassNotFoundException, StandardException

Find a public constructor that implements a given signature. The signature is given using the full Java class names of the types.
A untyped null parameter is indicated by passing in an empty string ("") as its class name.

Parameters
receiverType:String

The class name of the receiver

parmTypes:String[]

An array of class names representing the parameter types. Pass a zero-element array if there are no parameters.

primParmTypes:String[]

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 type

isParam:boolean[]

Array of booleans telling whether parameter is a ?.

Returns:Member

A Member representing the matching constructor. Returns null if no such constructor.

Exceptions
ClassNotFoundException:
One or more of the classes does not exist.
StandardException:
Thrown on ambiguous constructor invocation.
See Also
Member, Modifier
findPublicFieldback to summary
public Member findPublicField(String receiverType, String fieldName, boolean staticField) throws StandardException

Find a public field for a class. This follows the semantics of the java compiler for locating a field. This means if a field fieldName exists in the class with package, private or protected then an error is raised. Even if the field hides a field fieldName in a super-class/super--interface. See the JVM spec on fields.

Parameters
receiverType:String

The class name of the receiver

fieldName:String

The name of the field

staticField:boolean

Find a static field

Returns:Member

A Member representing the matching field.

Exceptions
StandardException:
Class or field does not exist or is not public or a security exception.
See Also
Member, Modifier
findPublicMethodback to summary
public Member findPublicMethod(String receiverType, String methodName, String[] parmTypes, String[] primParmTypes, boolean[] isParam, boolean staticMethod, boolean repeatLastParameter, boolean hasVarargs) throws ClassNotFoundException, StandardException

Find a public method that implements a given signature. The signature is given using the full Java class names of the types.
A untyped null parameter is indicated by passing in an empty string ("") as its class name.
If receiverType represents an interface then the methods of java.lang.Object are included in the candidate list.
If the caller is simply checking to see that a public method with the specified name exists, regardless of the signature, exists, then the caller should pass in a null for parmTypes. (This is useful for checking the validity of a method alias when creating one.)
We use a two-pass algorithm to resolve methods. In the first pass, we use all "object" types to try to match a method. If this fails, in the second pass, an array of "primitive" types (if the parameter has one, otherwise the same object type is used) is passed in, as well as the "object" type array. For each parameter of a method, we try to match it against either the "object" type, or the "primitive" type. Of all the qualified candidate methods found, we choose the closest one to the input parameter types. This involves comparing methods whose parameters are mixed "object" and "primitive" types in the second pass. This is eventually handled in classConvertableFromTo.

Parameters
receiverType:String

The class name of the receiver

methodName:String

The name of the method

parmTypes:String[]

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:String[]

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 type

isParam:boolean[]

Array of booleans telling whether parameter is a ?.

staticMethod:boolean

Find a static method.

repeatLastParameter:boolean

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.

hasVarargs:boolean

True if a varargs marker is expected

Returns:Member

A Member representing the matching method. Returns null if no such method.

Exceptions
ClassNotFoundException:
One or more of the classes does not exist.
StandardException:
Thrown on ambiguous method invocation.
See Also
Member, Modifier
findTypeBoundsback to summary
private Class<T>[][] findTypeBounds(ParameterizedType pt)

Get the type bounds for all of the type variables of the given parameterized type.

getClassback to summary
public Class<?> getClass(String className) throws ClassNotFoundException

Get (load) the class for the given class name. This method converts any java language class name into a Class object. This includes cases like String[] and primitive types. This will attempt to load the class from the application set.

Parameters
className:String

Name of class

Returns:Class<?>

the class

Exceptions
ClassNotFoundException:
Class cannot be found, or LinkageException was thrown loading the class.
getDeclaringClassback to summary
public String getDeclaringClass(Member method)

Get the declaring class for a method.

Parameters
method:Member

A Member describing a method

Returns:String

A String with the declaring class

See Also
Member#getDeclaringClass
getGenericParameterTypesback to summary
public Class<?>[] getGenericParameterTypes(Class<T> parameterizedType, Class<T> implementation) throws StandardException

Given an implementation of a parameterized interface, return the actual types of the interface type variables. May return null or an array of nulls if type resolution fails.

Parameters
parameterizedType:Class<T>

A parameterized type

implementation:Class<T>

An implementation of that type

Returns:Class<?>[]

the actual types of the interface type variables

Exceptions
StandardException:
on error
getParameterTypesback to summary
public String[] getParameterTypes(Member method)

Get the parameter types for a method described by a Member as a String[].

Parameters
method:Member

A Member describing a method

Returns:String[]

A String[] describing the parameters of the method

getParameterTypesback to summary
private ArrayList<Class<?>> getParameterTypes(Class<?> parameterizedType, HashMap<Type, 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.

getRawTypeback to summary
private Class<T> getRawType(Type bound)

Get the raw type of a type bound.

getResolvedTypesback to summary
private HashMap<Type, Type> getResolvedTypes(ArrayList<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.

getTypeback to summary
public String getType(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.

Parameters
member:Member

A Member representing the method for which we want the return type.

Returns:String

A Java-language-style string describing the return type of the method (for example, it returns "int" instead of "I".

getTypeBoundsback to summary
public Class<T>[][] getTypeBounds(Class<T> parameterizedInterface, Class<T> implementation) throws StandardException

Given an implementation of a parameterized interface, return the bounds on the type variables. May return null if type resolution fails.

Parameters
parameterizedInterface:Class<T>

A generic interface

implementation:Class<T>

An implementation of the interface

Returns:Class<T>[][]

the bounds on the type variable

Exceptions
StandardException:
on error
getTypeChainback to summary
private ArrayList<Class<?>> getTypeChain(Class<?> chainEnd, Class<?> start)

Construct an inheritance chain of types stretching from a supertype down to a concrete implementation.

instanceOfback to summary
public boolean instanceOf(String className, Object obj) throws ClassNotFoundException

Is the given object an instance of the named class?

Parameters
className:String

The name of the class

obj:Object

The object to test to see if it's an instance of the named class

Returns:boolean

true if obj is an instanceof className, false if not

Exceptions
ClassNotFoundException:
on error
isVarArgsMethodback to summary
public boolean isVarArgsMethod(Member member)

Return true if the method or constructor supports varargs.

Parameters
member:Member

A member method

Returns:boolean

true if it is a varargs method

primitiveTypeback to summary
public static boolean primitiveType(String typeName)

Determine whether a type is a Java primitive, like int or boolean

Parameters
typeName:String

The name of the Java type

Returns:boolean

true if it's a primitive type

readableClassNameback to summary
public static String readableClassName(Class<T> clazz)

Translate a JVM-style type descriptor to a Java-language-style type name.

Parameters
clazz:Class<T>

The String that contains the JVM type name

Returns:String

The Java-language-style type name

resolveMethodback to summary
private Member resolveMethod(Class<T> receiverClass, String methodName, Class<T>[] paramClasses, Class<T>[] primParamClasses, boolean[] isParam, boolean staticMethod, boolean repeatLastParameter, Member[] methods, boolean hasVarargs) throws StandardException

Tricky function to resolve a method. If primParamClasses is null we know it's first pass. First pass try to match as all "object" types, second pass try to match any combination of "object" and "primitive" types. Find the closest match among all the qualified candidates. If there's a tie, it's ambiguous. The preceding paragraph is a bit misleading. As of release 10.4, the second pass did not consider arbitrary combinations of primitive and wrapper types. This is because the first pass removed from consideration candidates which would be allowed under ANSI rules. As a fix for bug DERBY-3652, we now allow primitive and wrapper type matches during the first pass. The ANSI rules are documented in DERBY-3652.

Parameters
receiverClass:Class<T>

the class who holds the methods

methodName:String

the name of method

paramClasses:Class<T>[]

object type classes of input parameters

primParamClasses:Class<T>[]

primitive type classes or null

isParam:boolean[]

isParam (for ?) array

staticMethod:boolean

static method or not

methods:Member[]

method stack

Returns:Member

the matched method

signatureConvertableFromToback to summary
private boolean signatureConvertableFromTo(Class<T>[] fromTypes, Class<T>[] primFromTypes, Class<T>[] toTypes, boolean[] isParam, boolean mixTypes)

Can we convert a signature from fromTypes(primFromTypes) to toTypes. "mixTypes" is a flag to show if object/primitive type conversion is possible; this is used for comparing two candidate methods in the second pass of the two pass method resolution.

Parameters
fromTypes:Class<T>[]

from types' classes

primFromTypes:Class<T>[]

primitive from types or null

toTypes:Class<T>[]

to types' classes

isParam:boolean[]

is parameter (?) or not

mixTypes:boolean

mixing object/primitive types for comparison