public class QuickMethodCall extends Object
You would use it like this:
QuickMethodCall q = QuickMethodCall.getFor(target, "addToPanel(Leve/ui/CellPanel;Leve/ui/data/Editor;I)V", false); if (q != null){ Wrapper[] p = q.parameters(); p[0].setObject(cp); p[1].setObject(ed); p[2].setInt(options); q.invoke(null); // Do not use q or p after this. }
Modifier and Type | Class and Description |
---|---|
static interface |
QuickMethodCall.InvokeStoppedHandler
This is used with the special call for invokeAsync and is used to dispose of
a returned value from the method call if the external Handle was stopped before
the value was available.
|
static class |
QuickMethodCall.QuickMethodCallCache
This class is used for quick access to a particular method for any Class.
|
static class |
QuickMethodCall.QuickMethodCallInvocationException |
Constructor and Description |
---|
QuickMethodCall()
Don't call this constructor directly.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Only call this if you do not call invoke()/newInstance() after calling getFor()
|
static Throwable |
checkExceptionCause(Throwable thrown,
Class lookForType)
After receiving a QuickMethodCalInvocationException or any other Exception you can call
this to get the cause of the Exception as a particular type, so that you can throw it.
|
static QuickMethodCall |
getConstructorFor(Class objectClass,
Class[] parameterTypes) |
static QuickMethodCall |
getConstructorFor(Class objectClass,
String parameters) |
static QuickMethodCall |
getConstructorFor(Constructor c) |
static QuickMethodCall |
getFor(Object target,
Method m) |
static QuickMethodCall |
getFor(Object objectOrClass,
String nameAndParametersAndReturnType,
boolean declaredOnly)
Get a QuickMethodCall for a method.
|
static QuickMethodCall |
getFor(Object objectOrClass,
String name,
Class[] parameterTypes,
boolean declaredOnly)
Get a QuickMethodCall for a method.
|
static QuickMethodCall |
getFor(Object objectOrClass,
String name,
Class[] parameterTypes,
Object[] parameters,
boolean declaredOnly)
Get a QuickMethodCall for a method and set the parameters at the same time.
|
Member |
getMethodOrConstructor()
Get the method or constructor that will be invoked.
|
Wrapper |
invoke()
After this method is called the QuickMethodCall is returned to the Cache and should not be used again.
|
boolean |
invoke(Wrapper dest)
After this method is called the QuickMethodCall is returned to the Cache and should not be used again.
|
Handle |
invokeAsync()
Invoke the method in a separate Thread and return a Handle that can be used to monitor and possibly
stop the method.
|
Handle |
invokeAsync(boolean dontStart)
Invoke the method in a separate Thread and return a Handle that can be used to monitor and possibly
stop the method.
|
Object |
invokeAsync(String doing,
QuickMethodCall.InvokeStoppedHandler sh)
This calls invokeAsync() and waits indefinitely for the return value.
|
void |
invokeFull(Wrapper dest)
After this method is called the QuickMethodCall is returned to the Cache and should not be used again.
|
Object |
newInstance()
After this method is called the QuickMethodCall is returned to the Cache and should not be used again.
|
Wrapper[] |
parameters()
Get the parameters Wrappers which you can set.
|
QuickMethodCall |
setAllowExceptions(boolean allow)
Normally the QuickMethodCall class will not throw Exceptions from the invoke() or
newInstance() methods.
|
QuickMethodCall |
setParameters(Object[] parameters)
Set the parameters as an array of standard Java wrappers.
|
QuickMethodCall |
setTarget(Object target) |
static RuntimeException |
throwAsRuntimeException(Throwable thrown)
After checking for known types using checkExceptionCause() use this line:
throw QuickMethodCall.throwAsRuntimeException(thrown); to throw the exception cause as a RuntimeException
or an Error.
|
String |
toString()
Return a String representation of this object.
|
public QuickMethodCall()
public static Throwable checkExceptionCause(Throwable thrown, Class lookForType)
thrown
- the Throwable thrown by invokeAsync().lookForType
- the non-null Throwable type to return if the cause is of this type.public static RuntimeException throwAsRuntimeException(Throwable thrown) throws Error, RuntimeException
throw QuickMethodCall.throwAsRuntimeException(thrown); to throw the exception cause as a RuntimeException or an Error.
thrown
- the Throwable thrown by invokeAsync().Error
RuntimeException
public QuickMethodCall setAllowExceptions(boolean allow)
allow
- true to allow exceptions to be thrown, false if not.public Member getMethodOrConstructor()
public Wrapper[] parameters()
public void invokeFull(Wrapper dest) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
dest
- a destination Wrapper. This can be null if you are not interested in the result.IllegalArgumentException
IllegalAccessException
InvocationTargetException
public boolean invoke(Wrapper dest)
dest
- a destination Wrapper to hold the result. This can be null if you are not interested in the result.public Wrapper invoke()
public Object newInstance()
public void cancel()
public static QuickMethodCall getConstructorFor(Class objectClass, String parameters)
public static QuickMethodCall getConstructorFor(Class objectClass, Class[] parameterTypes)
public static QuickMethodCall getFor(Object objectOrClass, String nameAndParametersAndReturnType, boolean declaredOnly)
objectOrClass
- for a static method this should be the Class of the method, for an instance method
it should be the Object the method is invoked on.nameAndParametersAndReturnType
- the Java encoded name, parameters and return type of the method. If
no "(" is used, and only the method name is given then any method matching the name will be used.declaredOnly
- true if only a declared method is to be found and used.public static QuickMethodCall getFor(Object objectOrClass, String name, Class[] parameterTypes, boolean declaredOnly)
objectOrClass
- for a static method this should be the Class of the method, for an instance method
it should be the Object the method is invoked on.name
- the name of the method.parameterTypes
- the list of parameter types. This can be null for no parameters.declaredOnly
- true if only a declared method is to be found and used.public static QuickMethodCall getFor(Object objectOrClass, String name, Class[] parameterTypes, Object[] parameters, boolean declaredOnly)
objectOrClass
- for a static method this should be the Class of the method, for an instance method
it should be the Object the method is invoked on.name
- the name of the method.parameterTypes
- the list of parameter types. This can be null for no parameters.parameters
- the list of parameters as standard Java wrappers. This can be null for no parameters.declaredOnly
- true if only a declared method is to be found and used.public static QuickMethodCall getConstructorFor(Constructor c)
public static QuickMethodCall getFor(Object target, Method m)
public QuickMethodCall setTarget(Object target)
public QuickMethodCall setParameters(Object[] parameters)
parameters
- the parameters as an array of standard Java wrappers.public String toString()
Object
public Object invokeAsync(String doing, QuickMethodCall.InvokeStoppedHandler sh) throws QuickMethodCall.QuickMethodCallInvocationException, StoppedException
doing
- a message to indicate what the method will be doing.sh
- an InvokeStoppedHandler used to dispose of a return value if the invocation is stopped either
from the external handle or the invokeAsync() handle.QuickMethodCall.QuickMethodCallInvocationException
- if the method threw an exception that was not a StoppedException.StoppedException
- if the invocation was stopped by the mainHandle or by the invokeAsync handle.public final Handle invokeAsync()
public Handle invokeAsync(boolean dontStart)
dontStart
- if this is true then you must call start() on the returned Handle in order for the
invocation to actually execute.