codesimian
Class JavaFunctionSimple

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

public class JavaFunctionSimple
extends DefaultCS

Wrapper-class for a java.lang.reflect.Method, a dynamicly-called Java function. A Method can be found for any public Java function, and sometimes for protected functions. Example: JavaFunctionSimple.class.getMethods().

Param0 is always the returned value. Param1 is always the instance object to call the Method from. Param2 and above are the Method parameters. All CS params are CS.L(Class) to Java Objects or primitive-wrappers like java.lang.Boolean.

JavaFunctionSimple: param0 and param1 are required, even if Method does not use them. JavaMethod: param0 and param1 are usually optional, which confuses PType(int) as countP() changes.

WARNING: function overriding in subclasses does not work correctly. For example, method#codesimian.CS.javaCode(0 +(3 4 5) list) uses CS.javaCode(CS) instead of Add.javaCode(CS). SOLUTION: Change this class to update the java.lang.Method object by the class of JavaFunctionSimple.P(1), the instance object. Then for some reason it stopped having that error. ????????????


Field Summary
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
Constructor Summary
JavaFunctionSimple()
          default constructor used for testing, uses Method CS.countP()
JavaFunctionSimple(java.lang.reflect.Method m)
           
 
Method Summary
 java.lang.String description()
          a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for.
 double DForProxy()
          Execute this CS and cast to double.
static java.lang.reflect.Method findMethod(java.lang.Class c, java.lang.String methodName, java.lang.Class[] parameterTypes)
           
static java.lang.reflect.Method findMethod(java.lang.String methodPackageClassAndName)
           
 java.lang.Object getObject()
          Deprecated. 
static boolean isNumberType(java.lang.Class c)
          any primitive except void or boolean
 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()".
 java.lang.Object LForProxy(java.lang.Class castTo)
          the default implementation can use many Class parameters.
 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.
 CS PType(int indexP)
          There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1.
 boolean setName(java.lang.String newName)
          if the new name is a valid Method name (with Java package), like "java.lang.Object.equals".
 boolean setObject(java.lang.Object theMethod)
          Sets the main Object that this CS wraps.
 
Methods inherited from class codesimian.DefaultCS
B, C, countP, decrementMyFuel, deleteP, F, fuel, getExec, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, javaCode, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, S, setB, setC, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, 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, cost, 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
 

Constructor Detail

JavaFunctionSimple

public JavaFunctionSimple()
default constructor used for testing, uses Method CS.countP()


JavaFunctionSimple

public JavaFunctionSimple(java.lang.reflect.Method m)
Method Detail

DForProxy

public double DForProxy()
Description copied from class: CS
Execute this CS and cast to double.

D() and DForProxy() are the 2 most important functions in CS. They execute this CS. All other execute functions, by default, return DForProxy cast to their own type.

For example, J() calls the proxy which calls JForProxy() which calls DForProxy(). D() calls the proxy which calls DForProxy().

By default, all other primitive EXECUTE functions defer to D.
Functions that EXECUTE this CS: L(Class) L(int,Class,int) Z() B() C() S() I() J() F() D() V()

Specified by:
DForProxy in class DefaultCS

setName

public boolean setName(java.lang.String newName)
if the new name is a valid Method name (with Java package), like "java.lang.Object.equals". Unfortunately, overloaded functions (with the same name but different parameter types and/or quantities) all share the same name.

Overrides:
setName in class DefaultCS

findMethod

public static java.lang.reflect.Method findMethod(java.lang.String methodPackageClassAndName)

findMethod

public static java.lang.reflect.Method findMethod(java.lang.Class c,
                                                  java.lang.String methodName,
                                                  java.lang.Class[] parameterTypes)
                                           throws JavaReflectException
Throws:
JavaReflectException

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()

description

public java.lang.String description()
Description copied from class: CS
a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for. Example use: in automatically generated webpages for CodeSimian. Example: "returns sum of all params" for Add.

Overrides:
description in class DefaultCS

setObject

public boolean setObject(java.lang.Object theMethod)
Description copied from class: CS
Sets the main Object that this CS wraps. This function is deprecated and should be replaced with set setL(setTo)

Overrides:
setObject in class DefaultCS
See Also:
anyObject

getObject

@Deprecated
public java.lang.Object getObject()
Deprecated. 

Description copied from class: CS
Returns the main Object that this CS wraps (if one exists). This function is deprecated and should be replaced with L(Object.class), which uses getObject(). Then getObject() should be completely removed. L(Class) is more flexible.

Overrides:
getObject in class DefaultCS
See Also:
anyObject

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

PType

public CS PType(int indexP)
Description copied from class: CS
There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1. When a TYPE executes, it MEASURES THE TYPE OF its first param CS. It returns a positive number if it is that type, else 0 or negative. Some TYPEs use only 2 numbers, while others can return any number in a continuous range.

Types are optional. To not use types, return the default type: Static.defaultType(). The default type returns true for any CS. Most CSs do not need types therefore they use the default type.

Overrides:
PType in class DefaultCS

LForProxy

public java.lang.Object LForProxy(java.lang.Class castTo)
                           throws java.lang.ClassCastException
Description copied from class: DefaultCS
the default implementation can use many Class parameters. If you override but do not know what to return, return super.LForProxy(Class). All EXEC objects must override L(Class) the same way they override D(), reversed.

TODO: add ability to return List, or should I make every CS be a list?

Overrides:
LForProxy in class DefaultCS
Throws:
java.lang.ClassCastException
See Also:
execProxy(), setExecProxy(CS)

isNumberType

public static boolean isNumberType(java.lang.Class c)
any primitive except void or boolean