codesimian
Class InvokeMethod

java.lang.Object
  extended by codesimian.CS
      extended by codesimian.DefaultCS
          extended by codesimian.InvokeMethod
All Implemented Interfaces:
CodeSimian, java.io.Serializable

public class InvokeMethod
extends DefaultCS

Invokes (calls) a Java Method instance. Use someObject.getClass().getMethod("methodName") to get a Method for InvokeMethod to invoke.

See Also:
Serialized Form

Field Summary
 java.lang.Object invokeOnThisObject
          Leave null for static Method
 java.lang.reflect.Method method
          A Method that is dynamicly invoked in DForProxy().
 java.lang.Object[] methodParams
          Parameters for 'method'.
 java.lang.Class[] paramType
           
 boolean[] replace
          For each parameter of 'method', before each invoke(), true if the CS in param[] with the same index should create an Object like Boolean, Integer, etc and replace the Object in methodParams[] with it.
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, FUEL, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER
 
Constructor Summary
InvokeMethod()
          sets the method to System.out.println() to print an error, if you dont replace it
InvokeMethod(java.lang.reflect.Method method, java.lang.Object invokeOnThisObject, java.lang.Object[] methodParams, boolean[] replace)
           
 
Method Summary
 InvokeMethod[] allPublicMethodsForObject(java.lang.Object myMethods)
          Wraps all the Method's of 'myMethods' in InvokeMethod objects
 double chanceOfError()
          Returns 0.5 because dynamicly calling external functions, with unknown inputs, is dangerous.
 double cost()
          cost() should be changed to return a float, and should be renamed to costToExecute()

cost of EXECUTING this CS, not including any CSs it executes recursively.
 double DForProxy()
          Invokes a java Method with parameters methodParams[], after (optionally, if replace[x]) replacing some of methodParameters[] with CSs from param[] or Numbers with their DForProxy() values like "new Integer(CS.intValue())".


Tries to convert each param CS to types in this order: P(index).getObject() object, P(index) subclass of CS, primitive type int boolean etc.
 java.lang.String keyword()
          For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
 int minP()
          For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.
 boolean needMoreInfo()
          need the Method and its parameters
 boolean paramOrderMatters()
           
 boolean unknownCost()
          dont know cost of invoking 'method'
 
Methods inherited from class codesimian.DefaultCS
B, C, countP, decrementMyFuel, deleteP, description, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, javaCode, LForProxy, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, PType, S, setB, setC, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, setName, setObject, setP, setPrevExec, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addP, addP, addP, addP, addP, BForProxy, CForProxy, clone, D, deleteP, FForProxy, IForProxy, isIllusion, javaCode, JForProxy, L, L, L, L, L, maxD, maxP, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, setB, setC, setCost, setDescription, setF, setHeap, setI, setJ, setL, setL, setParent, setParsePriority, setProxyOf, setPType, setS, setTester, setZ, SForProxy, tester, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

method

public java.lang.reflect.Method method
A Method that is dynamicly invoked in DForProxy().


invokeOnThisObject

public java.lang.Object invokeOnThisObject
Leave null for static Method


methodParams

public java.lang.Object[] methodParams
Parameters for 'method'. Primitive types are derived from the CSs in param[] before each invoke(). Can be null or Objects, even Objects like Boolean, Integer, etc that are unwrapped during invoke().


paramType

public java.lang.Class[] paramType

replace

public boolean[] replace
For each parameter of 'method', before each invoke(), true if the CS in param[] with the same index should create an Object like Boolean, Integer, etc and replace the Object in methodParams[] with it.

Constructor Detail

InvokeMethod

public InvokeMethod()
sets the method to System.out.println() to print an error, if you dont replace it


InvokeMethod

public InvokeMethod(java.lang.reflect.Method method,
                    java.lang.Object invokeOnThisObject,
                    java.lang.Object[] methodParams,
                    boolean[] replace)
Parameters:
replace[] - true if that index in methodParams[] should be set to a Double, Boolean, CS (copy directly from param[]), Character, etc (convert the value of CS.D()) before method.invoke(invokeOnThisObject, methodParams) is called in DForProxy().
Method Detail

minP

public int minP()
Description copied from class: DefaultCS
For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.

Overrides:
minP in class DefaultCS

keyword

public java.lang.String keyword()
Description copied from class: DefaultCS
For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

For example, CS.MaxParams does not override keyword(), which returns "maxP".

Overrides:
keyword in class DefaultCS
See Also:
CS.parent(), CS.newInstance(), CS.name()

needMoreInfo

public boolean needMoreInfo()
need the Method and its parameters


paramOrderMatters

public boolean paramOrderMatters()

unknownCost

public boolean unknownCost()
dont know cost of invoking 'method'


cost

public double cost()
Description copied from class: CS
cost() should be changed to return a float, and should be renamed to costToExecute()

cost of EXECUTING this CS, not including any CSs it executes recursively. The INTERNAL cost.

One unit of myFuel() costs cost() units of fuel(). Beware of CSs that counterfeit fuel.

Returns 1 by default.

Overrides:
cost in class CS

chanceOfError

public double chanceOfError()
Returns 0.5 because dynamicly calling external functions, with unknown inputs, is dangerous.


DForProxy

public double DForProxy()
Invokes a java Method with parameters methodParams[], after (optionally, if replace[x]) replacing some of methodParameters[] with CSs from param[] or Numbers with their DForProxy() values like "new Integer(CS.intValue())".


Tries to convert each param CS to types in this order: P(index).getObject() object, P(index) subclass of CS, primitive type int boolean etc. If the params of this InvokeMethod can be converted, and boolean replace[] says to, converts params to these types and calls my java function dynamicly.

Method must be a public function in a public class, or DForProxy() will return NaN because of a Method access Exception.
Returns Double.NaN if there is an Exception.
If there is no Exception, and method's returned Object can be cast to Number, returns Number.doubleValue().
If it cant be cast to Number, but 'method' returns ok, returns 1.0.

Specified by:
DForProxy in class DefaultCS

allPublicMethodsForObject

public InvokeMethod[] allPublicMethodsForObject(java.lang.Object myMethods)
Wraps all the Method's of 'myMethods' in InvokeMethod objects