|
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 |
| package edu.rice.cs.javalanglevels; |
|
32 |
| |
|
33 |
| import edu.rice.cs.javalanglevels.tree.*; |
|
34 |
| import edu.rice.cs.javalanglevels.parser.*; |
|
35 |
| import edu.rice.cs.javalanglevels.util.Utilities; |
|
36 |
| |
|
37 |
| import edu.rice.cs.plt.reflect.JavaVersion; |
|
38 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
39 |
| import java.util.*; |
|
40 |
| import java.io.*; |
|
41 |
| |
|
42 |
| import junit.framework.TestCase; |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| public class InterfaceBodyFullJavaVisitor extends FullJavaVisitor { |
|
49 |
| |
|
50 |
| |
|
51 |
| private SymbolData _enclosing; |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
12
| public InterfaceBodyFullJavaVisitor(SymbolData sd,
|
|
64 |
| File file, |
|
65 |
| String packageName, |
|
66 |
| LinkedList<String> importedFiles, |
|
67 |
| LinkedList<String> importedPackages, |
|
68 |
| HashSet<String> classesInThisFile, |
|
69 |
| Hashtable<String, Triple<SourceInfo, LanguageLevelVisitor, SymbolData>> continuations, |
|
70 |
| LinkedList<Command> fixUps) { |
|
71 |
12
| super(file, packageName, sd.getName(), importedFiles, importedPackages, classesInThisFile, continuations, fixUps);
|
|
72 |
12
| _enclosing = sd;
|
|
73 |
| |
|
74 |
| |
|
75 |
| } |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
12
| public InterfaceBodyFullJavaVisitor(SymbolData sd,
|
|
89 |
| File file, |
|
90 |
| String packageName, |
|
91 |
| LinkedList<String> importedFiles, |
|
92 |
| LinkedList<String> importedPackages, |
|
93 |
| HashSet<String> classesInThisFile, |
|
94 |
| Hashtable<String, Triple<SourceInfo, LanguageLevelVisitor, SymbolData>> continuations, |
|
95 |
| LinkedList<Command> fixUps, |
|
96 |
| HashMap<String, SymbolData> genericTypes) { |
|
97 |
12
| super(file, packageName, sd.getName(), importedFiles, importedPackages, classesInThisFile, continuations, fixUps,
|
|
98 |
| genericTypes); |
|
99 |
12
| _enclosing = sd;
|
|
100 |
| |
|
101 |
| |
|
102 |
| } |
|
103 |
| |
|
104 |
| |
|
105 |
0
| public Void forStatementDoFirst(Statement that) { return null; }
|
|
106 |
| |
|
107 |
| |
|
108 |
1
| public Void forConcreteMethodDefDoFirst(ConcreteMethodDef that) {
|
|
109 |
1
| _addError("You cannot have concrete methods definitions in interfaces", that);
|
|
110 |
1
| return null;
|
|
111 |
| } |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
1
| public Void forInstanceInitializerDoFirst(InstanceInitializer that) {
|
|
116 |
1
| _addError("This open brace must mark the beginning of an interface body", that);
|
|
117 |
1
| return null;
|
|
118 |
| } |
|
119 |
| |
|
120 |
| |
|
121 |
0
| public Void forVariableDeclarationOnly(VariableDeclaration that) { return null; }
|
|
122 |
| |
|
123 |
| |
|
124 |
2
| public Void forThisReferenceDoFirst(ThisReference that) {
|
|
125 |
2
| _addAndIgnoreError("The field 'this' does not exist in interfaces. Only classes have a 'this' field.", that);
|
|
126 |
2
| return null;
|
|
127 |
| } |
|
128 |
| |
|
129 |
| |
|
130 |
2
| public Void forSuperReferenceDoFirst(SuperReference that) {
|
|
131 |
2
| _addAndIgnoreError("The field 'super' does not exist in interfaces. Only classes have a 'super' field", that);
|
|
132 |
2
| return null;
|
|
133 |
| } |
|
134 |
| |
|
135 |
13
| public Void forAbstractMethodDef(AbstractMethodDef that) {
|
|
136 |
13
| forAbstractMethodDefDoFirst(that);
|
|
137 |
0
| if (_checkError()) return null;
|
|
138 |
| |
|
139 |
13
| assert _enclosing != null;
|
|
140 |
| |
|
141 |
| |
|
142 |
13
| TypeParameter[] tps = that.getTypeParams();
|
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
13
| HashMap<String, SymbolData> oldGenericTypes = _genericTypes;
|
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
13
| @SuppressWarnings("unchecked")
|
|
154 |
| HashMap<String, SymbolData> copy = (HashMap<String, SymbolData>)_genericTypes.clone(); |
|
155 |
13
| _genericTypes = copy;
|
|
156 |
| |
|
157 |
13
| if (tps != null) {
|
|
158 |
13
| for (TypeParameter tp: tps) {
|
|
159 |
0
| final String typeName = tp.getVariable().getName();
|
|
160 |
0
| final String boundName = tp.getBound().getName();
|
|
161 |
0
| SymbolData boundSD = _identifyType(boundName, that.getSourceInfo(), _enclosingClassName);
|
|
162 |
0
| if (boundSD == null) {
|
|
163 |
0
| boundSD = symbolTable.get("java.lang.Object");
|
|
164 |
| |
|
165 |
| |
|
166 |
| } |
|
167 |
| |
|
168 |
| |
|
169 |
0
| _genericTypes.put(typeName, boundSD);
|
|
170 |
| } |
|
171 |
| } |
|
172 |
| |
|
173 |
13
| MethodData md = createMethodData(that, _enclosing);
|
|
174 |
| |
|
175 |
| |
|
176 |
13
| if (md.hasModifier("private")) {
|
|
177 |
1
| _addAndIgnoreError("Interface methods cannot be private. They must be public.", that.getMav());
|
|
178 |
| } |
|
179 |
13
| if (md.hasModifier("protected")) {
|
|
180 |
1
| _addAndIgnoreError("Interface methods cannot be protected. They must be public.", that.getMav());
|
|
181 |
| } |
|
182 |
| |
|
183 |
| |
|
184 |
13
| md.addModifier("public");
|
|
185 |
13
| md.addModifier("abstract");
|
|
186 |
13
| String className = getUnqualifiedClassName(_enclosing.getName());
|
|
187 |
13
| if (className.equals(md.getName())) {
|
|
188 |
1
| _addAndIgnoreError("Only constructors can have the same name as the class they appear in, " +
|
|
189 |
| "and constructors cannot appear in interfaces.", that); |
|
190 |
| } |
|
191 |
12
| else _enclosing.addMethod(md);
|
|
192 |
| |
|
193 |
13
| _genericTypes = oldGenericTypes;
|
|
194 |
13
| return null;
|
|
195 |
| } |
|
196 |
| |
|
197 |
| |
|
198 |
4
| public Void forInnerInterfaceDef(InnerInterfaceDef that) {
|
|
199 |
4
| String relName = that.getName().getText();
|
|
200 |
4
| handleInnerInterfaceDef(that, _enclosing, relName, getQualifiedClassName(_enclosing.getName()) + '.' + relName);
|
|
201 |
4
| return null;
|
|
202 |
| } |
|
203 |
| |
|
204 |
| |
|
205 |
1
| public Void forInnerClassDef(InnerClassDef that) {
|
|
206 |
1
| String relName = that.getName().getText();
|
|
207 |
1
| handleInnerClassDef(that, _enclosing, relName, getQualifiedClassName(_enclosing.getName()) + '.' + relName);
|
|
208 |
1
| return null;
|
|
209 |
| } |
|
210 |
| |
|
211 |
| |
|
212 |
1
| public Void forConstructorDefDoFirst(ConstructorDef that) {
|
|
213 |
1
| _addAndIgnoreError("Constructor definitions cannot appear in interfaces", that);
|
|
214 |
1
| return null;
|
|
215 |
| } |
|
216 |
| |
|
217 |
| |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
0
| protected VariableData[] _variableDeclaration2VariableData(VariableDeclaration vd, Data enclosingData) {
|
|
223 |
0
| VariableData[] vds = super._variableDeclaration2VariableData(vd, enclosingData);
|
|
224 |
0
| for (int i = 0; i < vds.length; i++) {
|
|
225 |
0
| vds[i].setFinalAndStatic();
|
|
226 |
| } |
|
227 |
0
| return vds;
|
|
228 |
| } |
|
229 |
| |
|
230 |
| |
|
231 |
0
| public Void forComplexAnonymousClassInstantiation(ComplexAnonymousClassInstantiation that) {
|
|
232 |
0
| complexAnonymousClassInstantiationHelper(that, _enclosing);
|
|
233 |
0
| return null;
|
|
234 |
| } |
|
235 |
| |
|
236 |
| |
|
237 |
0
| public Void forSimpleAnonymousClassInstantiation(SimpleAnonymousClassInstantiation that) {
|
|
238 |
| |
|
239 |
0
| simpleAnonymousClassInstantiationHelper(that, _enclosing);
|
|
240 |
0
| return null;
|
|
241 |
| } |
|
242 |
| |
|
243 |
| |
|
244 |
| public static class InterfaceBodyFullJavaVisitorTest extends TestCase { |
|
245 |
| |
|
246 |
| private InterfaceBodyFullJavaVisitor _ibfv; |
|
247 |
| |
|
248 |
| private SymbolData _sd1; |
|
249 |
| private SymbolData _objectSD; |
|
250 |
| |
|
251 |
| private ModifiersAndVisibility _publicMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"public"}); |
|
252 |
| private ModifiersAndVisibility _protectedMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"protected"}); |
|
253 |
| private ModifiersAndVisibility _privateMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"private"}); |
|
254 |
| private ModifiersAndVisibility _packageMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[0]); |
|
255 |
| private ModifiersAndVisibility _abstractMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"abstract"}); |
|
256 |
| private ModifiersAndVisibility _finalMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"final"}); |
|
257 |
| |
|
258 |
0
| public InterfaceBodyFullJavaVisitorTest() { this(""); }
|
|
259 |
12
| public InterfaceBodyFullJavaVisitorTest(String name) { super(name); }
|
|
260 |
| |
|
261 |
12
| public void setUp() {
|
|
262 |
12
| errors = new LinkedList<Pair<String, JExpressionIF>>();
|
|
263 |
12
| LanguageLevelConverter.symbolTable.clear();
|
|
264 |
12
| LanguageLevelConverter._newSDs.clear();
|
|
265 |
12
| LanguageLevelConverter.OPT = new Options(JavaVersion.JAVA_5, IterUtil.make(new File("lib/buildlib/junit.jar")));
|
|
266 |
12
| visitedFiles = new LinkedList<Pair<LanguageLevelVisitor, edu.rice.cs.javalanglevels.tree.SourceFile>>();
|
|
267 |
| |
|
268 |
| |
|
269 |
12
| _sd1 = new SymbolData("MyInterface");
|
|
270 |
12
| _sd1.setIsContinuation(false);
|
|
271 |
12
| _sd1.setInterface(true);
|
|
272 |
12
| _sd1.setPackage("");
|
|
273 |
12
| _sd1.setTypeParameters(new TypeParameter[0]);
|
|
274 |
12
| _sd1.setInterfaces(new ArrayList<SymbolData>());
|
|
275 |
| |
|
276 |
| |
|
277 |
12
| _ibfv = new InterfaceBodyFullJavaVisitor(_sd1,
|
|
278 |
| new File(""), |
|
279 |
| "", |
|
280 |
| new LinkedList<String>(), |
|
281 |
| new LinkedList<String>(), |
|
282 |
| new HashSet<String>(), |
|
283 |
| new Hashtable<String, Triple<SourceInfo, LanguageLevelVisitor, SymbolData>>(), |
|
284 |
| new LinkedList<Command>()); |
|
285 |
12
| _ibfv._classesInThisFile = new HashSet<String>();
|
|
286 |
12
| _ibfv.continuations = new Hashtable<String, Triple<SourceInfo, LanguageLevelVisitor, SymbolData>>();
|
|
287 |
12
| _ibfv._importedPackages.addFirst("java.lang");
|
|
288 |
12
| _ibfv._enclosingClassName = "MyInterface";
|
|
289 |
| |
|
290 |
12
| _objectSD = LanguageLevelConverter.symbolTable.get("java.lang.Object");
|
|
291 |
12
| _sd1.setSuperClass(_objectSD);
|
|
292 |
| |
|
293 |
12
| LanguageLevelConverter.symbolTable.put("MyInterface", _sd1);
|
|
294 |
| |
|
295 |
12
| _errorAdded = false;
|
|
296 |
| } |
|
297 |
| |
|
298 |
1
| public void testForConcreteMethodDefDoFirst() {
|
|
299 |
| |
|
300 |
1
| ConcreteMethodDef cmd = new ConcreteMethodDef(SourceInfo.NONE,
|
|
301 |
| _publicMav, |
|
302 |
| new TypeParameter[0], |
|
303 |
| new PrimitiveType(SourceInfo.NONE, "int"), |
|
304 |
| new Word(SourceInfo.NONE, "methodName"), |
|
305 |
| new FormalParameter[0], |
|
306 |
| new ReferenceType[0], |
|
307 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
308 |
1
| cmd.visit(_ibfv);
|
|
309 |
1
| assertEquals("There should not be 1 error", 1, errors.size());
|
|
310 |
1
| assertEquals("The error message should be correct", "You cannot have concrete methods definitions in interfaces",
|
|
311 |
| errors.getLast().getFirst()); |
|
312 |
| |
|
313 |
| } |
|
314 |
| |
|
315 |
1
| public void testForAbstractMethodDefDoFirst() {
|
|
316 |
| |
|
317 |
1
| _ibfv._enclosing.setMav(_abstractMav);
|
|
318 |
1
| AbstractMethodDef amd2 = new AbstractMethodDef(SourceInfo.NONE,
|
|
319 |
| _abstractMav, |
|
320 |
| new TypeParameter[0], |
|
321 |
| new PrimitiveType(SourceInfo.NONE, "double"), |
|
322 |
| new Word(SourceInfo.NONE, "methodName"), |
|
323 |
| new FormalParameter[0], |
|
324 |
| new ReferenceType[0]); |
|
325 |
1
| amd2.visit(_ibfv);
|
|
326 |
1
| assertEquals("There should be no errors", 0, errors.size());
|
|
327 |
1
| assertTrue("The method def should be public",
|
|
328 |
| _ibfv._enclosing.getMethods().get(0).hasModifier("public")); |
|
329 |
| |
|
330 |
| } |
|
331 |
| |
|
332 |
1
| public void testForInstanceInitializerDoFirst() {
|
|
333 |
1
| InstanceInitializer ii =
|
|
334 |
| new InstanceInitializer(SourceInfo.NONE, |
|
335 |
| new Block(SourceInfo.NONE, |
|
336 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0]))); |
|
337 |
1
| ii.visit(_ibfv);
|
|
338 |
1
| assertEquals("There should be one error.", 1, errors.size());
|
|
339 |
1
| assertEquals("The error message should be correct.",
|
|
340 |
| "This open brace must mark the beginning of an interface body", |
|
341 |
| errors.get(0).getFirst()); |
|
342 |
| } |
|
343 |
| |
|
344 |
1
| public void testForSimpleThisReferenceDoFirst() {
|
|
345 |
1
| SimpleThisReference tl = new SimpleThisReference(SourceInfo.NONE);
|
|
346 |
1
| tl.visit(_ibfv);
|
|
347 |
1
| assertEquals("There should be one error", 1, errors.size());
|
|
348 |
1
| assertEquals("The error message should be correct",
|
|
349 |
| "The field 'this' does not exist in interfaces. Only classes have a 'this' field.", |
|
350 |
| errors.get(0).getFirst()); |
|
351 |
| } |
|
352 |
| |
|
353 |
1
| public void testForComplexThisReferenceDoFirst() {
|
|
354 |
1
| ComplexThisReference tl = new ComplexThisReference(SourceInfo.NONE,
|
|
355 |
| new NullLiteral(SourceInfo.NONE)); |
|
356 |
1
| tl.visit(_ibfv);
|
|
357 |
1
| assertEquals("There should be one error", 1, errors.size());
|
|
358 |
1
| assertEquals("The error message should be correct",
|
|
359 |
| "The field 'this' does not exist in interfaces. Only classes have a 'this' field.", |
|
360 |
| errors.get(0).getFirst()); |
|
361 |
| |
|
362 |
| } |
|
363 |
| |
|
364 |
1
| public void testForSimpleSuperReferenceDoFirst() {
|
|
365 |
1
| SimpleSuperReference sr = new SimpleSuperReference(SourceInfo.NONE);
|
|
366 |
1
| sr.visit(_ibfv);
|
|
367 |
1
| assertEquals("There should be one error", 1, errors.size());
|
|
368 |
1
| assertEquals("The error message should be correct",
|
|
369 |
| "The field 'super' does not exist in interfaces. Only classes have a 'super' field", |
|
370 |
| errors.get(0).getFirst()); |
|
371 |
| } |
|
372 |
| |
|
373 |
1
| public void testForComplexSuperReferenceDoFirst() {
|
|
374 |
1
| ComplexSuperReference cr = new ComplexSuperReference(SourceInfo.NONE,
|
|
375 |
| new NullLiteral(SourceInfo.NONE)); |
|
376 |
1
| cr.visit(_ibfv);
|
|
377 |
1
| assertEquals("There should be one error", 1, errors.size());
|
|
378 |
1
| assertEquals("The error message should be correct",
|
|
379 |
| "The field 'super' does not exist in interfaces. Only classes have a 'super' field", |
|
380 |
| errors.get(0).getFirst()); |
|
381 |
| } |
|
382 |
| |
|
383 |
0
| public void xtestForVariableDeclarationDoFirst() {
|
|
384 |
| |
|
385 |
0
| VariableDeclaration vdecl0 = new VariableDeclaration(SourceInfo.NONE,
|
|
386 |
| _packageMav, |
|
387 |
| new VariableDeclarator[] { |
|
388 |
| new InitializedVariableDeclarator(SourceInfo.NONE, |
|
389 |
| new PrimitiveType(SourceInfo.NONE, "double"), |
|
390 |
| new Word (SourceInfo.NONE, "field0"), |
|
391 |
| new DoubleLiteral(SourceInfo.NONE, 2.345))}); |
|
392 |
| |
|
393 |
0
| vdecl0.visit(_ibfv);
|
|
394 |
0
| assertEquals("There should be no errors", 0, errors.size());
|
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
0
| VariableDeclaration vdecl = new VariableDeclaration(SourceInfo.NONE,
|
|
399 |
| _packageMav, |
|
400 |
| new VariableDeclarator[] { |
|
401 |
| new InitializedVariableDeclarator(SourceInfo.NONE, |
|
402 |
| new PrimitiveType(SourceInfo.NONE, "double"), |
|
403 |
| new Word (SourceInfo.NONE, "field1"), |
|
404 |
| new DoubleLiteral(SourceInfo.NONE, 2.45)), |
|
405 |
| new UninitializedVariableDeclarator(SourceInfo.NONE, |
|
406 |
| new PrimitiveType(SourceInfo.NONE, "boolean"), |
|
407 |
| new Word (SourceInfo.NONE, "field2"))}); |
|
408 |
0
| vdecl.visit(_ibfv);
|
|
409 |
0
| assertEquals("There should be one error", 1, errors.size());
|
|
410 |
0
| assertEquals("The error message should be correct",
|
|
411 |
| "All fields in interfaces must be assigned a value when they are declared", |
|
412 |
| errors.getLast().getFirst()); |
|
413 |
| } |
|
414 |
| |
|
415 |
1
| public void testForAbstractMethodDef() {
|
|
416 |
| |
|
417 |
1
| MethodDef mdef = new AbstractMethodDef(SourceInfo.NONE,
|
|
418 |
| _abstractMav, |
|
419 |
| new TypeParameter[0], |
|
420 |
| new PrimitiveType(SourceInfo.NONE, "int"), |
|
421 |
| new Word(SourceInfo.NONE, "methodName"), |
|
422 |
| new FormalParameter[0], |
|
423 |
| new ReferenceType[0]); |
|
424 |
1
| _ibfv._enclosing.setMav(_abstractMav);
|
|
425 |
1
| mdef.visit(_ibfv);
|
|
426 |
1
| assertEquals("There should not be any errors.", 0, errors.size());
|
|
427 |
| |
|
428 |
| |
|
429 |
1
| mdef = new AbstractMethodDef(SourceInfo.NONE,
|
|
430 |
| _abstractMav, |
|
431 |
| new TypeParameter[0], |
|
432 |
| new PrimitiveType(SourceInfo.NONE, "int"), |
|
433 |
| new Word(SourceInfo.NONE, "MyInterface"), |
|
434 |
| new FormalParameter[0], |
|
435 |
| new ReferenceType[0]); |
|
436 |
1
| mdef.visit(_ibfv);
|
|
437 |
1
| assertEquals("There should be one error.", 1, errors.size());
|
|
438 |
1
| assertEquals("The error message should be correct.",
|
|
439 |
| "Only constructors can have the same name as the class they appear in, and constructors cannot " |
|
440 |
| + "appear in interfaces.", |
|
441 |
| errors.get(0).getFirst()); |
|
442 |
| |
|
443 |
| |
|
444 |
1
| AbstractMethodDef amd3 = new AbstractMethodDef(SourceInfo.NONE,
|
|
445 |
| _publicMav, |
|
446 |
| new TypeParameter[0], |
|
447 |
| new PrimitiveType(SourceInfo.NONE, "double"), |
|
448 |
| new Word(SourceInfo.NONE, "methodName2"), |
|
449 |
| new FormalParameter[0], |
|
450 |
| new ReferenceType[0]); |
|
451 |
1
| amd3.visit(_ibfv);
|
|
452 |
1
| assertEquals("There should still be one error", 1, errors.size());
|
|
453 |
1
| assertTrue("The method def should be public", _ibfv._enclosing.getMethods().get(1).hasModifier("public"));
|
|
454 |
| |
|
455 |
| |
|
456 |
1
| AbstractMethodDef amd4 = new AbstractMethodDef(SourceInfo.NONE,
|
|
457 |
| _privateMav, |
|
458 |
| new TypeParameter[0], |
|
459 |
| new PrimitiveType(SourceInfo.NONE, "double"), |
|
460 |
| new Word(SourceInfo.NONE, "methodName3"), |
|
461 |
| new FormalParameter[0], |
|
462 |
| new ReferenceType[0]); |
|
463 |
1
| amd4.visit(_ibfv);
|
|
464 |
1
| assertEquals("There should be two errors", 2, errors.size());
|
|
465 |
1
| assertEquals("The error message should be correct",
|
|
466 |
| "Interface methods cannot be private. They must be public." , |
|
467 |
| errors.get(1).getFirst()); |
|
468 |
| |
|
469 |
| |
|
470 |
1
| AbstractMethodDef amd5 = new AbstractMethodDef(SourceInfo.NONE,
|
|
471 |
| _protectedMav, |
|
472 |
| new TypeParameter[0], |
|
473 |
| new PrimitiveType(SourceInfo.NONE, "double"), |
|
474 |
| new Word(SourceInfo.NONE, "methodName4"), |
|
475 |
| new FormalParameter[0], |
|
476 |
| new ReferenceType[0]); |
|
477 |
1
| amd5.visit(_ibfv);
|
|
478 |
1
| assertEquals("There should be three errors", 3, errors.size());
|
|
479 |
1
| assertEquals("The error message should be correct",
|
|
480 |
| "Interface methods cannot be protected. They must be public." , |
|
481 |
| errors.get(2).getFirst()); |
|
482 |
| } |
|
483 |
| |
|
484 |
| |
|
485 |
1
| public void testForInnerClassDef() {
|
|
486 |
1
| _ibfv._enclosing = new SymbolData("MyInterface");
|
|
487 |
1
| _ibfv._enclosing.setInterface(true);
|
|
488 |
| |
|
489 |
| |
|
490 |
1
| LanguageLevelConverter._newSDs.clear();
|
|
491 |
| |
|
492 |
| |
|
493 |
1
| InnerClassDef cd1 =
|
|
494 |
| new InnerClassDef(SourceInfo.NONE, |
|
495 |
| _packageMav, |
|
496 |
| new Word(SourceInfo.NONE, "Bart"), |
|
497 |
| new TypeParameter[0], |
|
498 |
| new ClassOrInterfaceType(SourceInfo.NONE, "java.lang.Object", new Type[0]), |
|
499 |
| new ReferenceType[0], |
|
500 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
501 |
1
| InnerClassDef cd0 =
|
|
502 |
| new InnerClassDef(SourceInfo.NONE, |
|
503 |
| _packageMav, |
|
504 |
| new Word(SourceInfo.NONE, "Lisa"), |
|
505 |
| new TypeParameter[0], |
|
506 |
| new ClassOrInterfaceType(SourceInfo.NONE, "java.lang.Object", new Type[0]), |
|
507 |
| new ReferenceType[0], |
|
508 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[] {cd1})); |
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
| |
|
514 |
| |
|
515 |
| |
|
516 |
| |
|
517 |
| |
|
518 |
| |
|
519 |
| |
|
520 |
| |
|
521 |
| |
|
522 |
| |
|
523 |
| |
|
524 |
| |
|
525 |
| |
|
526 |
| |
|
527 |
1
| cd0.visit(_ibfv);
|
|
528 |
| |
|
529 |
1
| SymbolData sd0 = _ibfv._enclosing.getInnerClassOrInterface("Lisa");
|
|
530 |
1
| assertNotNull("Inner class Lisa exists", sd0);
|
|
531 |
| |
|
532 |
1
| assertEquals("Lisa should have the correct outer data", _ibfv._enclosing, sd0.getOuterData());
|
|
533 |
1
| assertTrue("_sd1 should be an interface", _sd1.isInterface());
|
|
534 |
1
| assertFalse("sd0 should be a class", sd0.isInterface());
|
|
535 |
1
| assertEquals("Lisa should have 0 methods", 0, sd0.getMethods().size());
|
|
536 |
| |
|
537 |
1
| SymbolData sd1 = sd0.getInnerClassOrInterface("Bart");
|
|
538 |
1
| assertNotNull("Inner class Bart exists", sd1);
|
|
539 |
| |
|
540 |
1
| assertEquals("Bart should have the correct outer data", sd0, sd1.getOuterData());
|
|
541 |
1
| assertFalse("sd1 should be a class", sd1.isInterface());
|
|
542 |
1
| assertEquals("Bart should have 0 methods", 0, sd1.getMethods().size());
|
|
543 |
| } |
|
544 |
| |
|
545 |
1
| public void testForInnerInterfaceDef() {
|
|
546 |
| |
|
547 |
1
| InnerInterfaceDef cd1 =
|
|
548 |
| new InnerInterfaceDef(SourceInfo.NONE, _packageMav, new Word(SourceInfo.NONE, "Bart"), |
|
549 |
| new TypeParameter[0], new ReferenceType[0], |
|
550 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
551 |
| |
|
552 |
1
| InnerInterfaceDef cd0 =
|
|
553 |
| new InnerInterfaceDef(SourceInfo.NONE, _packageMav, new Word(SourceInfo.NONE, "Lisa"), |
|
554 |
| new TypeParameter[0], new ReferenceType[0], |
|
555 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[] {cd1})); |
|
556 |
| |
|
557 |
| |
|
558 |
| |
|
559 |
| |
|
560 |
| |
|
561 |
| |
|
562 |
| |
|
563 |
| |
|
564 |
| |
|
565 |
| |
|
566 |
| |
|
567 |
| |
|
568 |
| |
|
569 |
| |
|
570 |
| |
|
571 |
| |
|
572 |
| |
|
573 |
| |
|
574 |
| |
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
1
| cd0.visit(_ibfv);
|
|
579 |
| |
|
580 |
1
| SymbolData sd0 = _ibfv._enclosing.getInnerClassOrInterface("Lisa");
|
|
581 |
1
| assertNotNull("Inner interfacae Lisa exists", sd0);
|
|
582 |
| |
|
583 |
1
| assertEquals("Lisa should have the correct outer data", _ibfv._enclosing, sd0.getOuterData());
|
|
584 |
1
| assertTrue("_sd1 should be an interface", _sd1.isInterface());
|
|
585 |
1
| assertTrue("sd0 should be a interface", sd0.isInterface());
|
|
586 |
1
| assertEquals("Lisa should have 0 methods", 0, sd0.getMethods().size());
|
|
587 |
| |
|
588 |
1
| SymbolData sd1 = sd0.getInnerClassOrInterface("Bart");
|
|
589 |
1
| assertNotNull("Inner interface Bart exists", sd1);
|
|
590 |
| |
|
591 |
1
| assertEquals("Bart should have the correct outer data", sd0, sd1.getOuterData());
|
|
592 |
1
| assertTrue("sd1 should be an interface", sd1.isInterface());
|
|
593 |
1
| assertEquals("Bart should have 0 methods", 0, sd1.getMethods().size());
|
|
594 |
| } |
|
595 |
| |
|
596 |
1
| public void testForConstructorDef() {
|
|
597 |
| |
|
598 |
1
| ConstructorDef cd =
|
|
599 |
| new ConstructorDef(SourceInfo.NONE, new Word(SourceInfo.NONE, "MyClass"), |
|
600 |
| _publicMav, new FormalParameter[0], new ReferenceType[0], |
|
601 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
602 |
| |
|
603 |
| |
|
604 |
1
| cd.visit(_ibfv);
|
|
605 |
1
| assertEquals("There should now be one error", 1, errors.size());
|
|
606 |
1
| assertEquals("The error message should be correct", "Constructor definitions cannot appear in interfaces",
|
|
607 |
| errors.get(0).getFirst()); |
|
608 |
| |
|
609 |
| } |
|
610 |
1
| public void testDummy() { }
|
|
611 |
| } |
|
612 |
| } |