ch.sahits.codegen.java.model.util
Class MethodReflector

java.lang.Object
  extended by ch.sahits.codegen.java.model.util.MethodReflector

public class MethodReflector
extends java.lang.Object

This is a Helper class for Reflecting on Methods of a class

Since:
1.2.0
Author:
Andi Hotz, Sahits GmbH

Constructor Summary
MethodReflector(java.lang.Class<? extends java.lang.Object> clazz)
          Initialize the class to reflect on
 
Method Summary
 java.util.List<java.lang.reflect.Method> getAbstractMethods()
          Retrieve a list of Abstract methods
 java.lang.String getAccessModifier(java.lang.reflect.Method m)
          Retrieve the access modifier and return its String representation
 java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Object>> getArguments(java.lang.reflect.Constructor<?> c)
          Retrieve a list of parameter type parameter names
 java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Object>> getArguments(java.lang.reflect.Method m)
          Retrieve a list of parameter type parameter names
 java.util.List<java.lang.reflect.Constructor<?>> getConstructor()
          Retrieve a list of constructors
 java.util.List<java.lang.String> getException(java.lang.reflect.Constructor<?> c)
          Retrieve a list of Exceptions of the method
 java.util.List<java.lang.String> getException(java.lang.reflect.Method m)
          Retrieve a list of Exceptions of the method
 java.lang.String getMethodName(java.lang.reflect.Method m)
          Retrieve the method name
 java.util.List<java.lang.reflect.Method> getPublicOrProtectedMethods()
          Retrieve all public or protected methods of the class
 java.lang.String getReturnType(java.lang.reflect.Method m)
          Retrieve the return Type of the method
 java.lang.String getReturnValue(java.lang.reflect.Method m)
          Retrieve the return value for the return type.
 boolean hasDefaultConstructor()
          Check whether the default constructor is defined.
 boolean hasMultipleConstructors()
          Check whether the class has defined multiple constructors
 java.util.List<java.lang.Class<? extends java.lang.Object>> neededImportsOfAbstractMethods()
          Retrieve a list of class names of non simple types that are needed for the abstract methods
 java.util.List<java.lang.Class<? extends java.lang.Object>> needeImportsOfNonPrivateMethods()
          Retrieve a list of class names of non simple types that are needed for all non private methods
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MethodReflector

public MethodReflector(java.lang.Class<? extends java.lang.Object> clazz)
Initialize the class to reflect on

Parameters:
clazz -
Method Detail

getPublicOrProtectedMethods

public java.util.List<java.lang.reflect.Method> getPublicOrProtectedMethods()
Retrieve all public or protected methods of the class

Returns:
List of methods

getAbstractMethods

public java.util.List<java.lang.reflect.Method> getAbstractMethods()
Retrieve a list of Abstract methods

Returns:
List of methods

getAccessModifier

public java.lang.String getAccessModifier(java.lang.reflect.Method m)
Retrieve the access modifier and return its String representation

Parameters:
m - Method
Returns:
Access modifier string representation

getReturnType

public java.lang.String getReturnType(java.lang.reflect.Method m)
Retrieve the return Type of the method

Parameters:
m - Method
Returns:
generic return Type

getMethodName

public java.lang.String getMethodName(java.lang.reflect.Method m)
Retrieve the method name

Parameters:
m - Method
Returns:
name of the method

getArguments

public java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Object>> getArguments(java.lang.reflect.Method m)
Retrieve a list of parameter type parameter names

Parameters:
m - Method
Returns:
List of Pairs containing the typ and name

getException

public java.util.List<java.lang.String> getException(java.lang.reflect.Method m)
Retrieve a list of Exceptions of the method

Parameters:
m - Method
Returns:
List of Strings defining the Exeption names

neededImportsOfAbstractMethods

public java.util.List<java.lang.Class<? extends java.lang.Object>> neededImportsOfAbstractMethods()
Retrieve a list of class names of non simple types that are needed for the abstract methods

Returns:
List of class names

needeImportsOfNonPrivateMethods

public java.util.List<java.lang.Class<? extends java.lang.Object>> needeImportsOfNonPrivateMethods()
Retrieve a list of class names of non simple types that are needed for all non private methods

Returns:
List of class names

hasMultipleConstructors

public boolean hasMultipleConstructors()
Check whether the class has defined multiple constructors

Returns:
true if more than one constructor is defined

hasDefaultConstructor

public boolean hasDefaultConstructor()
Check whether the default constructor is defined. The default constructor may be defined explicit or implicit if no other constructor is defined

Returns:
true if a default constructor is present

getConstructor

public java.util.List<java.lang.reflect.Constructor<?>> getConstructor()
Retrieve a list of constructors

Returns:
List of constructors

getArguments

public java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Object>> getArguments(java.lang.reflect.Constructor<?> c)
Retrieve a list of parameter type parameter names

Parameters:
c - Constructor
Returns:
List of Pairs containing the typ and name

getException

public java.util.List<java.lang.String> getException(java.lang.reflect.Constructor<?> c)
Retrieve a list of Exceptions of the method

Parameters:
c - Constructor
Returns:
List of Strings defining the Exeption names

getReturnValue

public java.lang.String getReturnValue(java.lang.reflect.Method m)
Retrieve the return value for the return type. If the return type is a primitive type get the return value or null if it is not a primitive type

Parameters:
m - Method for which the return value should be extracted
Returns:
return value for the return type.