01: package jsint;
02:
03: /**
04: A Procedure that can invoke a Method.
05: * @author Ken R. Anderson, Copyright 2000, kanderso@bbn.com, <a href="license.txt">license</a>
06: * subsequently modified by Jscheme project members
07: * licensed under zlib licence (see license.txt)
08: */
09:
10: import java.lang.reflect.Method;
11: import java.lang.reflect.Modifier;
12:
13: public class RawMethod extends Procedure {
14: private Method method;
15:
16: public RawMethod(Method method) {
17: this .method = method;
18: this .minArgs = (this .isStatic() ? 0 : 1)
19: + method.getParameterTypes().length;
20: this .maxArgs = minArgs;
21: }
22:
23: public boolean isStatic() {
24: return Modifier.isStatic(method.getModifiers());
25: }
26:
27: public Object apply(Object[] args) {
28: if (this .isStatic())
29: return Invoke.invokeRawMethod(method, null, args);
30: else {
31: int L = this .minArgs - 1;
32: Object[] newArgs = new Object[L];
33: System.arraycopy(args, 1, newArgs, 0, L);
34: return Invoke.invokeRawMethod(method, args[0], newArgs);
35: }
36: }
37: }
|