1 package de.lathanda.eos.vm.commands;
3 import java.lang.reflect.InvocationTargetException;
5 import de.lathanda.eos.vm.Command;
6 import de.lathanda.eos.vm.MObject;
7 import de.lathanda.eos.vm.MType;
8 import de.lathanda.eos.vm.Machine;
9 import de.lathanda.eos.vm.Variable;
10 import de.lathanda.eos.vm.exceptions.NullAccessException;
20 private final MType[] parameters;
21 private final java.lang.reflect.Method method;
23 public Method(
MType[] parameters, java.lang.reflect.Method method) {
24 this.parameters = parameters;
30 Object target = m.pop();
31 Object[] args =
new Object[parameters.length];
32 for (
int i = 0; i < args.length; i++) {
41 if (target instanceof
MObject) {
42 result = method.invoke(((
MObject) target).getJavaObject(), args);
43 }
else if (target instanceof
Variable) {
44 result = method.invoke(((
Variable) target).
get(), args);
46 result = method.invoke(target, args);
51 }
catch (InvocationTargetException ite) {
52 throw (Exception) ite.getTargetException();
59 return "Method{" + method.getName() +
"(" + parameters.length +
") }";
boolean execute(Machine m)
Method(MType[] parameters, java.lang.reflect.Method method)
Object checkAndCast(Object obj)