|
1 |
| package edu.rice.cs.dynamicjava.symbol; |
|
2 |
| |
|
3 |
| import static edu.rice.cs.plt.debug.DebugUtil.debug; |
|
4 |
| |
|
5 |
| import java.lang.reflect.InvocationTargetException; |
|
6 |
| import java.lang.reflect.Method; |
|
7 |
| |
|
8 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
9 |
| import edu.rice.cs.plt.lambda.WrappedException; |
|
10 |
| import edu.rice.cs.dynamicjava.Options; |
|
11 |
| import edu.rice.cs.dynamicjava.interpreter.EvaluatorException; |
|
12 |
| import edu.rice.cs.dynamicjava.interpreter.RuntimeBindings; |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| public abstract class SpecialMethod implements DJMethod { |
|
19 |
| |
|
20 |
| protected abstract Method implementation() throws ClassNotFoundException, NoSuchMethodException; |
|
21 |
| |
|
22 |
0
| public DJMethod declaredSignature() { return this; }
|
|
23 |
0
| public Object evaluate(Object receiver, Iterable<Object> args, RuntimeBindings bindings,
|
|
24 |
| Options options) throws EvaluatorException { |
|
25 |
0
| if (receiver == null) {
|
|
26 |
0
| throw new WrappedException(new EvaluatorException(new NullPointerException()));
|
|
27 |
| } |
|
28 |
0
| try {
|
|
29 |
0
| Method m = implementation();
|
|
30 |
0
| try { m.setAccessible(true); }
|
|
31 |
0
| catch (SecurityException e) { debug.log(e); }
|
|
32 |
0
| return m.invoke(receiver, IterUtil.toArray(args, Object.class));
|
|
33 |
| } |
|
34 |
0
| catch (ClassNotFoundException e) { throw new RuntimeException(e); }
|
|
35 |
0
| catch (NoSuchMethodException e) { throw new RuntimeException(e); }
|
|
36 |
0
| catch (InvocationTargetException e) { throw new EvaluatorException(e.getCause(), EXTRA_STACK); }
|
|
37 |
0
| catch (IllegalAccessException e) { throw new RuntimeException(e); }
|
|
38 |
| } |
|
39 |
| |
|
40 |
| private static final String[] EXTRA_STACK = |
|
41 |
| new String[] { "java.lang.reflect.Method.invoke", |
|
42 |
| "sun.reflect.DelegatingMethodAccessorImpl.invoke", |
|
43 |
| "sun.reflect.NativeMethodAccessorImpl.invoke", |
|
44 |
| "sun.reflect.NativeMethodAccessorImpl.invoke0" }; |
|
45 |
| } |