codesimian
Class InvokeMethod

java.lang.Object
  extended by codesimian.CS<CSGeneric>
      extended by codesimian.DefaultCS
          extended by codesimian.InvokeMethod
All Implemented Interfaces:
CodeSimian

public class InvokeMethod
extends DefaultCS

THIS CLASS IS BEING REPLACED BY JavaFunctionSimple. Invokes (calls) a Java Method instance. Use someObject.getClass().getMethod("methodName") to get a Method for InvokeMethod to invoke.


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, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
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 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.
 
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, setPType, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addP, addS, addZ, BForProxy, CForProxy, clone, D, deleteP, FForProxy, GETB, GETC, GETD, GETF, GETI, GETJ, GETL, GETS, GETZ, IForProxy, isIllusion, 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, reflect6, setB, SETB, setC, SETC, setCost, SETD, setDescription, setF, SETF, setHeap, setI, SETI, setJ, SETJ, SETL, setL, setL, setParent, setParsePriority, setProxyOf, setS, SETS, setTester, setZ, SETZ, SForProxy, tester, toJavaCode, 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()

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

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