|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.uci.eecs.doc.cascade.util.ReflectionUtilities
public final class ReflectionUtilities
A collection of helper methods for Java reflection.
Method Summary | |
---|---|
static void |
clearCache()
FIXME: This is a quick fix for a problem that occurs when a class is analyzed by Volta, then modified and recompiled, and finally analyzed again (without exiting the VM in which Volta is running). |
static List<InstructionHandle> |
getBytecode(Method method)
Returns a list of the bytecode instructions for the given method. |
static Class |
getClassForName(String className,
List<String> classPath)
Returns a Class object corresponding to the given class name. |
static ClassInfo |
getClassInfo(Method method,
List<String> classPath)
Creates a JODE ClassInfo object corresponding to the given method. |
static ClassLoader |
getClassLoaderForClassPath(List<String> classPath)
Returns a ClassLoader that will only load classes only from a given class path. |
static Method |
getMethod(InvokeInstruction invokeInstruction,
Method caller,
List<String> classPath)
Returns a handle to the method invoked by the given invoke instruction. |
static Method |
getMethod(MethodInfo methodInfo,
ClassInfo classInfo)
Converts a JODE MethodInfo object to a standard Java method object. |
static Method |
getMethod(String name,
List<String> classPath)
Returns a Method object corresponding to the given method name. |
static MethodInfo |
getMethodInfo(Method method,
ClassInfo classInfo)
Converts a standard Java method object to a JODE MethodInfo object. |
static int |
getMethodSize(Method method)
Returns the size, in bytes, of the given method. |
static String |
getQualifiedName(Method method)
Returns a fully qualified human-readble name of the given method. |
static String |
getSignature(Class theClass)
Given a handle to a Java class, this method returns the class's signature. |
static int |
getSourceCodeLine(Method method,
String sourceCode)
Returns the line in the source code on which the given method was declared. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void clearCache()
public static String getSignature(Class theClass)
Ljava/lang/String; Z [Ljava/lang/Object; [[IThis differs from the standard
Class.getName()
method, which uses a
format that differs slightly from the usual Java signature syntax. Examples:
java.lang.String byte [Ljava.lang.Object; [[I
theClass
- a handle to a Java class
Class.getName()
public static String getQualifiedName(Method method)
java.lang.String.indexOf(java.lang.String,int)
method
- a handle to a Java method
public static Method getMethod(String name, List<String> classPath) throws NoSuchMethodException, ClassNotFoundException
name
- the fully qualified name of the method (e.g.,
java.lang.String.indexOf(java.lang.String,int)
)classPath
- a list of paths to use when searching for the method's class
NoSuchMethodException
- if the method cannot be found
ClassNotFoundException
- if the method's class cannot be foundpublic static Method getMethod(InvokeInstruction invokeInstruction, Method caller, List<String> classPath) throws NoSuchMethodException, ClassNotFoundException
invokeInstruction
- a BCEL instruction that invokes a methodcaller
- the method in which the invoke instruction is storedclassPath
- a list of paths to use when searching for the method
NoSuchMethodException
- if the method cannot be found
ClassNotFoundException
- if the method's class cannot be foundpublic static Class getClassForName(String className, List<String> classPath) throws ClassNotFoundException
Class.forName(String)
, but the search is restricted to a
custom class path instead of the system's default class path.
className
- the name of the class to load (e.g., java.lang.String
)classPath
- a list of paths to use when searching for the class
ClassNotFoundException
- if the class cannot be foundClass.forName(String)
public static ClassLoader getClassLoaderForClassPath(List<String> classPath) throws MalformedURLException
classPath
- a list of paths to which the ClassLoader should limit its search
MalformedURLException
- if at least one of the paths in the given path list is invalidpublic static ClassInfo getClassInfo(Method method, List<String> classPath)
method
- a handle to a Java methodclassPath
- a list of paths to use when searching for the method's class
public static MethodInfo getMethodInfo(Method method, ClassInfo classInfo) throws NoSuchMethodException
method
- a handle to a Java methodclassInfo
- a JODE ClassInfo object corresponding to the given method
NoSuchMethodException
public static Method getMethod(MethodInfo methodInfo, ClassInfo classInfo) throws NoSuchMethodException, ClassNotFoundException
methodInfo
- a JODE MethodInfo object
NoSuchMethodException
- if a method reference for the given MethodInfo
object could not be obtained
ClassNotFoundException
- if the method's class could not be foundpublic static int getMethodSize(Method method) throws ClassNotFoundException
ClassNotFoundException
- if the method's class could not be foundpublic static List<InstructionHandle> getBytecode(Method method) throws ClassNotFoundException
method
- a handle to the method
ClassNotFoundException
- if the method's class could not be foundpublic static int getSourceCodeLine(Method method, String sourceCode) throws ClassNotFoundException
LineNumberTable
attribute provides information
about source code line numbers, it only pertains to code within a method, not
the method declaration.)
The given method must have been compiled with debugging symbols turned on.
Note that this method will fail in some rare cases, such as when a statement
annotation is placed on the first statement of the method and has the
same name as the method.
method
- a handle to the methodsourceCode
- the source code in which the method was declared; must be
legal code (free of any compiler errors)
ClassNotFoundException
- if the class corresponding to the given method
cannot be found
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |