|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object junitx.ddtunit.util.ClassAnalyser
public class ClassAnalyser
This example is taken from Thinking in Java secd. ed. (p.680f) This class used reflection to show all the methods of a class, even if the methods are defined in the base class.
Field Summary | |
---|---|
static String |
CLASS_CONSTRUCTOR
Constant to define constructor select in method findMethodByParams(String, String, Class[]) |
Method Summary | |
---|---|
static String |
classPackage(Class<?> clazz)
Extract package from class |
static String |
classPackage(Object obj)
Extract package from object instance |
static Object |
createPrimitiveArray(Object value)
Convert an array of object to its primitive counterpart. |
static Method |
findMethodByName(String qualifiedClassName,
String methodName)
Display all methods of class quaifiedClassName to the configured appender specified by Log4j |
static Object |
findMethodByParams(String className,
String methodName,
Class[] args)
Find a Constructor/Method of class className by using the argument list args and try to vary arguments which could be of primitive type. |
static String[] |
getAllMethods(String qualifiedClassName)
Put all method names of the class qualifiedClassName into a String array and return it. |
static Class |
getPrimitiveArrayBaseType(Class clazz)
|
static Class |
getPrimitiveClass(Class checkClass)
Retrieve primitove type of specified clazz |
static Field |
getSelectedField(String qualifiedClassName,
String searchTerm)
Search for exact match of searchTerm in the list of declared fields of the class qualifiedClassName. |
static String |
getShortName(Class className)
Extract simple class name without package information |
static String |
getShortName(Object obj)
Extract simple class name without package information |
static String |
getShortName(String className)
Extract simple class name without package information |
static Set |
getSuperElements(Class clazz)
|
static boolean |
hasPrimitive(Class checkClass)
Verify if provided clazz has primitive type |
static void |
main(String[] args)
The main program for the ShowMethods class |
static void |
showAllFields(String qualifiedClassName)
Display all attributes/fields of class quaifiedClassName to the configured appender specified by Log4j |
static void |
showAllMethods(String qualifiedClassName)
Display all methods of class quaifiedClassName to the configured appender specified by Log4j |
static void |
showSelectedFields(String qualifiedClassName,
String searchTerm)
Display all attributes/fields of class quaifiedClassName matching searchTerm to the configured appender specified by Log4j |
static void |
showSelectedMethods(String qualifiedClassName,
String searchTerm)
Display all constructors and methods of qualifiedClassName class which match with searchTerm. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CLASS_CONSTRUCTOR
findMethodByParams(String, String, Class[])
Method Detail |
---|
public static void main(String[] args)
args
- The command line argumentspublic static String getShortName(Object obj)
obj
- object to analyse
public static String getShortName(Class className)
className
- to analyse
public static String getShortName(String className)
className
- qualified class name to analyse
public static void showAllFields(String qualifiedClassName)
qualifiedClassName
- name of class under analysis
RuntimeException
- ClassAnalyserException if an error occurespublic static void showSelectedFields(String qualifiedClassName, String searchTerm)
qualifiedClassName
- name of class under analysissearchTerm
- match string to check against
RuntimeException
- ClassAnalyserException if an error occurespublic static Field getSelectedField(String qualifiedClassName, String searchTerm)
qualifiedClassName
- Description of the ParametersearchTerm
- Description of the Parameter
RuntimeException
- ClassAnalyserException if an error occurespublic static void showAllMethods(String qualifiedClassName)
qualifiedClassName
- name of class under analysis
RuntimeException
- ClassAnalyserException if an error occurespublic static String[] getAllMethods(String qualifiedClassName)
qualifiedClassName
- Description of the Parameter
RuntimeException
- ClassAnalyserException if an error occurespublic static void showSelectedMethods(String qualifiedClassName, String searchTerm)
qualifiedClassName
- Name of class to analysesearchTerm
- Match term for methods to display
RuntimeException
- ClassAnalyserException if an error occurespublic static Object findMethodByParams(String className, String methodName, Class[] args)
className
- methodName
- args
-
public static Method findMethodByName(String qualifiedClassName, String methodName)
qualifiedClassName
- name of class under analysismethodName
- to search for
RuntimeException
- ClassAnalyserException if an error occurespublic static Set getSuperElements(Class clazz)
public static Class getPrimitiveClass(Class checkClass)
checkClass
- to retrieve associated primitive type from
public static Object createPrimitiveArray(Object value)
value
- - array of Object to convert
public static Class getPrimitiveArrayBaseType(Class clazz)
clazz
-
public static boolean hasPrimitive(Class checkClass)
checkClass
- to look for associated primitive type
public static String classPackage(Object obj)
public static String classPackage(Class<?> clazz)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |