ref_send API 2.17
defensive programming in Java

org.joe_e.reflect
Class Reflection

java.lang.Object
  extended by org.joe_e.reflect.Reflection

public final class Reflection
extends java.lang.Object

The reflection interface.

This API provides reflective access to all the public constructors, public fields and public methods of public Joe-E classes and interfaces. The API provides no more permission than is provided by static Joe-E program code. If you can do something with the reflection API, you could also have done it using static Joe-E code. The only difference is expressivity.


Method Summary
static void clearStackTrace(java.lang.Throwable e)
          Clears the stack trace on an exception.
static
<T> T
construct(java.lang.reflect.Constructor<T> ctor, java.lang.Object... args)
          Invokes a reflected constructor.
static
<T> java.lang.reflect.Constructor<T>
constructor(java.lang.Class<T> type, java.lang.Class<?>... args)
          Gets a public constructor.
static PowerlessArray<java.lang.reflect.Constructor<?>> constructors(java.lang.Class<?> type)
          Gets all declared public constructors.
static java.lang.reflect.Field field(java.lang.Class<?> type, java.lang.String name)
          Gets a public field.
static PowerlessArray<java.lang.reflect.Field> fields(java.lang.Class<?> type)
          Gets all public fields.
static java.lang.Object get(java.lang.reflect.Field field, java.lang.Object self)
          Gets the value of a field.
static java.lang.String getName(java.lang.Class<?> c)
          Get the name of the entity represented by a Class object, in the same format as returned by Class.getName().
static java.lang.Object invoke(java.lang.reflect.Method method, java.lang.Object self, java.lang.Object... args)
          Invokes a reflected method.
static java.lang.reflect.Method method(java.lang.Class<?> type, java.lang.String name, java.lang.Class<?>... args)
          Gets a public method.
static PowerlessArray<java.lang.reflect.Method> methods(java.lang.Class<?> type)
          Gets all public methods.
static void set(java.lang.reflect.Field field, java.lang.Object self, java.lang.Object value)
          Sets the value of a field.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

field

public static java.lang.reflect.Field field(java.lang.Class<?> type,
                                            java.lang.String name)
                                     throws java.lang.NoSuchFieldException
Gets a public field.

This method wraps Class.getField(java.lang.String).

Parameters:
type - class to search
name - field name
Returns:
described field
Throws:
java.lang.NoSuchFieldException - no matching field found

fields

public static PowerlessArray<java.lang.reflect.Field> fields(java.lang.Class<?> type)
Gets all public fields.

This method wraps Class.getFields().

Parameters:
type - object type
Returns:
described fields

constructor

public static <T> java.lang.reflect.Constructor<T> constructor(java.lang.Class<T> type,
                                                               java.lang.Class<?>... args)
                                                    throws java.lang.NoSuchMethodException
Gets a public constructor.

This method wraps Class.getConstructor(java.lang.Class...).

Parameters:
type - class to search
args - each parameter type
Returns:
described constructor
Throws:
java.lang.NoSuchMethodException - no matching constructor found

constructors

public static PowerlessArray<java.lang.reflect.Constructor<?>> constructors(java.lang.Class<?> type)
Gets all declared public constructors.

This method wraps Class.getConstructors().

Parameters:
type - class to search
Returns:
all public constructors

method

public static java.lang.reflect.Method method(java.lang.Class<?> type,
                                              java.lang.String name,
                                              java.lang.Class<?>... args)
                                       throws java.lang.NoSuchMethodException
Gets a public method.

This method wraps Class.getMethod(java.lang.String, java.lang.Class...).

Parameters:
type - class to search
name - method name
args - each parameter type
Returns:
described method
Throws:
java.lang.NoSuchMethodException - no matching method found

methods

public static PowerlessArray<java.lang.reflect.Method> methods(java.lang.Class<?> type)
Gets all public methods.

This method wraps Class.getMethods().

Parameters:
type - object type
Returns:
described methods

getName

public static java.lang.String getName(java.lang.Class<?> c)
Get the name of the entity represented by a Class object, in the same format as returned by Class.getName(). This wrapper exists to avoid exposing the number of proxy interfaces that have been generated.

Parameters:
c - the class to get the name of
Returns:
the name of class c
Throws:
java.lang.IllegalArgumentException - if c is a proxy class

clearStackTrace

public static void clearStackTrace(java.lang.Throwable e)
Clears the stack trace on an exception.

Parameters:
e - exception to modify

get

public static java.lang.Object get(java.lang.reflect.Field field,
                                   java.lang.Object self)
                            throws java.lang.IllegalAccessException
Gets the value of a field.

Parameters:
field - field to access
self - target object
Returns:
field value
Throws:
java.lang.IllegalAccessException - field is inaccessible

set

public static void set(java.lang.reflect.Field field,
                       java.lang.Object self,
                       java.lang.Object value)
                throws java.lang.IllegalAccessException
Sets the value of a field.

Parameters:
field - field to access
self - target object
value - new value
Throws:
java.lang.IllegalAccessException - field is inaccessible

construct

public static <T> T construct(java.lang.reflect.Constructor<T> ctor,
                              java.lang.Object... args)
                   throws java.lang.Exception
Invokes a reflected constructor.

Parameters:
ctor - constructor to invoke
args - each argument
Returns:
constructed object
Throws:
java.lang.IllegalAccessException - ctor is inaccessible
java.lang.ClassCastException - ctor.newInstance() throws an IllegalArgumentException, usually due to mismatched types
java.lang.Exception - an exception thrown by the invoked constructor

invoke

public static java.lang.Object invoke(java.lang.reflect.Method method,
                                      java.lang.Object self,
                                      java.lang.Object... args)
                               throws java.lang.Exception
Invokes a reflected method.

Parameters:
method - method to invoke
self - target object
args - each argument
Returns:
invocation return
Throws:
java.lang.IllegalAccessException - method is inaccessible
java.lang.ClassCastException - method.invoke() throws an IllegalArgumentException, usually due to mismatched types
java.lang.Exception - an exception thrown by the invoked method

ref_send API 2.17
defensive programming in Java

Submit a bug or feature, or get help

Copyright 1998-2009 Waterken Inc. under the terms of the MIT X license.