|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.eigenbase.util.ReflectUtil
public abstract class ReflectUtil
Static utilities for Java reflection.
| Field Summary | |
|---|---|
private static Map<Class,Class> |
primitiveToBoxingMap
|
private static Map<Class,Method> |
primitiveToByteBufferReadMethod
|
private static Map<Class,Method> |
primitiveToByteBufferWriteMethod
|
| Constructor Summary | |
|---|---|
ReflectUtil()
|
|
| Method Summary | ||
|---|---|---|
static
|
createDispatcher(Class<R> visitorBaseClazz,
Class<E> visiteeBaseClazz)
Creates a dispatcher for calls to lookupVisitMethod(java.lang.Class>, java.lang.Class>, java.lang.String). |
|
static Class |
getBoxingClass(Class primitiveClass)
Gets the Java boxing class for a primitive class. |
|
static Method |
getByteBufferReadMethod(Class clazz)
Uses reflection to find the correct java.nio.ByteBuffer "absolute get" method for a given primitive type. |
|
static Method |
getByteBufferWriteMethod(Class clazz)
Uses reflection to find the correct java.nio.ByteBuffer "absolute put" method for a given primitive type. |
|
static Class<?> |
getClassForName(String name)
Looks up a class by name. |
|
static String |
getUnmangledMethodName(Class declaringClass,
String methodName,
Class[] paramTypes)
Composes a string representing a human-readable method name (with neither exception nor return type information). |
|
static String |
getUnmangledMethodName(Method method)
Composes a string representing a human-readable method name (with neither exception nor return type information). |
|
static String |
getUnqualifiedClassName(Class c)
Gets the name of a class with no package qualifiers; if it's an inner class, it will still be qualified by the containing class (X$Y). |
|
static boolean |
invokeVisitor(ReflectiveVisitor visitor,
Object visitee,
Class hierarchyRoot,
String visitMethodName)
Implements the Glossary.VisitorPattern via reflection. |
|
private static boolean |
invokeVisitorInternal(Object visitor,
Object visitee,
Class hierarchyRoot,
String visitMethodName)
Shared implementation of the two forms of invokeVisitor. |
|
static Method |
lookupVisitMethod(Class<?> visitorClass,
Class<?> visiteeClass,
String visitMethodName)
Looks up a visit method. |
|
private static Method |
lookupVisitMethod(Class<?> visitorClass,
Class<?> visiteeClass,
String visitMethodName,
Class<?>[] paramTypes,
Map<Class<?>,Method> cache)
|
|
static Method |
lookupVisitMethod(Class<?> visitorClass,
Class<?> visiteeClass,
String visitMethodName,
List<Class> additionalParameterTypes)
Looks up a visit method taking additional parameters beyond the overloaded visitee type. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static Map<Class,Class> primitiveToBoxingMap
private static Map<Class,Method> primitiveToByteBufferReadMethod
private static Map<Class,Method> primitiveToByteBufferWriteMethod
| Constructor Detail |
|---|
public ReflectUtil()
| Method Detail |
|---|
public static Method getByteBufferReadMethod(Class clazz)
clazz - the Class object representing the primitive type
public static Method getByteBufferWriteMethod(Class clazz)
clazz - the Class object representing the primitive type
public static Class getBoxingClass(Class primitiveClass)
primitiveClass - representative class for primitive (e.g.
java.lang.Integer.TYPE)
public static String getUnqualifiedClassName(Class c)
c - the class of interest
public static String getUnmangledMethodName(Class declaringClass,
String methodName,
Class[] paramTypes)
declaringClass - class on which method is definedmethodName - simple name of method without signatureparamTypes - method parameter types
public static String getUnmangledMethodName(Method method)
method - method whose name is to be generated
public static boolean invokeVisitor(ReflectiveVisitor visitor,
Object visitee,
Class hierarchyRoot,
String visitMethodName)
Glossary.VisitorPattern via reflection. The basic
technique is taken from a
Javaworld article. For an example of how to use it, see ReflectVisitorTest. Visit method lookup follows the same rules as if
compile-time resolution for VisitorClass.visit(VisiteeClass) were
performed. An ambiguous match due to multiple interface inheritance
results in an IllegalArgumentException. A non-match is indicated by
returning false.
visitor - object whose visit method is to be invokedvisitee - object to be passed as a parameter to the visit methodhierarchyRoot - if non-null, visitor method will only be invoked if
it takes a parameter whose type is a subtype of hierarchyRootvisitMethodName - name of visit method, e.g. "visit"
private static boolean invokeVisitorInternal(Object visitor,
Object visitee,
Class hierarchyRoot,
String visitMethodName)
visitor - object whose visit method is to be invokedvisitee - object to be passed as a parameter to the visit methodhierarchyRoot - if non-null, visitor method will only be invoked if
it takes a parameter whose type is a subtype of hierarchyRootvisitMethodName - name of visit method, e.g. "visit"
public static Method lookupVisitMethod(Class<?> visitorClass,
Class<?> visiteeClass,
String visitMethodName)
visitorClass - class of object whose visit method is to be invokedvisiteeClass - class of object to be passed as a parameter to the
visit methodvisitMethodName - name of visit method
public static Method lookupVisitMethod(Class<?> visitorClass,
Class<?> visiteeClass,
String visitMethodName,
List<Class> additionalParameterTypes)
visitorClass - class of object whose visit method is to be invokedvisiteeClass - class of object to be passed as a parameter to the
visit methodvisitMethodName - name of visit methodadditionalParameterTypes - list of additional parameter types
createDispatcher(Class,Class)
private static Method lookupVisitMethod(Class<?> visitorClass,
Class<?> visiteeClass,
String visitMethodName,
Class<?>[] paramTypes,
Map<Class<?>,Method> cache)
public static <R extends ReflectiveVisitor,E> ReflectiveVisitDispatcher<R,E> createDispatcher(Class<R> visitorBaseClazz,
Class<E> visiteeBaseClazz)
lookupVisitMethod(java.lang.Class>, java.lang.Class>, java.lang.String). The
dispatcher caches methods between invocations.
visitorBaseClazz - Visitor base classvisiteeBaseClazz - Visitee base class
public static Class<?> getClassForName(String name)
throws Exception
name - fully-qualified name of class to look up
Exception
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||