| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
package smetana.core; |
| 38 |
|
| 39 |
import java.lang.reflect.InvocationTargetException; |
| 40 |
import java.lang.reflect.Method; |
| 41 |
|
| 42 |
import smetana.core.amiga.Area; |
| 43 |
|
| 44 |
public class CFunctionImpl extends UnsupportedC implements CFunction, Area { |
| 45 |
|
| 46 |
private final Class codingClass; |
| 47 |
private final String name; |
| 48 |
private final Method method; |
| 49 |
|
| 50 |
public static CFunctionImpl create(Class codingClass, String name) { |
| 51 |
return new CFunctionImpl(codingClass, name); |
| 52 |
} |
| 53 |
|
| 54 |
private CFunctionImpl(Class codingClass, String name) { |
| 55 |
this.codingClass = codingClass; |
| 56 |
this.name = name; |
| 57 |
for (Method m : codingClass.getMethods()) { |
| 58 |
if (m.getName().equals(name)) { |
| 59 |
this.method = m; |
| 60 |
return; |
| 61 |
} |
| 62 |
} |
| 63 |
JUtils.LOG("CANNOT FIND METHOD " + name + " IN " + codingClass); |
| 64 |
throw new IllegalStateException("codingClass=" + codingClass + " name=" + name); |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public String toString() { |
| 69 |
return codingClass.getName() + "::" + name; |
| 70 |
} |
| 71 |
|
| 72 |
public Object exe(Object... args) { |
| 73 |
JUtils.LOG("-------"); |
| 74 |
for (Object arg : args) { |
| 75 |
JUtils.LOG("arg=" + arg); |
| 76 |
} |
| 77 |
JUtils.LOG("method="+method); |
| 78 |
try { |
| 79 |
return this.method.invoke(null, args); |
| 80 |
} catch (InvocationTargetException e) { |
| 81 |
e.printStackTrace(); |
| 82 |
throw new UnsupportedOperationException(toString()); |
| 83 |
} catch (IllegalArgumentException e) { |
| 84 |
e.printStackTrace(); |
| 85 |
throw new UnsupportedOperationException(toString()); |
| 86 |
} catch (IllegalAccessException e) { |
| 87 |
e.printStackTrace(); |
| 88 |
throw new UnsupportedOperationException(toString()); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
public String getName() { |
| 93 |
return name; |
| 94 |
} |
| 95 |
|
| 96 |
public void memcopyFrom(Area source) { |
| 97 |
throw new UnsupportedOperationException(); |
| 98 |
} |
| 99 |
|
| 100 |
} |