randoop.util
Class Reflection

Object
  extended by Reflection

public final class Reflection
extends Object

Utility methods that operate on reflection objects (classes, methods, etc.).


Nested Class Summary
Modifier and Type Class and Description
static class Reflection.Match
          Used by methods that that a java.lang.Class object as argument and use it to compute something based on it.
 
Field Summary
Modifier and Type Field and Description
static long num_times_canBeUsedAs_called
           
static Comparator<Member> SORT_MEMBERS_BY_NAME
           
 
Method Summary
Modifier and Type Method and Description
static boolean canBePassedAsArgument(Object inputObject, Class<?> parameterType)
          Returns whether the input can be used as argument for the specified parameter type.
static boolean canBeUsedAs(Class<?> c1, Class<?> c2)
          Checks if an object of class c1 can be used as an object of class c2.
static String checkArgumentTypes(Object[] inputs, Class<?>[] paramTypes, Object errMsgContext)
          Checks whether the inputs can be used as arguments for the specified parameter types.
static ArrayList<Class<?>> classesForNames(ArrayList<String> l)
           
static Class<?> classForName(String classname)
          Gets the class corresponding to the given string.
static Class<?> classForName(String classname, boolean noerr)
          Gets the class corresponding to the given string.
static String getCompilableName(Class<?> cls)
          Returns a name that can be used in Java source for the given class.
static Constructor<?> getConstructorForSignature(String s)
           
static Constructor<?>[] getConstructorsOrdered(Class<?> c)
          Like Class.getConstructors(), but guarantees always same order.
static Constructor<?>[] getDeclaredConstructorsOrdered(Class<?> c)
          Like Class.getDeclaredConstructors(), but guarantees always same order.
static Method[] getDeclaredMethodsOrdered(Class<?> c)
          Like Class.getDeclaredMethods(), but guarantees always same order.
static Set<Class<?>> getDirectSuperTypes(Class<?> c)
           
static Method getMethodForSignature(String s)
           
static Method[] getMethodsOrdered(Class<?> c)
          Like Class.getMethods(), but guarantees always same order.
static ArrayList<String> getNamesForClasses(ArrayList<Class<?>> cl)
          To deserialize a list serialized with this method, use the method deserializeClassList.
static String getSignature(Constructor<?> c)
           
static String getSignature(Method m)
           
static List<StatementKind> getStatements(Collection<Class<?>> classListing, ReflectionFilter filter)
           
static boolean isAbstract(Class<?> c)
           
static boolean isVisible(Class<?> c)
           
static boolean isVisible(int modifiers)
          Returns true if the the specified modifier is visible to Randoop.
static List<Class<?>> loadClassesFromFile(File classListingFile)
          Blank lines and lines starting with "#" are ignored.
static List<Class<?>> loadClassesFromFile(File classListingFile, boolean noerr)
          Blank lines and lines starting with "#" are ignored.
static List<Class<?>> loadClassesFromList(List<String> classNames, boolean noerr)
          Returns a list of classes, given a list of class names.
static List<Class<?>> loadClassesFromReader(BufferedReader reader, String filename)
          Blank lines and lines starting with "#" are ignored.
static List<Class<?>> loadClassesFromReader(BufferedReader reader, String filename, boolean noerr)
          Blank lines and lines starting with "#" are ignored.
static List<Class<?>> loadClassesFromStream(InputStream in, String filename)
          Blank lines and lines starting with "#" are ignored.
static List<Member> loadMethodsAndCtorsFromFile(File classListingFile)
          Blank lines and lines starting with "#" are ignored.
static List<Member> loadMethodsAndCtorsFromLines(List<String> lines)
          Blank lines and lines starting with "#" are ignored.
static List<Member> loadMethodsAndCtorsFromReader(BufferedReader reader)
          Blank lines and lines starting with "#" are ignored.
static List<Member> loadMethodsAndCtorsFromStream(InputStream in)
          Blank lines and lines starting with "#" are ignored.
static Set<Class<?>> relatedClasses(Class<?> clazz, int depth)
          Returns the set of classes that appear, recursively, in the interface of the given class, to a given depth.
static Set<Class<?>> relatedClasses(Collection<Class<?>> classes, int i)
           
static void saveClassesToFile(List<Class<?>> classes, String file)
           
static Method super_get_declared_method(Class<?> c, String methodname, Class<?>... parameter_types)
          Looks for the specified method name in the specified class and all of its superclasses
static StackTraceElement throwPointForName(String s)
           
static String throwPointToString(StackTraceElement throwPoint)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SORT_MEMBERS_BY_NAME

public static final Comparator<Member> SORT_MEMBERS_BY_NAME

num_times_canBeUsedAs_called

public static long num_times_canBeUsedAs_called
Method Detail

relatedClasses

public static Set<Class<?>> relatedClasses(Class<?> clazz,
                                           int depth)
Returns the set of classes that appear, recursively, in the interface of the given class, to a given depth. For example, if class C1 declares only method foo(C2)/C3, and class C2 declares method bar(C4)/C5, then: We say that C1, C2 and C3 are related to C1 at depth >= 0. We say that C4 and C5 are related to C1 at depth >= 1. We say that a class C2 appears in the interface of C iff: (1) C2 is C (2) C2 is a return value of some method in C.getMethods() (2) C2 is a parameter of some method in C.getMethods() or some constructor in C.getConstructors().


relatedClasses

public static Set<Class<?>> relatedClasses(Collection<Class<?>> classes,
                                           int i)

getMethodsOrdered

public static Method[] getMethodsOrdered(Class<?> c)
Like Class.getMethods(), but guarantees always same order.


getDeclaredMethodsOrdered

public static Method[] getDeclaredMethodsOrdered(Class<?> c)
Like Class.getDeclaredMethods(), but guarantees always same order.


getConstructorsOrdered

public static Constructor<?>[] getConstructorsOrdered(Class<?> c)
Like Class.getConstructors(), but guarantees always same order.


getDeclaredConstructorsOrdered

public static Constructor<?>[] getDeclaredConstructorsOrdered(Class<?> c)
Like Class.getDeclaredConstructors(), but guarantees always same order.


classForName

public static Class<?> classForName(String classname)
Gets the class corresponding to the given string. Assumes the string is in the format output by the method java.lang.Class.toString().


classForName

public static Class<?> classForName(String classname,
                                    boolean noerr)
Gets the class corresponding to the given string. Assumes the string is in the format output by the method java.lang.Class.toString(). If noerr==true and Class.forName(classname) throws an exception, throws an Error. If noerr==false and Class.forName(classname) throws an exception, returns null.


getDirectSuperTypes

public static Set<Class<?>> getDirectSuperTypes(Class<?> c)

canBeUsedAs

public static boolean canBeUsedAs(Class<?> c1,
                                  Class<?> c2)
Checks if an object of class c1 can be used as an object of class c2. This is more than subtyping: for example, int can be used as Integer, but the latter is not a subtype of the former.


checkArgumentTypes

public static String checkArgumentTypes(Object[] inputs,
                                        Class<?>[] paramTypes,
                                        Object errMsgContext)
Checks whether the inputs can be used as arguments for the specified parameter types. This method considers "null" as always being a valid argument. errMsgContext is uninterpreted - just printed in error messages Returns null if inputs are OK wrt paramTypes. Returns error message otherwise.


canBePassedAsArgument

public static boolean canBePassedAsArgument(Object inputObject,
                                            Class<?> parameterType)
Returns whether the input can be used as argument for the specified parameter type.


loadClassesFromList

public static List<Class<?>> loadClassesFromList(List<String> classNames,
                                                 boolean noerr)
Returns a list of classes, given a list of class names. if noerr=true, any classnames where Class.forName(classname) are ignored and not added to the list. Otherwise, an exception is thrown in this situation.


