joptsimple.internal
Class Reflection

java.lang.Object
  extended by joptsimple.internal.Reflection

public abstract class Reflection
extends java.lang.Object

Helper methods for reflection.

Version:
$Id: Reflection.java,v 1.17 2009/04/04 01:24:27 pholser Exp $
Author:
Paul Holser

Constructor Summary
Reflection()
           
 
Method Summary
private static
<V> ValueConverter<V>
constructorConverter(java.lang.Class<V> clazz)
           
static
<V> ValueConverter<V>
findConverter(java.lang.Class<V> clazz)
          Finds an appropriate value converter for the given class.
static
<T> T
instantiate(java.lang.reflect.Constructor<T> constructor, java.lang.Object... args)
          Invokes the given constructor with the given arguments.
static java.lang.Object invoke(java.lang.reflect.Method method, java.lang.Object... args)
          Invokes the given static method with the given arguments.
private static boolean meetsConverterRequirements(java.lang.reflect.Method method, java.lang.Class<?> expectedReturnType)
           
private static java.lang.RuntimeException reflectionException(java.lang.Exception ex)
           
private static
<V> ValueConverter<V>
valueOfConverter(java.lang.Class<V> clazz)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflection

public Reflection()
Method Detail

findConverter

public static <V> ValueConverter<V> findConverter(java.lang.Class<V> clazz)
Finds an appropriate value converter for the given class.

Type Parameters:
V - a constraint on the class object to introspect
Parameters:
clazz - class to introspect on
Returns:
a converter method or constructor

valueOfConverter

private static <V> ValueConverter<V> valueOfConverter(java.lang.Class<V> clazz)

constructorConverter

private static <V> ValueConverter<V> constructorConverter(java.lang.Class<V> clazz)

instantiate

public static <T> T instantiate(java.lang.reflect.Constructor<T> constructor,
                                java.lang.Object... args)
Invokes the given constructor with the given arguments.

Type Parameters:
T - constraint on the type of the objects yielded by the constructor
Parameters:
constructor - constructor to invoke
args - arguments to hand to the constructor
Returns:
the result of invoking the constructor
Throws:
ReflectionException - in lieu of the gaggle of reflection-related exceptions

invoke

public static java.lang.Object invoke(java.lang.reflect.Method method,
                                      java.lang.Object... args)
Invokes the given static method with the given arguments.

Parameters:
method - method to invoke
args - arguments to hand to the method
Returns:
the result of invoking the method
Throws:
ReflectionException - in lieu of the gaggle of reflection-related exceptions

meetsConverterRequirements

private static boolean meetsConverterRequirements(java.lang.reflect.Method method,
                                                  java.lang.Class<?> expectedReturnType)

reflectionException

private static java.lang.RuntimeException reflectionException(java.lang.Exception ex)