1 |
| package edu.rice.cs.dynamicjava.symbol; |
2 |
| |
3 |
| import java.util.Iterator; |
4 |
| import edu.rice.cs.plt.lambda.Lambda; |
5 |
| import edu.rice.cs.plt.lambda.LambdaUtil; |
6 |
| import edu.rice.cs.plt.iter.IterUtil; |
7 |
| import edu.rice.cs.plt.iter.SequenceIterator; |
8 |
| |
9 |
| import edu.rice.cs.dynamicjava.Options; |
10 |
| import edu.rice.cs.dynamicjava.interpreter.RuntimeBindings; |
11 |
| import edu.rice.cs.dynamicjava.interpreter.EvaluatorException; |
12 |
| import edu.rice.cs.dynamicjava.symbol.type.Type; |
13 |
| import edu.rice.cs.dynamicjava.symbol.type.VariableType; |
14 |
| |
15 |
| import static edu.rice.cs.plt.debug.DebugUtil.debug; |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| public class FunctionWrapperClass implements DJClass { |
22 |
| |
23 |
| private static final Iterator<Integer> ID_COUNTER = |
24 |
| new SequenceIterator<Integer>(1, LambdaUtil.INCREMENT_INT); |
25 |
| |
26 |
| private final Access.Module _accessModule; |
27 |
| private final Iterable<DJMethod> _methods; |
28 |
| private final String _name; |
29 |
| |
30 |
108
| public FunctionWrapperClass(Access.Module accessModule, Iterable<? extends LocalFunction> functions) {
|
31 |
108
| _accessModule = accessModule;
|
32 |
108
| _methods = IterUtil.mapSnapshot(functions, FUNCTION_AS_METHOD);
|
33 |
108
| _name = "Overload" + ID_COUNTER.next();
|
34 |
| } |
35 |
| |
36 |
| |
37 |
| private final Lambda<LocalFunction, DJMethod> FUNCTION_AS_METHOD = |
38 |
| new Lambda<LocalFunction, DJMethod>() { |
39 |
108
| public DJMethod value(LocalFunction f) { return new FunctionWrapperMethod(f); }
|
40 |
| }; |
41 |
| |
42 |
0
| public String packageName() { return _accessModule.packageName(); }
|
43 |
| |
44 |
| |
45 |
0
| public String fullName() {
|
46 |
| |
47 |
0
| String pkg = packageName();
|
48 |
0
| if (pkg.length() > 0) pkg += ".";
|
49 |
0
| return pkg + "$" + _name;
|
50 |
| } |
51 |
| |
52 |
0
| public boolean isAnonymous() { return false; }
|
53 |
0
| public String declaredName() { return _name; }
|
54 |
0
| public boolean isInterface() { return false; }
|
55 |
216
| public boolean isStatic() { return false; }
|
56 |
0
| public boolean isAbstract() { return false; }
|
57 |
0
| public boolean isFinal() { return true; }
|
58 |
0
| public Access accessibility() { return Access.PUBLIC; }
|
59 |
0
| public Access.Module accessModule() { return _accessModule; }
|
60 |
0
| public boolean hasRuntimeBindingsParams() { return false; }
|
61 |
| |
62 |
216
| public DJClass declaringClass() { return null; }
|
63 |
| |
64 |
108
| public Iterable<VariableType> declaredTypeParameters() { return IterUtil.empty(); }
|
65 |
| |
66 |
108
| public Iterable<Type> declaredSupertypes() { return IterUtil.empty(); }
|
67 |
0
| public Iterable<DJField> declaredFields() { return IterUtil.empty(); }
|
68 |
0
| public Iterable<DJConstructor> declaredConstructors() { return IterUtil.empty(); }
|
69 |
108
| public Iterable<DJMethod> declaredMethods() { return _methods; }
|
70 |
0
| public Iterable<DJClass> declaredClasses() { return IterUtil.empty(); }
|
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
0
| public Type immediateSuperclass() { return null; }
|
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
0
| public Class<?> load() { throw new UnsupportedOperationException(); }
|
83 |
| |
84 |
| |
85 |
0
| public boolean equals(Object o) { return this == o; }
|
86 |
| |
87 |
108
| public int hashCode() { return System.identityHashCode(this); }
|
88 |
| |
89 |
| |
90 |
| private class FunctionWrapperMethod implements DJMethod { |
91 |
| private final LocalFunction _f; |
92 |
108
| public FunctionWrapperMethod(LocalFunction f) { _f = f; }
|
93 |
216
| public Iterable<VariableType> typeParameters() { return _f.typeParameters(); }
|
94 |
108
| public Iterable<LocalVariable> parameters() { return _f.parameters(); }
|
95 |
108
| public Iterable<Type> thrownTypes() { return _f.thrownTypes(); }
|
96 |
108
| public String declaredName() { return _f.declaredName(); }
|
97 |
0
| public DJClass declaringClass() { return FunctionWrapperClass.this; }
|
98 |
324
| public Type returnType() { return _f.returnType(); }
|
99 |
216
| public boolean isStatic() { return true; }
|
100 |
0
| public boolean isAbstract() { return false; }
|
101 |
0
| public boolean isFinal() { return false; }
|
102 |
108
| public Access accessibility() { return Access.PUBLIC; }
|
103 |
0
| public Access.Module accessModule() { return _accessModule; }
|
104 |
0
| public DJMethod declaredSignature() { return this; }
|
105 |
108
| public Object evaluate(Object receiver, Iterable<Object> args, RuntimeBindings bindings, Options options)
|
106 |
| throws EvaluatorException { |
107 |
108
| return _f.evaluate(args, bindings, options);
|
108 |
| } |
109 |
| } |
110 |
| |
111 |
| } |