|
1 |
| package edu.rice.cs.dynamicjava.interpreter; |
|
2 |
| |
|
3 |
| import edu.rice.cs.dynamicjava.symbol.*; |
|
4 |
| import edu.rice.cs.dynamicjava.symbol.type.ClassType; |
|
5 |
| import edu.rice.cs.dynamicjava.symbol.type.VariableType; |
|
6 |
| |
|
7 |
| import static edu.rice.cs.plt.debug.DebugUtil.debug; |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| public class ClassSignatureContext extends DelegatingContext { |
|
14 |
| |
|
15 |
| private DJClass _c; |
|
16 |
| private ClassLoader _loader; |
|
17 |
| |
|
18 |
267
| public ClassSignatureContext(TypeContext next, DJClass c, ClassLoader loader) {
|
|
19 |
267
| super(next);
|
|
20 |
267
| _c = c;
|
|
21 |
267
| _loader = loader;
|
|
22 |
| } |
|
23 |
| |
|
24 |
0
| protected ClassSignatureContext duplicate(TypeContext next) {
|
|
25 |
0
| return new ClassSignatureContext(next, _c, _loader);
|
|
26 |
| } |
|
27 |
| |
|
28 |
| |
|
29 |
3
| @Override public boolean typeExists(String name, TypeSystem ts) {
|
|
30 |
3
| return matchesClass(name) || matchesTypeVariable(name) || super.typeExists(name, ts);
|
|
31 |
| } |
|
32 |
| |
|
33 |
778
| private boolean matchesTopLevelClass(String name) {
|
|
34 |
778
| return !_c.isAnonymous() && _c.declaringClass() == null && _c.declaredName().equals(name);
|
|
35 |
| } |
|
36 |
| |
|
37 |
778
| private boolean matchesMemberClass(String name) {
|
|
38 |
778
| return !_c.isAnonymous() && _c.declaringClass() != null && _c.declaredName().equals(name);
|
|
39 |
| } |
|
40 |
| |
|
41 |
95
| private boolean matchesClass(String name) {
|
|
42 |
95
| return !_c.isAnonymous() && _c.declaredName().equals(name);
|
|
43 |
| } |
|
44 |
| |
|
45 |
781
| private boolean matchesTypeVariable(String name) {
|
|
46 |
781
| return declaredTypeVariable(name) != null;
|
|
47 |
| } |
|
48 |
| |
|
49 |
1057
| private VariableType declaredTypeVariable(String name) {
|
|
50 |
1057
| for (VariableType t : _c.declaredTypeParameters()) {
|
|
51 |
368
| if (t.symbol().name().equals(name)) { return t; }
|
|
52 |
| } |
|
53 |
689
| return null;
|
|
54 |
| } |
|
55 |
| |
|
56 |
| |
|
57 |
0
| @Override public boolean topLevelClassExists(String name, TypeSystem ts) {
|
|
58 |
0
| return matchesTopLevelClass(name) ||
|
|
59 |
| (!matchesMemberClass(name) && !matchesTypeVariable(name) && super.topLevelClassExists(name, ts)); |
|
60 |
| } |
|
61 |
| |
|
62 |
| |
|
63 |
686
| @Override public DJClass getTopLevelClass(String name, TypeSystem ts) throws AmbiguousNameException {
|
|
64 |
686
| if (matchesTopLevelClass(name)) {
|
|
65 |
0
| return _c;
|
|
66 |
| } |
|
67 |
686
| else if (!matchesMemberClass(name) && !matchesTypeVariable(name)) {
|
|
68 |
502
| return super.getTopLevelClass(name, ts);
|
|
69 |
| } |
|
70 |
184
| else { return null; }
|
|
71 |
| } |
|
72 |
| |
|
73 |
| |
|
74 |
0
| @Override public boolean memberClassExists(String name, TypeSystem ts) {
|
|
75 |
0
| return matchesMemberClass(name) ||
|
|
76 |
| (!matchesTopLevelClass(name) && !matchesTypeVariable(name) && super.memberClassExists(name, ts)); |
|
77 |
| } |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
92
| @Override public ClassType typeContainingMemberClass(String name, TypeSystem ts) throws AmbiguousNameException {
|
|
84 |
92
| debug.logStart(new String[]{"class","name"}, _c, name); try {
|
|
85 |
| |
|
86 |
92
| if (matchesMemberClass(name)) {
|
|
87 |
0
| return SymbolUtil.thisType(_c.declaringClass());
|
|
88 |
| } |
|
89 |
92
| else if (!matchesTopLevelClass(name) && !matchesTypeVariable(name)) {
|
|
90 |
92
| return super.typeContainingMemberClass(name, ts);
|
|
91 |
| } |
|
92 |
0
| else { return null; }
|
|
93 |
| |
|
94 |
92
| } finally { debug.logEnd(); }
|
|
95 |
| } |
|
96 |
| |
|
97 |
| |
|
98 |
0
| @Override public boolean typeVariableExists(String name, TypeSystem ts) {
|
|
99 |
0
| return matchesTypeVariable(name) ||
|
|
100 |
| (!matchesClass(name) && super.typeVariableExists(name, ts)); |
|
101 |
| } |
|
102 |
| |
|
103 |
| |
|
104 |
276
| @Override public VariableType getTypeVariable(String name, TypeSystem ts) {
|
|
105 |
276
| VariableType result = declaredTypeVariable(name);
|
|
106 |
184
| if (result != null) { return result; }
|
|
107 |
92
| else if (!matchesClass(name)) { return super.getTypeVariable(name, ts); }
|
|
108 |
0
| else { return null; }
|
|
109 |
| } |
|
110 |
| |
|
111 |
0
| @Override public ClassLoader getClassLoader() { return _loader; }
|
|
112 |
| |
|
113 |
1042
| @Override public Access.Module accessModule() { return _c.accessModule(); }
|
|
114 |
| |
|
115 |
| } |