loadClassesFromStream

public static List<Class<?>> loadClassesFromStream(InputStream in,
                                                   String filename)
Blank lines and lines starting with "#" are ignored. Other lines must contain string such that Class.forName(s) returns a class.


loadClassesFromReader

public static List<Class<?>> loadClassesFromReader(BufferedReader reader,
                                                   String filename)
Blank lines and lines starting with "#" are ignored. Other lines must contain string such that Class.forName(s) returns a class.


loadClassesFromReader

public static List<Class<?>> loadClassesFromReader(BufferedReader reader,
                                                   String filename,
                                                   boolean noerr)
Blank lines and lines starting with "#" are ignored. Other lines must contain string such that Class.forName(s) returns a class.


loadClassesFromFile

public static List<Class<?>> loadClassesFromFile(File classListingFile)
                                          throws IOException
Blank lines and lines starting with "#" are ignored. Other lines must contain string such that Class.forName(s) returns a class.

Throws:
IOException

loadClassesFromFile

public static List<Class<?>> loadClassesFromFile(File classListingFile,
                                                 boolean noerr)
                                          throws IOException
Blank lines and lines starting with "#" are ignored. Other lines must contain string such that Class.forName(s) returns a class.

Throws:
IOException

loadMethodsAndCtorsFromStream

public static List<Member> loadMethodsAndCtorsFromStream(InputStream in)
Blank lines and lines starting with "#" are ignored. Other lines must contain string such that Class.forName(s) returns a class.


loadMethodsAndCtorsFromReader

public static List<Member> loadMethodsAndCtorsFromReader(BufferedReader reader)
Blank lines and lines starting with "#" are ignored. Other lines must contain string such that Class.forName(s) returns a class.


loadMethodsAndCtorsFromLines

public static List<Member> loadMethodsAndCtorsFromLines(List<String> lines)
Blank lines and lines starting with "#" are ignored. Other lines must contain string representing a method or constructor signature.


loadMethodsAndCtorsFromFile

public static List<Member> loadMethodsAndCtorsFromFile(File classListingFile)
                                                throws IOException
Blank lines and lines starting with "#" are ignored. Other lines must contain string such that Class.forName(s) returns a class.

Throws:
IOException

isVisible

public static boolean isVisible(Class<?> c)

isAbstract

public static boolean isAbstract(Class<?> c)

saveClassesToFile

public static void saveClassesToFile(List<Class<?>> classes,
                                     String file)
                              throws IOException
Throws:
IOException

getStatements

public static List<StatementKind> getStatements(Collection<Class<?>> classListing,
                                                ReflectionFilter filter)
Parameters:
classListing -
filter - can be null.

getNamesForClasses

public static ArrayList<String> getNamesForClasses(ArrayList<Class<?>> cl)
To deserialize a list serialized with this method, use the method deserializeClassList.

Throws:
IOException

classesForNames

public static ArrayList<Class<?>> classesForNames(ArrayList<String> l)

getSignature

public static String getSignature(Constructor<?> c)

getSignature

public static String getSignature(Method m)

getMethodForSignature

public static Method getMethodForSignature(String s)

getConstructorForSignature

public static Constructor<?> getConstructorForSignature(String s)

throwPointToString

public static String throwPointToString(StackTraceElement throwPoint)

throwPointForName

public static StackTraceElement throwPointForName(String s)

getCompilableName

public static String getCompilableName(Class<?> cls)
Returns a name that can be used in Java source for the given class.


super_get_declared_method

public static Method super_get_declared_method(Class<?> c,
                                               String methodname,
                                               Class<?>... parameter_types)
                                        throws Exception
Looks for the specified method name in the specified class and all of its superclasses

Throws:
Exception

isVisible

public static boolean isVisible(int modifiers)
Returns true if the the specified modifier is visible to Randoop.

See Also:
GenInputsAbstract.public_only