codesimian
Class JavaMethod2

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

public class JavaMethod2
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: JavaMethod2.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.

JavaMethod2: 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 JavaMethod2.P(1), the instance object. Then for some reason it stopped having that error. ????????????

See Also:
Serialized Form

Field Summary
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, FUEL, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER
 
Constructor Summary
JavaMethod2()
          default constructor used for testing, uses Method CS.countP()
JavaMethod2(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()
          D() and DForProxy() are the 2 most important functions in CS.
static java.lang.reflect.Method findMethod(java.lang.String methodName)
           
 java.lang.Object getObject()
          Returns the main Object that this CS wraps.
static boolean isNumberType(java.lang.Class c)
          any primitive except void or boolean
 java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
          this function could use a better algorithm, but for now try to get javaCode(CS) to work at all.
 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 L(java.lang.Class castTo)
          Optionally execute this CS, and definitely try to CAST it to the specified Java type.
 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, LForProxy, 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, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addP, addP, addP, addP, addP, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, IForProxy, isIllusion, javaCode, JForProxy, 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
 

Constructor Detail

JavaMethod2

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


JavaMethod2

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

DForProxy

public double DForProxy()
Description copied from class: CS
D() and DForProxy() are the 2 most important functions in CS. They execute this CS. All other execute functions, by default, use DForProxy instead of reinventing-the-wheel for their own type.

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

Execute this CS and cast to double. D() is the main EXECUTE function. D() uses DForProxy(). DForProxy() is the main action of every CS, the most important function. 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 methodName)

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

public java.lang.Object getObject()
Description copied from class: CS
Returns the main Object that this CS wraps. 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 on a continuous scale.

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

L

public java.lang.Object L(java.lang.Class castTo)
                   throws java.lang.ClassCastException
Description copied from class: CS
Optionally execute this CS, and definitely try to CAST it to the specified Java type. If fail, throw a ClassCastException.

Should I change this from throwing a CSCastException to return null instead?

It is preferred not to return CSs from this function. If you have a CS to return, the standard is to put it in param0... setP(0,returnValue), where the function caller should get the output from... P(0).

The functions: V L Z B C S I J F and D, usually EXECUTE this CS and CAST its value to the specified type.
L does not have to execute this CS, but all the others do. The other difference is L can throw a CSCastException (extends ClassCastException), which is a RuntimeException so you do not have to use try/catch if you trust it.

No pattern of L()'s behavior is guaranteed.
The L's of some some CSs are more predictable than others, often written about in javadoc.
If it casts correctly, it could fail later. If it fails many times, and you try again, it could still succeed.

Example: new int[7][6][5].getClass().getName() returns "[[[I". These 9 function names (not 10 because excludes Void) are also used by a very important part of Java (but not as function names): java.lang.Class.name() .

EXAMPLES:
JButton b = (JButton) new ButtonCS().L(Component.class); //JButton inherits from Component
int fiveFiftyFive = new N(555).I();
double charValues[] = (double[]) new S("arraySize11").L(double[].class);

Overrides:
L in class CS
Throws:
java.lang.ClassCastException
See Also:
CS.Z(), CS.B(), CS.C(), CS.S(), CS.I(), CS.J(), CS.F(), CS.D()

javaCode

public java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
this function could use a better algorithm, but for now try to get javaCode(CS) to work at all.

Overrides:
javaCode in class DefaultCS
Returns:
String of Java code, or null if this CS does not know how to convert itself to Java code.

isNumberType

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