|
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 edu.rice.cs.javalanglevels; |
|
38 |
| |
|
39 |
| import org.objectweb.asm.*; |
|
40 |
| import edu.rice.cs.javalanglevels.tree.*; |
|
41 |
| import edu.rice.cs.javalanglevels.tree.Type; |
|
42 |
| import edu.rice.cs.javalanglevels.parser.JExprParser; |
|
43 |
| import edu.rice.cs.javalanglevels.parser.ParseException; |
|
44 |
| import edu.rice.cs.javalanglevels.util.Log; |
|
45 |
| import edu.rice.cs.javalanglevels.util.Utilities; |
|
46 |
| import java.util.*; |
|
47 |
| import java.io.*; |
|
48 |
| import edu.rice.cs.plt.reflect.JavaVersion; |
|
49 |
| import edu.rice.cs.plt.iter.*; |
|
50 |
| import edu.rice.cs.plt.io.IOUtil; |
|
51 |
| |
|
52 |
| import junit.framework.TestCase; |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| public class LanguageLevelVisitor extends JExpressionIFPrunableDepthFirstVisitor { |
|
64 |
| |
|
65 |
| public static final ModifiersAndVisibility PUBLIC_MAV = |
|
66 |
| new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"public"}); |
|
67 |
| public static final ModifiersAndVisibility PROTECTED_MAV = |
|
68 |
| new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"protected"}); |
|
69 |
| public static final ModifiersAndVisibility PRIVATE_MAV = |
|
70 |
| new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"private"}); |
|
71 |
| public static final ModifiersAndVisibility PACKAGE_MAV = |
|
72 |
| new ModifiersAndVisibility(SourceInfo.NONE, new String[0]); |
|
73 |
| public static final ModifiersAndVisibility FINAL_MAV = |
|
74 |
| new ModifiersAndVisibility(SourceInfo.NONE, new String[]{"final"}); |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| protected static LinkedList<Pair<String, JExpressionIF>> errors; |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| public final Symboltable symbolTable; |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| static Hashtable<String, Triple<SourceInfo, LanguageLevelVisitor, SymbolData>> continuations; |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| static LinkedList<Command> fixUps; |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| static LinkedList<Pair<LanguageLevelVisitor, SourceFile>> visitedFiles; |
|
101 |
| |
|
102 |
| |
|
103 |
| static boolean _errorAdded; |
|
104 |
| |
|
105 |
| |
|
106 |
| File _file; |
|
107 |
| |
|
108 |
| |
|
109 |
| String _package; |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| String _enclosingClassName; |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| LinkedList<String> _importedFiles; |
|
119 |
| |
|
120 |
| |
|
121 |
| LinkedList<String> _importedPackages; |
|
122 |
| |
|
123 |
| |
|
124 |
| public HashMap<String, SymbolData> _genericTypes; |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| HashSet<String> _classesInThisFile; |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| protected static final Log _log = new Log("LLConverter.txt", false); |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
2138
| public LanguageLevelVisitor(File file,
|
|
144 |
| String packageName, |
|
145 |
| String enclosingClassName, |
|
146 |
| LinkedList<String> importedFiles, |
|
147 |
| LinkedList<String> importedPackages, |
|
148 |
| HashSet<String> classesInThisFile, |
|
149 |
| Hashtable<String, Triple<SourceInfo, LanguageLevelVisitor, SymbolData>> continuations, |
|
150 |
| LinkedList<Command> fixUps, |
|
151 |
| HashMap<String, SymbolData> genericTypes) { |
|
152 |
2138
| _file = file;
|
|
153 |
2138
| _package = packageName;
|
|
154 |
2138
| _enclosingClassName = enclosingClassName;
|
|
155 |
2138
| if (_enclosingClassName != null && _enclosingClassName.startsWith("null")) assert false;
|
|
156 |
2138
| _importedFiles = importedFiles;
|
|
157 |
2138
| _importedPackages = importedPackages;
|
|
158 |
2138
| _classesInThisFile = classesInThisFile;
|
|
159 |
| |
|
160 |
2138
| this.continuations = continuations;
|
|
161 |
2138
| this.fixUps = fixUps;
|
|
162 |
2138
| _genericTypes = genericTypes;
|
|
163 |
| |
|
164 |
2138
| symbolTable = LanguageLevelConverter.symbolTable;
|
|
165 |
| |
|
166 |
2138
| assert fixUps != null;
|
|
167 |
2138
| assert _genericTypes != null;
|
|
168 |
| |
|
169 |
| |
|
170 |
135
| if (! _importedPackages.contains("java.lang")) _importedPackages.addFirst("java.lang");
|
|
171 |
| |
|
172 |
2138
| LanguageLevelConverter.loadSymbolTable();
|
|
173 |
| } |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
491
| public LanguageLevelVisitor(File file,
|
|
184 |
| String packageName, |
|
185 |
| String enclosingClassName, |
|
186 |
| LinkedList<String> importedFiles, |
|
187 |
| LinkedList<String> importedPackages, |
|
188 |
| HashSet<String> classesInThisFile, |
|
189 |
| Hashtable<String, Triple<SourceInfo, LanguageLevelVisitor, SymbolData>> continuations, |
|
190 |
| LinkedList<Command> fixUps) { |
|
191 |
491
| this(file, packageName, enclosingClassName, importedFiles, importedPackages, classesInThisFile, continuations, fixUps,
|
|
192 |
| new HashMap<String, SymbolData>()); |
|
193 |
| } |
|
194 |
| |
|
195 |
| |
|
196 |
0
| protected void _resetNonStaticFields() {
|
|
197 |
0
| _file = new File("");
|
|
198 |
0
| _enclosingClassName = null;
|
|
199 |
0
| _package = "";
|
|
200 |
0
| _importedFiles = new LinkedList<String>();
|
|
201 |
0
| _importedPackages = new LinkedList<String>();
|
|
202 |
| } |
|
203 |
| |
|
204 |
| |
|
205 |
136
| public static String getFieldAccessorName(String name) { return name; }
|
|
206 |
| |
|
207 |
| |
|
208 |
0
| public File getFile() { return _file; }
|
|
209 |
| |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
14
| protected boolean isConstructor(Data d) {
|
|
214 |
1
| if ( !(d instanceof MethodData) ) return false;
|
|
215 |
13
| MethodData md = (MethodData) d;
|
|
216 |
13
| SymbolData rt = md.getReturnType();
|
|
217 |
13
| SymbolData sd = md.getSymbolData();
|
|
218 |
| |
|
219 |
13
| return (rt != null && sd != null && rt.getName().indexOf(md.getName()) != -1 && rt == sd);
|
|
220 |
| } |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
| |
|
225 |
0
| public LanguageLevelVisitor newClassBodyVisitor(SymbolData anonSD, String anonName) {
|
|
226 |
0
| return new ClassBodyFullJavaVisitor(anonSD, anonName, _file, _package, _importedFiles, _importedPackages,
|
|
227 |
| _classesInThisFile, continuations, fixUps); |
|
228 |
| } |
|
229 |
| |
|
230 |
| |
|
231 |
| |
|
232 |
70144
| public static String getUnqualifiedClassName(String className) {
|
|
233 |
70144
| int lastIndexOfDot = className.lastIndexOf('.');
|
|
234 |
70144
| if (lastIndexOfDot != -1) {
|
|
235 |
66552
| className = className.substring(lastIndexOfDot + 1);
|
|
236 |
| } |
|
237 |
70144
| int lastIndexOfDollar = className.lastIndexOf('$');
|
|
238 |
70144
| if (lastIndexOfDollar != -1) {
|
|
239 |
10124
| className = className.substring(lastIndexOfDollar + 1);
|
|
240 |
| } |
|
241 |
| |
|
242 |
70144
| while (className.length() > 0 && Character.isDigit(className.charAt(0))) {
|
|
243 |
2182
| className = className.substring(1, className.length());
|
|
244 |
| } |
|
245 |
70144
| return className;
|
|
246 |
| } |
|
247 |
| |
|
248 |
| |
|
249 |
222
| protected static String[] referenceType2String(ReferenceType[] rts) {
|
|
250 |
222
| String[] throwStrings = new String[rts.length];
|
|
251 |
222
| for (int i = 0; i < throwStrings.length; i++) {
|
|
252 |
9
| throwStrings[i] = rts[i].getName();
|
|
253 |
| } |
|
254 |
222
| return throwStrings;
|
|
255 |
| } |
|
256 |
| |
|
257 |
| |
|
258 |
| |
|
259 |
| |
|
260 |
| |
|
261 |
| |
|
262 |
| |
|
263 |
| |
|
264 |
| |
|
265 |
| |
|
266 |
3398
| public static boolean isJavaLibraryClass(String className) {
|
|
267 |
3398
| return className.startsWith("java.") ||
|
|
268 |
| className.startsWith("javax.") || |
|
269 |
| className.startsWith("org.ietf.") || |
|
270 |
| className.startsWith("org.omg.") || |
|
271 |
| className.startsWith("org.w3c.") || |
|
272 |
| className.startsWith("org.xml.") || |
|
273 |
| className.startsWith("sun.") || |
|
274 |
| className.startsWith("junit.framework."); |
|
275 |
| } |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
0
| public static boolean isDuplicateVariableData(LinkedList<VariableData> vds, VariableData toInsert) {
|
|
281 |
0
| for (int i = 0; i<vds.size(); i++) {
|
|
282 |
0
| VariableData temp = vds.get(i);
|
|
283 |
0
| if (temp.getName().equals(toInsert.getName())) {
|
|
284 |
0
| return true;
|
|
285 |
| } |
|
286 |
| } |
|
287 |
0
| return false;
|
|
288 |
| } |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
| |
|
294 |
19
| public ArrayData defineArraySymbolData(SymbolData eltSd, LanguageLevelVisitor llv, SourceInfo si) {
|
|
295 |
19
| ArrayData arraySd = new ArrayData(eltSd, llv, si);
|
|
296 |
| |
|
297 |
19
| symbolTable.put(arraySd.getName(), arraySd);
|
|
298 |
19
| return arraySd;
|
|
299 |
| } |
|
300 |
| |
|
301 |
| |
|
302 |
26
| private SymbolData getArraySymbolData(String eltClassName, SourceInfo si, boolean addError, boolean checkImports) {
|
|
303 |
26
| return _getArraySymbolData(eltClassName, si, addError, checkImports );
|
|
304 |
| } |
|
305 |
| |
|
306 |
| |
|
307 |
| |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
26
| private SymbolData _getArraySymbolData(String eltClassName, SourceInfo si, boolean addError, boolean checkImports
|
|
314 |
| ) { |
|
315 |
| |
|
316 |
| |
|
317 |
| |
|
318 |
26
| SymbolData eltSD = getSymbolData(eltClassName, si, addError, checkImports);
|
|
319 |
26
| if (eltSD != null) {
|
|
320 |
| |
|
321 |
21
| SymbolData sd = symbolTable.get(eltSD.getName() + "[]");
|
|
322 |
11
| if (sd != null) return sd;
|
|
323 |
10
| else return defineArraySymbolData(eltSD, this, si );
|
|
324 |
| } |
|
325 |
5
| else return null;
|
|
326 |
| } |
|
327 |
| |
|
328 |
| |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
| |
|
337 |
40
| private SymbolData _getQualifiedArraySymbolData(String eltClassName, SourceInfo si, boolean resolve,
|
|
338 |
| boolean fromClassFile ) { |
|
339 |
| |
|
340 |
40
| SymbolData eltSD = getQualifiedSymbolData(eltClassName, si, resolve, fromClassFile, true );
|
|
341 |
40
| if (eltSD != null) {
|
|
342 |
9
| SymbolData sd = symbolTable.get(eltSD.getName() + "[]");
|
|
343 |
0
| if (sd != null) return sd;
|
|
344 |
9
| else return defineArraySymbolData(eltSD, this, si );
|
|
345 |
| } |
|
346 |
31
| else return null;
|
|
347 |
| } |
|
348 |
| |
|
349 |
| |
|
350 |
| |
|
351 |
| |
|
352 |
| |
|
353 |
| |
|
354 |
| |
|
355 |
| |
|
356 |
| |
|
357 |
| |
|
358 |
| |
|
359 |
| |
|
360 |
14
| protected SymbolData _getSymbolDataFromFileSystem(final String qualifiedClassName, SourceInfo si, boolean resolve,
|
|
361 |
| boolean addError) { |
|
362 |
| |
|
363 |
14
| SymbolData sd = symbolTable.get(qualifiedClassName);
|
|
364 |
7
| if (sd != null && (! sd.isContinuation() || ! resolve)) return sd;
|
|
365 |
| |
|
366 |
| |
|
367 |
| |
|
368 |
| |
|
369 |
| |
|
370 |
| |
|
371 |
| |
|
372 |
| |
|
373 |
| |
|
374 |
7
| String qualifiedClassNameWithSlashes =
|
|
375 |
| qualifiedClassName.replace('.', System.getProperty("file.separator").charAt(0)); |
|
376 |
7
| File _fileParent = _file.getParentFile();
|
|
377 |
| |
|
378 |
7
| String programRoot = (_fileParent == null) ? "" : _fileParent.getAbsolutePath();
|
|
379 |
7
| assert (programRoot != null);
|
|
380 |
| |
|
381 |
7
| final String path;
|
|
382 |
| |
|
383 |
7
| if (programRoot.length() > 0) {
|
|
384 |
6
| String packageWithSlashes = _package.replace('.', System.getProperty("file.separator").charAt(0));
|
|
385 |
| |
|
386 |
6
| int indexOfPackage = programRoot.lastIndexOf(packageWithSlashes);
|
|
387 |
1
| if (indexOfPackage < 0) path = qualifiedClassName;
|
|
388 |
| else { |
|
389 |
5
| programRoot = programRoot.substring(0, indexOfPackage);
|
|
390 |
5
| path = programRoot + System.getProperty("file.separator") + qualifiedClassNameWithSlashes;
|
|
391 |
| } |
|
392 |
| } |
|
393 |
| else { |
|
394 |
1
| path = qualifiedClassNameWithSlashes;
|
|
395 |
| } |
|
396 |
| |
|
397 |
7
| String dirPath;
|
|
398 |
7
| String newPackage = "";
|
|
399 |
7
| int lastSlashIndex = qualifiedClassNameWithSlashes.lastIndexOf(System.getProperty("file.separator"));
|
|
400 |
7
| if (lastSlashIndex != -1) {
|
|
401 |
2
| String newPackageWithSlashes = qualifiedClassNameWithSlashes.substring(0, lastSlashIndex);
|
|
402 |
2
| dirPath = programRoot + System.getProperty("file.separator") + newPackageWithSlashes;
|
|
403 |
2
| newPackage = newPackageWithSlashes.replace(System.getProperty("file.separator").charAt(0), '.');
|
|
404 |
| } |
|
405 |
| else { |
|
406 |
5
| int lastPathSlashIndex = path.lastIndexOf(System.getProperty("file.separator"));
|
|
407 |
4
| if (lastPathSlashIndex != -1) dirPath = path.substring(0, lastPathSlashIndex);
|
|
408 |
1
| else dirPath = "";
|
|
409 |
| } |
|
410 |
| |
|
411 |
| |
|
412 |
| |
|
413 |
7
| File classFile = new File(path + ".class");
|
|
414 |
| |
|
415 |
| |
|
416 |
7
| File[] sourceFiles = new File(dirPath).listFiles(new FileFilter() {
|
|
417 |
152
| public boolean accept(File f) {
|
|
418 |
152
| try {
|
|
419 |
152
| f = f.getCanonicalFile();
|
|
420 |
152
| return new File(path + ".dj").getCanonicalFile().equals(f) ||
|
|
421 |
| new File(path + ".dj0").getCanonicalFile().equals(f) || |
|
422 |
| new File(path + ".dj1").getCanonicalFile().equals(f) || |
|
423 |
| new File(path + ".dj2").getCanonicalFile().equals(f) || |
|
424 |
| new File(path + ".java").getCanonicalFile().equals(f); |
|
425 |
| } |
|
426 |
0
| catch (IOException e) { return false; }
|
|
427 |
| }}); |
|
428 |
| |
|
429 |
7
| File sourceFile = null;
|
|
430 |
7
| if (sourceFiles != null) {
|
|
431 |
5
| long mostRecentTime = 0;
|
|
432 |
5
| for (File f : sourceFiles) {
|
|
433 |
5
| long currentLastModified = f.lastModified();
|
|
434 |
5
| if (f.exists() && mostRecentTime < currentLastModified) {
|
|
435 |
5
| mostRecentTime = currentLastModified;
|
|
436 |
5
| sourceFile = f;
|
|
437 |
| } |
|
438 |
| } |
|
439 |
| } |
|
440 |
| |
|
441 |
| |
|
442 |
| |
|
443 |
| |
|
444 |
| |
|
445 |
| |
|
446 |
| |
|
447 |
| |
|
448 |
| |
|
449 |
7
| if (sourceFile != null) {
|
|
450 |
| |
|
451 |
4
| if (! resolve) {
|
|
452 |
0
| assert sd == null;
|
|
453 |
0
| sd = makeContinuation(si, qualifiedClassName);
|
|
454 |
0
| return sd;
|
|
455 |
| |
|
456 |
| |
|
457 |
| |
|
458 |
| |
|
459 |
| |
|
460 |
| |
|
461 |
| } |
|
462 |
| |
|
463 |
4
| long classModTime = classFile.lastModified();
|
|
464 |
1
| if (classModTime == 0L) return null;
|
|
465 |
| |
|
466 |
3
| if (sourceFile.lastModified() > classModTime) {
|
|
467 |
0
| if (addError) {
|
|
468 |
0
| _addAndIgnoreError("The file " + sourceFile.getAbsolutePath() +
|
|
469 |
| " needs to be recompiled; it's class files either do not exist or are out of date.", |
|
470 |
| new NullLiteral(si)); |
|
471 |
| } |
|
472 |
0
| return null;
|
|
473 |
| } |
|
474 |
| } |
|
475 |
| |
|
476 |
| |
|
477 |
| |
|
478 |
6
| if (classFile.exists()) {
|
|
479 |
| |
|
480 |
4
| _log.log("Reading classFile " + qualifiedClassName);
|
|
481 |
4
| sd = LanguageLevelConverter._classFile2SymbolData(qualifiedClassName, programRoot);
|
|
482 |
4
| if (sd == null) {
|
|
483 |
0
| if (addError) {
|
|
484 |
0
| _addAndIgnoreError("File " + classFile + " is not a valid class file.", new NullLiteral(si));
|
|
485 |
| } |
|
486 |
0
| return null;
|
|
487 |
| } |
|
488 |
4
| _log.log("Returning symbol constructed by loading class file");
|
|
489 |
4
| return sd;
|
|
490 |
| } |
|
491 |
2
| return SymbolData.NOT_FOUND;
|
|
492 |
| } |
|
493 |
| |
|
494 |
| |
|
495 |
6
| public SymbolData resolveSymbol(SourceInfo si, SymbolData cont) {
|
|
496 |
| |
|
497 |
6
| return getQualifiedSymbolData(cont.getName(), si, true);
|
|
498 |
| } |
|
499 |
| |
|
500 |
| |
|
501 |
| |
|
502 |
| |
|
503 |
| |
|
504 |
| |
|
505 |
1461
| public SymbolData getSymbolData(String className, SourceInfo si) {
|
|
506 |
1461
| return getSymbolData(className, si, true, true);
|
|
507 |
| } |
|
508 |
| |
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
| |
|
514 |
| |
|
515 |
257
| protected SymbolData getSymbolData(String className, SourceInfo si, boolean addError) {
|
|
516 |
257
| return this.getSymbolData(className, si, addError, true);
|
|
517 |
| } |
|
518 |
| |
|
519 |
| |
|
520 |
| |
|
521 |
| |
|
522 |
| |
|
523 |
| |
|
524 |
3149
| protected SymbolData getSymbolData(String className, SourceInfo si, boolean addError, boolean checkImports) {
|
|
525 |
3149
| return getSymbolData(_file, _package, _importedFiles, _importedPackages, _enclosingClassName,
|
|
526 |
| className, si, addError, checkImports); |
|
527 |
| } |
|
528 |
| |
|
529 |
| |
|
530 |
| |
|
531 |
| |
|
532 |
| |
|
533 |
| |
|
534 |
| |
|
535 |
| |
|
536 |
| |
|
537 |
| |
|
538 |
| |
|
539 |
| |
|
540 |
| |
|
541 |
| |
|
542 |
| |
|
543 |
| |
|
544 |
| |
|
545 |
| |
|
546 |
| |
|
547 |
| |
|
548 |
| |
|
549 |
| |
|
550 |
| |
|
551 |
| |
|
552 |
| |
|
553 |
| |
|
554 |
| |
|
555 |
3149
| protected SymbolData getSymbolData(File file,
|
|
556 |
| String pkg, |
|
557 |
| LinkedList<String> importedFiles, |
|
558 |
| LinkedList<String> importedPackages, |
|
559 |
| String enclosingClassName, |
|
560 |
| String className, |
|
561 |
| SourceInfo si, |
|
562 |
| boolean addError, |
|
563 |
| boolean checkImports) { |
|
564 |
| |
|
565 |
3149
| if (className == null) {
|
|
566 |
| |
|
567 |
| assert false; |
|
568 |
| } |
|
569 |
| |
|
570 |
| |
|
571 |
3149
| SymbolData existingSD = getQualifiedSymbolData(className, si, false, false, addError);
|
|
572 |
2379
| if (existingSD != null) return existingSD;
|
|
573 |
| |
|
574 |
770
| if (className.endsWith("[]")) {
|
|
575 |
21
| String eltClassName = className.substring(0, className.length() - 2);
|
|
576 |
| |
|
577 |
21
| return getArraySymbolData(
|
|
578 |
| eltClassName, si, addError, checkImports); |
|
579 |
| } |
|
580 |
| |
|
581 |
| |
|
582 |
749
| String qualClassName = getQualifiedClassName(pkg, className);
|
|
583 |
749
| existingSD = getQualifiedSymbolData(qualClassName, si);
|
|
584 |
8
| if (existingSD != null) return existingSD;
|
|
585 |
| |
|
586 |
| |
|
587 |
741
| if (enclosingClassName != null) {
|
|
588 |
| |
|
589 |
| |
|
590 |
| |
|
591 |
377
| SymbolData enclosingSD = getQualifiedSymbolData(enclosingClassName, si);
|
|
592 |
377
| if (enclosingSD != null) {
|
|
593 |
371
| SymbolData sd = enclosingSD.getInnerClassOrInterface(className);
|
|
594 |
13
| if (sd != null) return sd;
|
|
595 |
| |
|
596 |
| |
|
597 |
| |
|
598 |
| |
|
599 |
| |
|
600 |
| } |
|
601 |
| } |
|
602 |
| |
|
603 |
| |
|
604 |
| |
|
605 |
728
| if (className.indexOf('.') == -1) {
|
|
606 |
| |
|
607 |
| |
|
608 |
659
| if (checkImports) {
|
|
609 |
| |
|
610 |
| |
|
611 |
| |
|
612 |
| |
|
613 |
658
| Iterator<String> iter = importedFiles.iterator();
|
|
614 |
658
| while (iter.hasNext()) {
|
|
615 |
38
| String s = iter.next();
|
|
616 |
38
| if (s.endsWith(className)) {
|
|
617 |
13
| SymbolData importSD = symbolTable.get(s);
|
|
618 |
| |
|
619 |
| |
|
620 |
13
| return importSD;
|
|
621 |
| } |
|
622 |
| } |
|
623 |
| } |
|
624 |
| |
|
625 |
| |
|
626 |
| |
|
627 |
646
| SymbolData resultSD = null;
|
|
628 |
646
| assert importedPackages.contains("java.lang");
|
|
629 |
| |
|
630 |
646
| for (String prefix: importedPackages) {
|
|
631 |
685
| String s = prefix + '.' + className;
|
|
632 |
| |
|
633 |
685
| SymbolData sD = getQualifiedSymbolData(s, si, false, false, false);
|
|
634 |
| |
|
635 |
| |
|
636 |
685
| if (sD != null) {
|
|
637 |
382
| if (resultSD == null || resultSD.equals(sD)) resultSD = sD;
|
|
638 |
| else { |
|
639 |
1
| if (addError) {
|
|
640 |
1
| _addAndIgnoreError("The class name " + qualClassName + " is ambiguous. It could be " + resultSD.getName()
|
|
641 |
| + " or " + sD.getName(), new NullLiteral(si)); |
|
642 |
1
| return null;
|
|
643 |
| } |
|
644 |
| } |
|
645 |
| } |
|
646 |
| } |
|
647 |
376
| if (resultSD != null) return resultSD;
|
|
648 |
269
| else return null;
|
|
649 |
| } |
|
650 |
| |
|
651 |
| |
|
652 |
| |
|
653 |
69
| int indexOfNextDot = 0;
|
|
654 |
| |
|
655 |
69
| SymbolData sd;
|
|
656 |
69
| int length = className.length();
|
|
657 |
69
| while (indexOfNextDot != length) {
|
|
658 |
150
| indexOfNextDot = className.indexOf('.', indexOfNextDot + 1);
|
|
659 |
51
| if (indexOfNextDot == -1) { indexOfNextDot = length; }
|
|
660 |
150
| String prefix = className.substring(0, indexOfNextDot);
|
|
661 |
| |
|
662 |
| |
|
663 |
150
| sd = getQualifiedSymbolData(prefix, si, false, false, false);
|
|
664 |
150
| if (sd != null && sd != SymbolData.AMBIGUOUS_REFERENCE) {
|
|
665 |
23
| String outerClassName = prefix;
|
|
666 |
23
| String innerClassName = "";
|
|
667 |
23
| if (indexOfNextDot != length) {
|
|
668 |
23
| SymbolData outerClassSD = sd;
|
|
669 |
23
| innerClassName = className.substring(indexOfNextDot + 1);
|
|
670 |
| |
|
671 |
| |
|
672 |
23
| sd = outerClassSD.getInnerClassOrInterface(innerClassName);
|
|
673 |
18
| if (sd != null) return sd;
|
|
674 |
| |
|
675 |
| |
|
676 |
| |
|
677 |
| |
|
678 |
| |
|
679 |
| } |
|
680 |
| } |
|
681 |
| } |
|
682 |
51
| return null;
|
|
683 |
| } |
|
684 |
| |
|
685 |
| |
|
686 |
| |
|
687 |
| |
|
688 |
| |
|
689 |
| |
|
690 |
| |
|
691 |
| |
|
692 |
21
| protected SymbolData getSymbolData(TypeData lhs, String name, SourceInfo si, boolean addError) {
|
|
693 |
| |
|
694 |
21
| boolean checkImports = false;
|
|
695 |
| |
|
696 |
5
| if (lhs == null) return null;
|
|
697 |
| |
|
698 |
16
| else if (lhs instanceof PackageData) {
|
|
699 |
0
| String qualClassName = lhs.getName() + '.' + name;
|
|
700 |
0
| return getQualifiedSymbolData(qualClassName, si, false, false, addError);
|
|
701 |
| } |
|
702 |
| |
|
703 |
| else { |
|
704 |
16
| SymbolData result = lhs.getInnerClassOrInterface(name);
|
|
705 |
16
| if (result == SymbolData.AMBIGUOUS_REFERENCE) {
|
|
706 |
0
| if (addError) { _addAndIgnoreError("Ambiguous reference to class or interface " + name, new NullLiteral(si)); }
|
|
707 |
0
| return null;
|
|
708 |
| } |
|
709 |
16
| return result;
|
|
710 |
| } |
|
711 |
| } |
|
712 |
| |
|
713 |
| |
|
714 |
| |
|
715 |
235
| protected SymbolData getQualifiedSymbolData(String qualClassName) {
|
|
716 |
235
| return getQualifiedSymbolData(qualClassName, SourceInfo.NONE);
|
|
717 |
| } |
|
718 |
| |
|
719 |
| |
|
720 |
| |
|
721 |
1423
| protected SymbolData getQualifiedSymbolData(String qualClassName, SourceInfo si) {
|
|
722 |
1423
| return getQualifiedSymbolData(qualClassName, si, false, false, true);
|
|
723 |
| } |
|
724 |
| |
|
725 |
| |
|
726 |
| |
|
727 |
| |
|
728 |
57
| protected SymbolData getQualifiedSymbolData(String qualClassName, SourceInfo si, boolean resolve) {
|
|
729 |
57
| return getQualifiedSymbolData(qualClassName, si, resolve, false, true);
|
|
730 |
| } |
|
731 |
| |
|
732 |
| |
|
733 |
| |
|
734 |
| |
|
735 |
| |
|
736 |
| |
|
737 |
| |
|
738 |
| |
|
739 |
| |
|
740 |
| |
|
741 |
| |
|
742 |
| |
|
743 |
| |
|
744 |
| |
|
745 |
5727
| protected SymbolData getQualifiedSymbolData(String qualClassName, SourceInfo si, boolean resolve, boolean fromClassFile,
|
|
746 |
| boolean addError) { |
|
747 |
5727
| assert qualClassName != null;
|
|
748 |
| |
|
749 |
| |
|
750 |
| |
|
751 |
5727
| if (qualClassName.equals("java.lang.Throwable")) {
|
|
752 |
| |
|
753 |
| |
|
754 |
| } |
|
755 |
| |
|
756 |
5727
| assert (qualClassName != null && ! qualClassName.equals(""));
|
|
757 |
| |
|
758 |
| |
|
759 |
| |
|
760 |
5727
| SymbolData sd = LanguageLevelConverter._getPrimitiveSymbolData(qualClassName);
|
|
761 |
5727
| if (sd != null) {
|
|
762 |
| |
|
763 |
599
| return sd;
|
|
764 |
| } |
|
765 |
| |
|
766 |
| |
|
767 |
| |
|
768 |
5128
| String name = getUnqualifiedClassName(qualClassName);
|
|
769 |
5128
| if (_genericTypes.containsKey(name)) {
|
|
770 |
| |
|
771 |
0
| return _genericTypes.get(name);
|
|
772 |
| } |
|
773 |
| |
|
774 |
| |
|
775 |
5128
| SymbolData existingSD = symbolTable.get(qualClassName);
|
|
776 |
2864
| if (existingSD != null && (! resolve || ! existingSD.isContinuation())) return existingSD;
|
|
777 |
| |
|
778 |
| |
|
779 |
2264
| if (qualClassName.endsWith("[]"))
|
|
780 |
40
| return _getQualifiedArraySymbolData(qualClassName.substring(0, qualClassName.length() - 2), si, resolve,
|
|
781 |
| fromClassFile); |
|
782 |
| |
|
783 |
2224
| SymbolData genericBinding = _genericTypes.get(qualClassName);
|
|
784 |
0
| if (genericBinding != null) return genericBinding;
|
|
785 |
| |
|
786 |
| |
|
787 |
2224
| if (isJavaLibraryClass(qualClassName)) {
|
|
788 |
695
| _log.log("Calling _classFile2SymbolData");
|
|
789 |
695
| SymbolData cfSD = LanguageLevelConverter._classFile2SymbolData(qualClassName, null);
|
|
790 |
695
| if (! qualClassName.startsWith("java.") && ! qualClassName.startsWith("sun."))
|
|
791 |
| |
|
792 |
72
| assert cfSD == null || symbolTable.contains(cfSD);
|
|
793 |
695
| return cfSD;
|
|
794 |
| } |
|
795 |
| |
|
796 |
1529
| if (_classesInThisFile.contains(qualClassName))
|
|
797 |
12
| return makeContinuation(si, qualClassName);
|
|
798 |
| |
|
799 |
| |
|
800 |
1517
| if (resolve) {
|
|
801 |
2
| SymbolData newSd = _getSymbolDataFromFileSystem(qualClassName, si, true, true);
|
|
802 |
2
| if (newSd != null && newSd != SymbolData.NOT_FOUND) {
|
|
803 |
2
| _log.log("Returning " + sd + " from file system");
|
|
804 |
2
| return newSd;
|
|
805 |
| } |
|
806 |
| else { |
|
807 |
| |
|
808 |
0
| _addAndIgnoreError("The class " + qualClassName + " was not found.", new NullLiteral(si));
|
|
809 |
| assert false; |
|
810 |
| } |
|
811 |
| } |
|
812 |
1515
| return null;
|
|
813 |
| } |
|
814 |
| |
|
815 |
| |
|
816 |
| |
|
817 |
| |
|
818 |
| |
|
819 |
| |
|
820 |
| |
|
821 |
880
| protected String getQualifiedClassName(String className) { return getQualifiedClassName(_package, className); }
|
|
822 |
| |
|
823 |
| |
|
824 |
| |
|
825 |
| |
|
826 |
| |
|
827 |
| |
|
828 |
1629
| public static String getQualifiedClassName(String pkg, String className) {
|
|
829 |
| |
|
830 |
112
| if (! pkg.equals("") && ! className.startsWith(pkg)) return pkg + '.' + className;
|
|
831 |
1517
| else return className;
|
|
832 |
| } |
|
833 |
| |
|
834 |
| |
|
835 |
0
| protected SymbolData addInnerSymbolData(SourceInfo si, String qualifiedTypeName, Data enclosing) {
|
|
836 |
0
| SymbolData sd = makeContinuation(si, qualifiedTypeName);
|
|
837 |
0
| SymbolData enclosingSD = enclosing.getSymbolData();
|
|
838 |
| |
|
839 |
0
| enclosing.getSymbolData().addInnerClass(sd);
|
|
840 |
0
| sd.setOuterData(enclosingSD);
|
|
841 |
0
| return sd;
|
|
842 |
| } |
|
843 |
| |
|
844 |
| |
|
845 |
| |
|
846 |
| |
|
847 |
| |
|
848 |
44
| protected SymbolData makeContinuation(SourceInfo si, String qualClassName) {
|
|
849 |
| |
|
850 |
44
| if (qualClassName.equals("D.E")) assert false;
|
|
851 |
44
| SymbolData sd = new SymbolData(qualClassName);
|
|
852 |
44
| symbolTable.put(qualClassName, sd);
|
|
853 |
44
| continuations.put(qualClassName, new Triple<SourceInfo, LanguageLevelVisitor, SymbolData>(si, this, sd));
|
|
854 |
| |
|
855 |
44
| return sd;
|
|
856 |
| } |
|
857 |
| |
|
858 |
| |
|
859 |
| |
|
860 |
| |
|
861 |
224
| protected SymbolData _lookupTypeFromWithinClass(ReferenceType rt, String qualifiedClassName) {
|
|
862 |
| |
|
863 |
224
| String rtName = rt.getName();
|
|
864 |
224
| SourceInfo si = rt.getSourceInfo();
|
|
865 |
| |
|
866 |
224
| assert _importedPackages.contains("java.lang");
|
|
867 |
224
| SymbolData sD = getSymbolData(rtName, si, false);
|
|
868 |
| |
|
869 |
| |
|
870 |
224
| if (sD == null && qualifiedClassName != null) {
|
|
871 |
0
| SymbolData sd = getQualifiedSymbolData(qualifiedClassName, SourceInfo.NONE);
|
|
872 |
0
| sD = sd.getInnerClassOrInterface(rtName);
|
|
873 |
0
| assert sD == getQualifiedSymbolData(qualifiedClassName + '.' + rtName, SourceInfo.NONE);
|
|
874 |
| } |
|
875 |
224
| else if (qualifiedClassName != null) {
|
|
876 |
33
| int prefixLen = qualifiedClassName.lastIndexOf('.');
|
|
877 |
33
| if (sD == null && prefixLen >= 0) {
|
|
878 |
| |
|
879 |
0
| String qualifyingBase = qualifiedClassName.substring(0, qualifiedClassName.lastIndexOf('.'));
|
|
880 |
0
| SymbolData outerSD = getQualifiedSymbolData(qualifyingBase, SourceInfo.NONE);
|
|
881 |
0
| if (outerSD != null) {
|
|
882 |
0
| sD = outerSD.getInnerClassOrInterface(rtName);
|
|
883 |
0
| assert sD == getQualifiedSymbolData(qualifyingBase + '.' + rtName, si);
|
|
884 |
| |
|
885 |
| } |
|
886 |
| } |
|
887 |
| } |
|
888 |
224
| return sD;
|
|
889 |
| } |
|
890 |
| |
|
891 |
| |
|
892 |
| |
|
893 |
221
| protected SymbolData defineSymbolData(TypeDefBase typeDefBase, final String qualifiedTypeName) {
|
|
894 |
221
| return defineSymbolData(typeDefBase, qualifiedTypeName, _enclosingClassName );
|
|
895 |
| } |
|
896 |
| |
|
897 |
| |
|
898 |
| |
|
899 |
| |
|
900 |
| |
|
901 |
| |
|
902 |
| |
|
903 |
| |
|
904 |
| |
|
905 |
| |
|
906 |
221
| protected SymbolData defineSymbolData(final TypeDefBase typeDefBase, final String qualifiedTypeName,
|
|
907 |
| final String enclosingClassName ) { |
|
908 |
221
| assert (typeDefBase instanceof InterfaceDef) || (typeDefBase instanceof ClassDef);
|
|
909 |
221
| assert ! qualifiedTypeName.startsWith("null.");
|
|
910 |
221
| String name = qualifiedTypeName;
|
|
911 |
221
| SymbolData contSd = symbolTable.get(qualifiedTypeName);
|
|
912 |
| |
|
913 |
221
| if (contSd != null && ! contSd.isContinuation()) {
|
|
914 |
1
| _addAndIgnoreError("The class or interface " + name + " has already been defined.", typeDefBase);
|
|
915 |
1
| return null;
|
|
916 |
| } |
|
917 |
| |
|
918 |
220
| final SymbolData sd = (contSd == null) ? new SymbolData(qualifiedTypeName) : contSd;
|
|
919 |
220
| symbolTable.put(qualifiedTypeName, sd);
|
|
920 |
| |
|
921 |
| |
|
922 |
| |
|
923 |
| |
|
924 |
| |
|
925 |
| |
|
926 |
220
| sd.setIsContinuation(false);
|
|
927 |
| |
|
928 |
220
| sd.setPackage(_package);
|
|
929 |
| |
|
930 |
220
| sd.setMav(typeDefBase.getMav());
|
|
931 |
220
| sd.setTypeParameters(typeDefBase.getTypeParameters());
|
|
932 |
| |
|
933 |
| |
|
934 |
220
| final ArrayList<SymbolData> interfaces = new ArrayList<SymbolData>();
|
|
935 |
| |
|
936 |
| |
|
937 |
220
| ReferenceType[] rts = typeDefBase.getInterfaces();
|
|
938 |
220
| for (int i = 0; i < rts.length; i++) {
|
|
939 |
13
| final ReferenceType rt = rts[i];
|
|
940 |
13
| final String rtName = rt.getName();
|
|
941 |
13
| boolean forwardRef = false;
|
|
942 |
13
| SymbolData iD = _lookupTypeFromWithinClass(rt, enclosingClassName);
|
|
943 |
13
| if (iD != null && ! iD.isContinuation() && ! iD.isInterface()) {
|
|
944 |
0
| _addAndIgnoreError("The symbol " + rtName + " is not an interface", typeDefBase);
|
|
945 |
| } |
|
946 |
13
| if (iD == null || iD.isContinuation()) {
|
|
947 |
7
| iD = new SymbolData(rtName);
|
|
948 |
7
| forwardRef = true;
|
|
949 |
| } |
|
950 |
| |
|
951 |
13
| interfaces.add(iD);
|
|
952 |
13
| if (forwardRef) {
|
|
953 |
| |
|
954 |
7
| final int j = i;
|
|
955 |
7
| Command fixUp = new Command() {
|
|
956 |
7
| public void execute() {
|
|
957 |
7
| SymbolData newID = _lookupTypeFromWithinClass(rt, enclosingClassName);
|
|
958 |
0
| if (newID == null) _addAndIgnoreError("The symbol " + rtName + " is not defined", typeDefBase);
|
|
959 |
7
| else if (! newID.isInterface())
|
|
960 |
0
| _addAndIgnoreError("The symbol " + rtName + " is not an interface", typeDefBase);
|
|
961 |
7
| interfaces.set(j, newID);
|
|
962 |
7
| sd.addEnclosingData(newID);
|
|
963 |
| } |
|
964 |
| }; |
|
965 |
7
| fixUps.add(fixUp);
|
|
966 |
| } |
|
967 |
| } |
|
968 |
| |
|
969 |
| |
|
970 |
| |
|
971 |
220
| sd.setInterfaces(interfaces);
|
|
972 |
| |
|
973 |
| |
|
974 |
220
| SymbolData superSD = null;
|
|
975 |
| |
|
976 |
| |
|
977 |
| |
|
978 |
220
| if (typeDefBase instanceof InterfaceDef) {
|
|
979 |
| |
|
980 |
24
| SymbolData objectSD = getSymbolData("java.lang.Object", typeDefBase.getSourceInfo(), false);
|
|
981 |
24
| sd.setInterface(true);
|
|
982 |
24
| sd.setSuperClass(objectSD);
|
|
983 |
| } |
|
984 |
| |
|
985 |
196
| else if (typeDefBase instanceof ClassDef) {
|
|
986 |
196
| sd.setInterface(false);
|
|
987 |
196
| ClassDef cd = (ClassDef) typeDefBase;
|
|
988 |
196
| final ReferenceType rt = cd.getSuperclass();
|
|
989 |
196
| superSD = _lookupTypeFromWithinClass(rt, enclosingClassName);
|
|
990 |
| |
|
991 |
188
| if (superSD != null) sd.setSuperClass(superSD);
|
|
992 |
| else { |
|
993 |
8
| Command fixUp = new Command() {
|
|
994 |
8
| public void execute() {
|
|
995 |
8
| SymbolData newSuperSD = _lookupTypeFromWithinClass(rt, enclosingClassName);
|
|
996 |
8
| if (newSuperSD == null)
|
|
997 |
2
| _addAndIgnoreError("The class " + sd + " has an undefined superclass " + rt, typeDefBase);
|
|
998 |
| else |
|
999 |
6
| sd.setSuperClass(newSuperSD);
|
|
1000 |
| } |
|
1001 |
| }; |
|
1002 |
8
| fixUps.add(fixUp);
|
|
1003 |
| } |
|
1004 |
| } |
|
1005 |
| |
|
1006 |
| |
|
1007 |
| |
|
1008 |
220
| _log.log("REMOVING continuation " + qualifiedTypeName);
|
|
1009 |
220
| continuations.remove(qualifiedTypeName);
|
|
1010 |
| |
|
1011 |
| |
|
1012 |
196
| if (! sd.isInterface()) { LanguageLevelConverter._newSDs.put(sd, this); }
|
|
1013 |
| |
|
1014 |
220
| _classesInThisFile.remove(qualifiedTypeName);
|
|
1015 |
220
| return sd;
|
|
1016 |
| } |
|
1017 |
| |
|
1018 |
| |
|
1019 |
| |
|
1020 |
| |
|
1021 |
| |
|
1022 |
| |
|
1023 |
| |
|
1024 |
| |
|
1025 |
38
| protected SymbolData defineInnerSymbolData(TypeDefBase typeDefBase, String relName, String qualifiedTypeName,
|
|
1026 |
| Data enclosing) { |
|
1027 |
38
| assert (enclosing instanceof SymbolData) || (enclosing instanceof MethodData);
|
|
1028 |
| |
|
1029 |
| |
|
1030 |
38
| SymbolData sd = defineSymbolData(typeDefBase, qualifiedTypeName );
|
|
1031 |
| |
|
1032 |
38
| assert sd != null;
|
|
1033 |
| |
|
1034 |
| |
|
1035 |
38
| sd.setOuterData(enclosing);
|
|
1036 |
| |
|
1037 |
38
| if (sd.isInterface()) {
|
|
1038 |
| |
|
1039 |
| |
|
1040 |
7
| ((SymbolData) enclosing).addInnerInterface(sd);
|
|
1041 |
| } |
|
1042 |
31
| else if (! enclosing.getName().equals(_enclosingClassName)) {
|
|
1043 |
| |
|
1044 |
| |
|
1045 |
| |
|
1046 |
| |
|
1047 |
9
| assert enclosing instanceof MethodData;
|
|
1048 |
9
| SymbolData enclosingClassSD = getQualifiedSymbolData(_enclosingClassName);
|
|
1049 |
9
| assert enclosingClassSD != null;
|
|
1050 |
9
| enclosingClassSD.addInnerClass(sd);
|
|
1051 |
9
| enclosing.addInnerClass(sd);
|
|
1052 |
| } |
|
1053 |
| else { |
|
1054 |
| |
|
1055 |
22
| assert enclosing.getName().equals(_enclosingClassName);
|
|
1056 |
22
| enclosing.addInnerClass(sd);
|
|
1057 |
| |
|
1058 |
| } |
|
1059 |
38
| return sd;
|
|
1060 |
| } |
|
1061 |
| |
|
1062 |
| |
|
1063 |
| |
|
1064 |
| |
|
1065 |
| |
|
1066 |
| |
|
1067 |
5
| protected SymbolData defineAnonymousSymbolData(final AnonymousClassInstantiation anonInst,
|
|
1068 |
| final String qualifiedAnonName, |
|
1069 |
| final String superName) { |
|
1070 |
| |
|
1071 |
| |
|
1072 |
| |
|
1073 |
5
| final SourceInfo si = anonInst.getSourceInfo();
|
|
1074 |
| |
|
1075 |
5
| final SymbolData sd = new SymbolData(qualifiedAnonName);
|
|
1076 |
5
| symbolTable.put(qualifiedAnonName, sd);
|
|
1077 |
| |
|
1078 |
| |
|
1079 |
5
| sd.setIsContinuation(false);
|
|
1080 |
| |
|
1081 |
5
| sd.setPackage(_package);
|
|
1082 |
| |
|
1083 |
| |
|
1084 |
| |
|
1085 |
| |
|
1086 |
5
| if (_enclosingClassName != null) {
|
|
1087 |
5
| SymbolData enclosingSD = getQualifiedSymbolData(_enclosingClassName, SourceInfo.NONE);
|
|
1088 |
5
| assert (enclosingSD != null);
|
|
1089 |
5
| enclosingSD.addInnerClass(sd);
|
|
1090 |
| |
|
1091 |
| |
|
1092 |
| |
|
1093 |
| |
|
1094 |
| |
|
1095 |
5
| sd.setOuterData(enclosingSD);
|
|
1096 |
| |
|
1097 |
| } |
|
1098 |
| |
|
1099 |
5
| SymbolData superSD = getSymbolData(superName, anonInst.getSourceInfo());
|
|
1100 |
| |
|
1101 |
5
| if (superSD != null) {
|
|
1102 |
4
| if (superSD.isInterface()) {
|
|
1103 |
0
| sd.setSuperClass(getQualifiedSymbolData("java.lang.Object", si));
|
|
1104 |
0
| sd.setInterfaces(new ArrayList<SymbolData>(Arrays.asList(new SymbolData[] { superSD })));
|
|
1105 |
| } |
|
1106 |
4
| else sd.setSuperClass(superSD);
|
|
1107 |
| } |
|
1108 |
| else { |
|
1109 |
| |
|
1110 |
1
| Command fixUp = new Command() {
|
|
1111 |
0
| public void execute() {
|
|
1112 |
0
| SymbolData superSD = getSymbolData(superName, si);
|
|
1113 |
0
| if (superSD == null)
|
|
1114 |
0
| _addAndIgnoreError("The class/interface " + superName + " was not found.", anonInst);
|
|
1115 |
0
| else if (superSD.isInterface()) {
|
|
1116 |
0
| sd.setSuperClass(getQualifiedSymbolData("java.lang.Object", si));
|
|
1117 |
0
| sd.setInterfaces(new ArrayList<SymbolData>(Arrays.asList(new SymbolData[] { superSD })));
|
|
1118 |
| } |
|
1119 |
0
| else sd.setSuperClass(superSD);
|
|
1120 |
| } |
|
1121 |
| }; |
|
1122 |
1
| fixUps.add(fixUp);
|
|
1123 |
| } |
|
1124 |
5
| return sd;
|
|
1125 |
| } |
|
1126 |
| |
|
1127 |
| |
|
1128 |
| |
|
1129 |
163
| protected String[] getFormalParameterMav(Data d) { return new String[] {"final"}; }
|
|
1130 |
| |
|
1131 |
| |
|
1132 |
| |
|
1133 |
| |
|
1134 |
| |
|
1135 |
| |
|
1136 |
| |
|
1137 |
| |
|
1138 |
| |
|
1139 |
234
| protected VariableData[] formalParameters2VariableData(FormalParameter[] fps, SymbolData enclosing) {
|
|
1140 |
234
| assert enclosing != null ;
|
|
1141 |
| |
|
1142 |
| |
|
1143 |
| |
|
1144 |
| |
|
1145 |
234
| final VariableData[] varData = new VariableData[fps.length];
|
|
1146 |
234
| final String enclosingClassName = enclosing.getName();
|
|
1147 |
| |
|
1148 |
234
| String[] mav = getFormalParameterMav(enclosing);
|
|
1149 |
| |
|
1150 |
234
| for (int i = 0; i < fps.length; i++) {
|
|
1151 |
95
| VariableDeclarator vd = fps[i].getDeclarator();
|
|
1152 |
95
| String name = vd.getName().getText();
|
|
1153 |
| |
|
1154 |
95
| Type type = vd.getType();
|
|
1155 |
95
| final String typeName = type.getName();
|
|
1156 |
| |
|
1157 |
| |
|
1158 |
95
| final SourceInfo si = type.getSourceInfo();
|
|
1159 |
| |
|
1160 |
95
| SymbolData sd = _identifyType(typeName, si, enclosingClassName);
|
|
1161 |
| |
|
1162 |
95
| varData[i] =
|
|
1163 |
| new VariableData(name, new ModifiersAndVisibility(SourceInfo.NONE, mav), sd, true, enclosing); |
|
1164 |
| |
|
1165 |
95
| assert ! varData[i].isPrivate();
|
|
1166 |
| |
|
1167 |
95
| if (sd == null || sd == SymbolData.NOT_FOUND) {
|
|
1168 |
| |
|
1169 |
1
| final int j = i;
|
|
1170 |
| |
|
1171 |
| |
|
1172 |
1
| varData[j].setType(new SymbolData(typeName));
|
|
1173 |
1
| Command fixUp = new Command() {
|
|
1174 |
1
| public void execute() {
|
|
1175 |
1
| SymbolData newSd = _identifyType(typeName, si, enclosingClassName);
|
|
1176 |
1
| if (newSd == null || newSd == SymbolData.NOT_FOUND)
|
|
1177 |
0
| System.err.println("****** In fixUp, the type " + typeName + " at " + si + " was NOT found.");
|
|
1178 |
| |
|
1179 |
1
| if (newSd != null) varData[j].setType(newSd);
|
|
1180 |
| } |
|
1181 |
| }; |
|
1182 |
1
| fixUps.add(fixUp);
|
|
1183 |
| } |
|
1184 |
| |
|
1185 |
| |
|
1186 |
95
| varData[i].gotValue();
|
|
1187 |
95
| varData[i].setIsLocalVariable(true);
|
|
1188 |
| } |
|
1189 |
234
| return varData;
|
|
1190 |
| } |
|
1191 |
| |
|
1192 |
| |
|
1193 |
| |
|
1194 |
| |
|
1195 |
| |
|
1196 |
| |
|
1197 |
| |
|
1198 |
| |
|
1199 |
| |
|
1200 |
| |
|
1201 |
| |
|
1202 |
| |
|
1203 |
| |
|
1204 |
| |
|
1205 |
0
| private SymbolData _lookupReturnString(String rtString, SourceInfo si) {
|
|
1206 |
0
| return rtString.equals("void") ? SymbolData.VOID_TYPE : getSymbolData(rtString, si);
|
|
1207 |
| } |
|
1208 |
| |
|
1209 |
| |
|
1210 |
190
| protected MethodData createMethodData(final MethodDef that, final SymbolData sd) {
|
|
1211 |
| |
|
1212 |
190
| assert _enclosingClassName != null && getQualifiedSymbolData(_enclosingClassName).equals(sd);
|
|
1213 |
| |
|
1214 |
| |
|
1215 |
| |
|
1216 |
| |
|
1217 |
190
| that.getMav().visit(this);
|
|
1218 |
190
| that.getName().visit(this);
|
|
1219 |
| |
|
1220 |
| |
|
1221 |
190
| String[] throwStrings = referenceType2String(that.getThrows());
|
|
1222 |
| |
|
1223 |
190
| final String rtString = that.getResult().getName();
|
|
1224 |
| |
|
1225 |
| |
|
1226 |
190
| final SourceInfo si = that.getResult().getSourceInfo();
|
|
1227 |
| |
|
1228 |
| |
|
1229 |
| |
|
1230 |
| |
|
1231 |
| |
|
1232 |
| |
|
1233 |
| |
|
1234 |
190
| SymbolData returnType = _identifyType(rtString, si, _enclosingClassName);
|
|
1235 |
| |
|
1236 |
190
| final String name = that.getName().getText();
|
|
1237 |
| |
|
1238 |
190
| final MethodData md =
|
|
1239 |
| MethodData.make(name, that.getMav(), that.getTypeParams(), returnType, null, throwStrings, sd, that); |
|
1240 |
190
| VariableData[] vds = formalParameters2VariableData(that.getParams(), sd);
|
|
1241 |
| |
|
1242 |
190
| if (returnType == null) {
|
|
1243 |
| |
|
1244 |
10
| final String enclosingClassName = _enclosingClassName;
|
|
1245 |
10
| Command fixUp = new Command() {
|
|
1246 |
10
| public void execute() {
|
|
1247 |
10
| SymbolData newReturnType = _identifyType(rtString, si, enclosingClassName);
|
|
1248 |
10
| if (newReturnType == null && (! (LanguageLevelVisitor.this instanceof FullJavaVisitor))) {
|
|
1249 |
1
| _addAndIgnoreError("The return type " + rtString + " for method " + name + " in type " + sd + " is undefined.",
|
|
1250 |
| that); |
|
1251 |
| |
|
1252 |
| |
|
1253 |
| } |
|
1254 |
| else { |
|
1255 |
| |
|
1256 |
9
| md.setReturnType(newReturnType);
|
|
1257 |
| } |
|
1258 |
| } |
|
1259 |
| }; |
|
1260 |
10
| fixUps.add(fixUp);
|
|
1261 |
| } |
|
1262 |
| |
|
1263 |
| |
|
1264 |
| |
|
1265 |
| |
|
1266 |
| |
|
1267 |
| |
|
1268 |
190
| if (_checkError()) {
|
|
1269 |
0
| return md;
|
|
1270 |
| } |
|
1271 |
| |
|
1272 |
190
| md.setParams(vds);
|
|
1273 |
| |
|
1274 |
| |
|
1275 |
190
| if (! md.addVars(vds)) {
|
|
1276 |
2
| _addAndIgnoreError("You cannot have two method parameters with the same name", that);
|
|
1277 |
| } |
|
1278 |
190
| return md;
|
|
1279 |
| } |
|
1280 |
| |
|
1281 |
| |
|
1282 |
0
| private static String declaratorsToString(VariableDeclarator[] vds) {
|
|
1283 |
0
| StringBuilder printString = new StringBuilder("{ ");
|
|
1284 |
0
| for (VariableDeclarator vd: vds) {
|
|
1285 |
0
| printString.append(vd.getName().getText()).append(": ").append(vd.getType().getName()).append("; ");
|
|
1286 |
| } |
|
1287 |
0
| return printString.append('}').toString();
|
|
1288 |
| } |
|
1289 |
| |
|
1290 |
| |
|
1291 |
| |
|
1292 |
| |
|
1293 |
| |
|
1294 |
177
| protected VariableData[] _variableDeclaration2VariableData(VariableDeclaration vd, final Data enclosing) {
|
|
1295 |
177
| assert enclosing != null;
|
|
1296 |
| |
|
1297 |
177
| LinkedList<VariableData> vds = new LinkedList<VariableData>();
|
|
1298 |
177
| ModifiersAndVisibility mav = vd.getMav();
|
|
1299 |
177
| VariableDeclarator[] declarators = vd.getDeclarators();
|
|
1300 |
177
| for (final VariableDeclarator declarator: declarators) {
|
|
1301 |
192
| declarator.visit(this);
|
|
1302 |
192
| final Type type = declarator.getType();
|
|
1303 |
192
| final String name = declarator.getName().getText();
|
|
1304 |
192
| final String typeName = type.getName();
|
|
1305 |
| |
|
1306 |
| |
|
1307 |
| |
|
1308 |
| |
|
1309 |
| |
|
1310 |
| |
|
1311 |
192
| SymbolData sd = _identifyType(typeName, declarator.getSourceInfo(), _enclosingClassName);
|
|
1312 |
192
| boolean initialized = declarator instanceof InitializedVariableDeclarator;
|
|
1313 |
| |
|
1314 |
| |
|
1315 |
192
| final VariableData vdata = new VariableData(name, mav, sd, initialized, enclosing);
|
|
1316 |
192
| vdata.setHasInitializer(initialized);
|
|
1317 |
| |
|
1318 |
192
| vds.addLast(vdata);
|
|
1319 |
| |
|
1320 |
192
| if (sd == null) {
|
|
1321 |
| |
|
1322 |
7
| final String enclosingName = _enclosingClassName;
|
|
1323 |
| |
|
1324 |
7
| Command fixup = new Command() {
|
|
1325 |
6
| public void execute() {
|
|
1326 |
| |
|
1327 |
6
| SymbolData newSd = _identifyType(typeName, declarator.getSourceInfo(), enclosingName);
|
|
1328 |
4
| if (newSd != null) vdata.setType(newSd);
|
|
1329 |
2
| else if (! (LanguageLevelVisitor.this instanceof FullJavaVisitor) )
|
|
1330 |
2
| _addAndIgnoreError("Class or Interface " + typeName + " not found", type);
|
|
1331 |
| } |
|
1332 |
| }; |
|
1333 |
7
| fixUps.add(fixup);
|
|
1334 |
| } |
|
1335 |
| } |
|
1336 |
| |
|
1337 |
177
| return vds.toArray(new VariableData[vds.size()]);
|
|
1338 |
| } |
|
1339 |
| |
|
1340 |
| |
|
1341 |
| |
|
1342 |
| |
|
1343 |
| |
|
1344 |
494
| protected SymbolData _identifyType(String name, SourceInfo si, String enclosingClassName) {
|
|
1345 |
| |
|
1346 |
| |
|
1347 |
| |
|
1348 |
0
| if (_genericTypes.containsKey(name)) return _genericTypes.get(name);
|
|
1349 |
| |
|
1350 |
494
| SymbolData sd = getSymbolData(name, si);
|
|
1351 |
473
| if (sd != null) return sd;
|
|
1352 |
| |
|
1353 |
| |
|
1354 |
| |
|
1355 |
| |
|
1356 |
| |
|
1357 |
| |
|
1358 |
| |
|
1359 |
| |
|
1360 |
0
| if (enclosingClassName == null) return null;
|
|
1361 |
| |
|
1362 |
21
| SymbolData enclosingSD = getQualifiedSymbolData(enclosingClassName, SourceInfo.NONE);
|
|
1363 |
1
| if (enclosingSD == null) return null;
|
|
1364 |
| |
|
1365 |
20
| sd = enclosingSD.getInnerClassOrInterface(name);
|
|
1366 |
| |
|
1367 |
| |
|
1368 |
| |
|
1369 |
| |
|
1370 |
| |
|
1371 |
| |
|
1372 |
| |
|
1373 |
| |
|
1374 |
| |
|
1375 |
20
| return sd;
|
|
1376 |
| } |
|
1377 |
| |
|
1378 |
| |
|
1379 |
| |
|
1380 |
| |
|
1381 |
| |
|
1382 |
26
| protected static void _addError(String message, JExpressionIF that) {
|
|
1383 |
| |
|
1384 |
26
| _errorAdded = true;
|
|
1385 |
26
| Pair<String, JExpressionIF> p = new Pair<String, JExpressionIF>(message, that);
|
|
1386 |
25
| if (! errors.contains(p)) errors.addLast(p);
|
|
1387 |
| } |
|
1388 |
| |
|
1389 |
| |
|
1390 |
| |
|
1391 |
| |
|
1392 |
| |
|
1393 |
71
| protected static void _addAndIgnoreError(String message, JExpressionIF that) {
|
|
1394 |
| |
|
1395 |
71
| if (_errorAdded) {
|
|
1396 |
1
| throw new RuntimeException("Internal Program Error: _addAndIgnoreError called while _errorAdded was true." +
|
|
1397 |
| " Please report this bug."); |
|
1398 |
| } |
|
1399 |
70
| _errorAdded = false;
|
|
1400 |
70
| Pair<String, JExpressionIF> newMsg = new Pair<String, JExpressionIF>(message, that);
|
|
1401 |
69
| if (! errors.contains(newMsg)) errors.addLast(newMsg);
|
|
1402 |
| |
|
1403 |
| } |
|
1404 |
| |
|
1405 |
4142
| protected boolean prune(JExpressionIF node) { return _checkError(); }
|
|
1406 |
| |
|
1407 |
| |
|
1408 |
| |
|
1409 |
| |
|
1410 |
| |
|
1411 |
| |
|
1412 |
4426
| protected static boolean _checkError() {
|
|
1413 |
4426
| if (_errorAdded) {
|
|
1414 |
24
| _errorAdded = false;
|
|
1415 |
24
| return true;
|
|
1416 |
| } |
|
1417 |
4402
| else return false;
|
|
1418 |
| } |
|
1419 |
| |
|
1420 |
| |
|
1421 |
7
| public void _badModifiers(String first, String second, JExpressionIF that) {
|
|
1422 |
7
| _addError("Illegal combination of modifiers. Can't use " + first + " and " + second + " together.", that);
|
|
1423 |
| } |
|
1424 |
| |
|
1425 |
| |
|
1426 |
| |
|
1427 |
| |
|
1428 |
650
| public Void forModifiersAndVisibilityDoFirst(ModifiersAndVisibility that) {
|
|
1429 |
650
| String[] modifiersAndVisibility = that.getModifiers();
|
|
1430 |
650
| Arrays.sort(modifiersAndVisibility);
|
|
1431 |
650
| if (modifiersAndVisibility.length > 0) {
|
|
1432 |
185
| String s = modifiersAndVisibility[0];
|
|
1433 |
| |
|
1434 |
185
| for (int i = 1; i < modifiersAndVisibility.length; i++) {
|
|
1435 |
14
| if (s.equals(modifiersAndVisibility[i])) {
|
|
1436 |
1
| _addError("Duplicate modifier: " + s, that);
|
|
1437 |
| } |
|
1438 |
14
| s = modifiersAndVisibility[i];
|
|
1439 |
| } |
|
1440 |
| |
|
1441 |
| |
|
1442 |
185
| String visibility = "package";
|
|
1443 |
185
| boolean isAbstract = false;
|
|
1444 |
185
| boolean isStatic = false;
|
|
1445 |
185
| boolean isFinal = false;
|
|
1446 |
185
| boolean isSynchronized = false;
|
|
1447 |
185
| boolean isStrictfp = false;
|
|
1448 |
185
| boolean isTransient = false;
|
|
1449 |
185
| boolean isVolatile = false;
|
|
1450 |
185
| boolean isNative = false;
|
|
1451 |
185
| for (int i = 0; i < modifiersAndVisibility.length; i++) {
|
|
1452 |
199
| s = modifiersAndVisibility[i];
|
|
1453 |
199
| if (s.equals("public") || s.equals("protected") || s.equals("private")) {
|
|
1454 |
1
| if (! visibility.equals("package")) _badModifiers(visibility, s, that);
|
|
1455 |
1
| else if (s.equals("private") && isAbstract) _badModifiers("private", "abstract", that);
|
|
1456 |
118
| else visibility = s;
|
|
1457 |
| } |
|
1458 |
35
| else if (s.equals("abstract")) isAbstract = true;
|
|
1459 |
44
| else if (s.equals("final")) {
|
|
1460 |
15
| isFinal = true;
|
|
1461 |
2
| if (isAbstract) _badModifiers("final", "abstract", that);
|
|
1462 |
| } |
|
1463 |
29
| else if (s.equals("native")) {
|
|
1464 |
1
| isNative = true;
|
|
1465 |
0
| if (isAbstract) _badModifiers("native", "abstract", that);
|
|
1466 |
| } |
|
1467 |
28
| else if (s.equals("synchronized")) {
|
|
1468 |
1
| isSynchronized = true;
|
|
1469 |
0
| if (isAbstract) _badModifiers("synchronized", "abstract", that);
|
|
1470 |
| } |
|
1471 |
27
| else if (s.equals("volatile")) {
|
|
1472 |
4
| isVolatile = true;
|
|
1473 |
2
| if (isFinal) _badModifiers("final", "volatile", that);
|
|
1474 |
| } |
|
1475 |
| } |
|
1476 |
185
| return forJExpressionDoFirst(that);
|
|
1477 |
| } |
|
1478 |
465
| return null;
|
|
1479 |
| } |
|
1480 |
| |
|
1481 |
| |
|
1482 |
| |
|
1483 |
| |
|
1484 |
209
| public Void forClassDefDoFirst(ClassDef that) {
|
|
1485 |
209
| String name = that.getName().getText();
|
|
1486 |
209
| Iterator<String> iter = _importedFiles.iterator();
|
|
1487 |
209
| while (iter.hasNext()) {
|
|
1488 |
14
| String s = iter.next();
|
|
1489 |
14
| if (s.endsWith(name) && ! s.equals(getQualifiedClassName(name))) {
|
|
1490 |
1
| _addAndIgnoreError("The class " + name + " was already imported.", that);
|
|
1491 |
| } |
|
1492 |
| } |
|
1493 |
| |
|
1494 |
| |
|
1495 |
209
| String[] mavStrings = that.getMav().getModifiers();
|
|
1496 |
209
| if (! (that instanceof InnerClassDef)) {
|
|
1497 |
177
| for (int i = 0; i < mavStrings.length; i++) {
|
|
1498 |
34
| if (mavStrings[i].equals("private")) {
|
|
1499 |
1
| _addAndIgnoreError("Top level classes cannot be private", that);
|
|
1500 |
| } |
|
1501 |
| } |
|
1502 |
| } |
|
1503 |
| |
|
1504 |
| |
|
1505 |
209
| SymbolData javaLangClass =
|
|
1506 |
| getQualifiedSymbolData("java.lang." + that.getName().getText(), that.getSourceInfo(), false, false, false); |
|
1507 |
209
| if (that.getName().getText().equals("TestCase") || (javaLangClass != null && ! javaLangClass.isContinuation())) {
|
|
1508 |
2
| _addError("You cannot define a class with the name " + that.getName().getText() +
|
|
1509 |
| " because that class name is reserved." + |
|
1510 |
| " Please choose a different name for this class", that); |
|
1511 |
| } |
|
1512 |
209
| return forTypeDefBaseDoFirst(that);
|
|
1513 |
| } |
|
1514 |
| |
|
1515 |
| |
|
1516 |
22
| public Void forInterfaceDefDoFirst(InterfaceDef that) {
|
|
1517 |
| |
|
1518 |
22
| String[] mavStrings = that.getMav().getModifiers();
|
|
1519 |
22
| for (int i = 0; i < mavStrings.length; i++) {
|
|
1520 |
11
| if (mavStrings[i].equals("private")) {
|
|
1521 |
1
| _addAndIgnoreError("Top level interfaces cannot be private", that);
|
|
1522 |
| } |
|
1523 |
11
| if (mavStrings[i].equals("final")) {
|
|
1524 |
1
| _addAndIgnoreError("Interfaces cannot be final", that);
|
|
1525 |
| } |
|
1526 |
| } |
|
1527 |
22
| return forTypeDefBaseDoFirst(that);
|
|
1528 |
| } |
|
1529 |
| |
|
1530 |
| |
|
1531 |
| |
|
1532 |
| |
|
1533 |
10
| public Void forInnerInterfaceDefDoFirst(InnerInterfaceDef that) {
|
|
1534 |
10
| String[] mavStrings = that.getMav().getModifiers();
|
|
1535 |
10
| for (int i = 0; i < mavStrings.length; i++) {
|
|
1536 |
3
| if (mavStrings[i].equals("final")) {
|
|
1537 |
1
| _addAndIgnoreError("Interfaces cannot be final", that);
|
|
1538 |
| } |
|
1539 |
| } |
|
1540 |
10
| return forTypeDefBaseDoFirst(that);
|
|
1541 |
| } |
|
1542 |
| |
|
1543 |
| |
|
1544 |
| |
|
1545 |
| |
|
1546 |
| |
|
1547 |
| |
|
1548 |
| |
|
1549 |
5
| public void anonymousClassInstantiationHelper(AnonymousClassInstantiation that, SymbolData enclosing, String superName) {
|
|
1550 |
5
| that.getArguments().visit(this);
|
|
1551 |
5
| SymbolData enclosingSD = enclosing.getSymbolData();
|
|
1552 |
5
| String enclosingSDName = enclosingSD.getName();
|
|
1553 |
5
| assert enclosingSDName.equals(_enclosingClassName);
|
|
1554 |
5
| String anonName = getQualifiedClassName(enclosingSDName) + "$" + enclosingSD.preincrementAnonymousInnerClassNum();
|
|
1555 |
| |
|
1556 |
| |
|
1557 |
| |
|
1558 |
| |
|
1559 |
| |
|
1560 |
5
| SymbolData anonSD = defineAnonymousSymbolData(that, anonName, superName);
|
|
1561 |
| |
|
1562 |
| |
|
1563 |
| |
|
1564 |
5
| createToString(anonSD);
|
|
1565 |
5
| createHashCode(anonSD);
|
|
1566 |
5
| createEquals(anonSD);
|
|
1567 |
| |
|
1568 |
| |
|
1569 |
| |
|
1570 |
| |
|
1571 |
| |
|
1572 |
5
| that.getBody().visit(newClassBodyVisitor(anonSD, anonName));
|
|
1573 |
| } |
|
1574 |
| |
|
1575 |
| |
|
1576 |
214
| protected void identifyInnerClasses(TypeDefBase that) {
|
|
1577 |
214
| String prefix = _enclosingClassName == null ? "" : _enclosingClassName + '.';
|
|
1578 |
214
| String enclosingType = getQualifiedClassName(prefix + that.getName().getText());
|
|
1579 |
| |
|
1580 |
214
| assert enclosingType != null;
|
|
1581 |
| |
|
1582 |
| |
|
1583 |
214
| SymbolData sd = getSymbolData(enclosingType, SourceInfo.NONE);
|
|
1584 |
| |
|
1585 |
214
| enclosingType = sd.getName();
|
|
1586 |
214
| BracedBody body = that.getBody();
|
|
1587 |
214
| for (BodyItemI bi: body.getStatements()) {
|
|
1588 |
337
| if (bi instanceof TypeDefBase) {
|
|
1589 |
25
| TypeDefBase type = (TypeDefBase) bi;
|
|
1590 |
25
| String rawClassName = type.getName().getText();
|
|
1591 |
| |
|
1592 |
25
| String fullClassName = enclosingType + '.' + rawClassName;
|
|
1593 |
| |
|
1594 |
| |
|
1595 |
| |
|
1596 |
| |
|
1597 |
25
| SymbolData innerSD = makeContinuation(bi.getSourceInfo(), fullClassName);
|
|
1598 |
| |
|
1599 |
| |
|
1600 |
25
| sd.addInnerClass(innerSD);
|
|
1601 |
| } |
|
1602 |
| } |
|
1603 |
| |
|
1604 |
| } |
|
1605 |
| |
|
1606 |
| |
|
1607 |
| |
|
1608 |
| |
|
1609 |
| |
|
1610 |
| |
|
1611 |
| |
|
1612 |
| |
|
1613 |
| |
|
1614 |
| |
|
1615 |
| |
|
1616 |
| |
|
1617 |
| |
|
1618 |
| |
|
1619 |
| |
|
1620 |
| |
|
1621 |
| |
|
1622 |
| |
|
1623 |
| |
|
1624 |
| |
|
1625 |
| |
|
1626 |
| |
|
1627 |
| |
|
1628 |
| |
|
1629 |
| |
|
1630 |
| |
|
1631 |
| |
|
1632 |
| |
|
1633 |
16
| public Void forPackageStatementOnly(PackageStatement that) {
|
|
1634 |
16
| CompoundWord cWord = that.getCWord();
|
|
1635 |
16
| Word[] words = cWord.getWords();
|
|
1636 |
16
| String newPackage;
|
|
1637 |
16
| String separator = System.getProperty("file.separator");
|
|
1638 |
16
| if (words.length > 0) {
|
|
1639 |
15
| _package = words[0].getText();
|
|
1640 |
15
| newPackage = _package;
|
|
1641 |
15
| for (int i = 1; i < words.length; i++) {
|
|
1642 |
7
| String temp = words[i].getText();
|
|
1643 |
7
| newPackage = newPackage + separator + temp;
|
|
1644 |
7
| _package = _package + '.' + temp;
|
|
1645 |
| } |
|
1646 |
15
| String directory = _file.getParent();
|
|
1647 |
15
| if (directory == null || !directory.endsWith(newPackage)) {
|
|
1648 |
1
| _addAndIgnoreError("The package name must mirror your file's directory.", that);
|
|
1649 |
| } |
|
1650 |
| } |
|
1651 |
| |
|
1652 |
| |
|
1653 |
| |
|
1654 |
| |
|
1655 |
| |
|
1656 |
16
| return forJExpressionOnly(that);
|
|
1657 |
| } |
|
1658 |
| |
|
1659 |
| |
|
1660 |
| |
|
1661 |
| |
|
1662 |
| |
|
1663 |
| |
|
1664 |
10
| public Void forClassImportStatementOnly(ClassImportStatement that) {
|
|
1665 |
10
| CompoundWord cWord = that.getCWord();
|
|
1666 |
10
| Word[] words = cWord.getWords();
|
|
1667 |
| |
|
1668 |
| |
|
1669 |
10
| for (int i = 0; i < _importedFiles.size(); i++) {
|
|
1670 |
2
| String name = _importedFiles.get(i);
|
|
1671 |
2
| int indexOfLastDot = name.lastIndexOf('.');
|
|
1672 |
2
| if (indexOfLastDot != -1 &&
|
|
1673 |
| (words[words.length-1].getText()).equals(name.substring(indexOfLastDot + 1, name.length()))) { |
|
1674 |
1
| _addAndIgnoreError("The class " + words[words.length-1].getText() + " has already been imported.", that);
|
|
1675 |
1
| return null;
|
|
1676 |
| } |
|
1677 |
| } |
|
1678 |
| |
|
1679 |
9
| StringBuilder nameBuff = new StringBuilder(words[0].getText());
|
|
1680 |
17
| for (int i = 1; i < words.length; i++) {nameBuff.append('.' + words[i].getText());}
|
|
1681 |
| |
|
1682 |
9
| String qualifiedTypeName = nameBuff.toString();
|
|
1683 |
| |
|
1684 |
| |
|
1685 |
| |
|
1686 |
| |
|
1687 |
| |
|
1688 |
| |
|
1689 |
| |
|
1690 |
| |
|
1691 |
| |
|
1692 |
| |
|
1693 |
| |
|
1694 |
| |
|
1695 |
| |
|
1696 |
| |
|
1697 |
9
| _importedFiles.addLast(qualifiedTypeName);
|
|
1698 |
| |
|
1699 |
| |
|
1700 |
9
| createImportedSymbolContinuation(qualifiedTypeName, that.getSourceInfo());
|
|
1701 |
9
| return forImportStatementOnly(that);
|
|
1702 |
| } |
|
1703 |
| |
|
1704 |
| |
|
1705 |
12
| protected SymbolData createImportedSymbolContinuation(String qualifiedTypeName, SourceInfo si) {
|
|
1706 |
| |
|
1707 |
12
| SymbolData sd = symbolTable.get(qualifiedTypeName);
|
|
1708 |
12
| if (sd == null) {
|
|
1709 |
| |
|
1710 |
| |
|
1711 |
| |
|
1712 |
7
| sd = makeContinuation(si, qualifiedTypeName);
|
|
1713 |
| } |
|
1714 |
12
| return sd;
|
|
1715 |
| } |
|
1716 |
| |
|
1717 |
| |
|
1718 |
8
| public Void forPackageImportStatementOnly(PackageImportStatement that) {
|
|
1719 |
8
| CompoundWord cWord = that.getCWord();
|
|
1720 |
8
| Word[] words = cWord.getWords();
|
|
1721 |
8
| StringBuilder tempBuff = new StringBuilder(words[0].getText());
|
|
1722 |
8
| for (int i = 1; i < words.length; i++) { tempBuff.append('.' + words[i].getText()); }
|
|
1723 |
8
| String temp = tempBuff.toString();
|
|
1724 |
| |
|
1725 |
| |
|
1726 |
| |
|
1727 |
8
| if (_package.equals(temp)) {
|
|
1728 |
1
| _addAndIgnoreError("You do not need to import package " + temp +
|
|
1729 |
| ". It is your package so all public classes in it are already visible.", that); |
|
1730 |
1
| return null;
|
|
1731 |
| } |
|
1732 |
| |
|
1733 |
7
| if (! _importedPackages.contains(temp)) _importedPackages.addLast(temp);
|
|
1734 |
| |
|
1735 |
7
| return forImportStatementOnly(that);
|
|
1736 |
| } |
|
1737 |
| |
|
1738 |
| |
|
1739 |
149
| public Void forConcreteMethodDefDoFirst(ConcreteMethodDef that) {
|
|
1740 |
149
| ModifiersAndVisibility mav = that.getMav();
|
|
1741 |
149
| String[] modifiers = mav.getModifiers();
|
|
1742 |
| |
|
1743 |
149
| for (int i = 0; i < modifiers.length; i++) {
|
|
1744 |
47
| if (modifiers[i].equals("abstract")) {
|
|
1745 |
2
| _addError("Methods that have a braced body cannot be declared \"abstract\"", that);
|
|
1746 |
2
| break;
|
|
1747 |
| } |
|
1748 |
| } |
|
1749 |
149
| return super.forConcreteMethodDefDoFirst(that);
|
|
1750 |
| } |
|
1751 |
| |
|
1752 |
| |
|
1753 |
43
| public Void forAbstractMethodDefDoFirst(AbstractMethodDef that) {
|
|
1754 |
43
| ModifiersAndVisibility mav = that.getMav();
|
|
1755 |
43
| String[] modifiers = mav.getModifiers();
|
|
1756 |
| |
|
1757 |
1
| if (Utilities.isStatic(modifiers)) _badModifiers("static", "abstract", that);
|
|
1758 |
43
| return super.forAbstractMethodDefDoFirst(that);
|
|
1759 |
| } |
|
1760 |
| |
|
1761 |
| |
|
1762 |
3
| public Void forShiftAssignmentExpressionDoFirst(ShiftAssignmentExpression that) { return null; }
|
|
1763 |
3
| public Void forBitwiseAssignmentExpressionDoFirst(BitwiseAssignmentExpression that) { return null; }
|
|
1764 |
0
| public Void forBitwiseBinaryExpressionDoFirst(BitwiseBinaryExpression that) { return null; }
|
|
1765 |
3
| public Void forBitwiseOrExpressionDoFirst(BitwiseOrExpression that) { return null; }
|
|
1766 |
1
| public Void forBitwiseXorExpressionDoFirst(BitwiseXorExpression that) { return null; }
|
|
1767 |
1
| public Void forBitwiseAndExpressionDoFirst(BitwiseAndExpression that) { return null; }
|
|
1768 |
1
| public Void forBitwiseNotExpressionDoFirst(BitwiseNotExpression that) { return null; }
|
|
1769 |
3
| public Void forShiftBinaryExpressionDoFirst(ShiftBinaryExpression that) { return null; }
|
|
1770 |
0
| public Void forBitwiseNotExpressionDoFirst(ShiftBinaryExpression that) { return null; }
|
|
1771 |
| |
|
1772 |
| |
|
1773 |
| |
|
1774 |
1
| public Void forEmptyExpressionDoFirst(EmptyExpression that) {
|
|
1775 |
1
| _addAndIgnoreError("You appear to be missing an expression here", that);
|
|
1776 |
1
| return null;
|
|
1777 |
| } |
|
1778 |
| |
|
1779 |
| |
|
1780 |
| |
|
1781 |
1
| public Void forNoOpExpressionDoFirst(NoOpExpression that) {
|
|
1782 |
1
| _addAndIgnoreError("You are missing a binary operator here", that);
|
|
1783 |
1
| return null;
|
|
1784 |
| } |
|
1785 |
| |
|
1786 |
| |
|
1787 |
137
| public Void forSourceFileDoFirst(SourceFile that) {
|
|
1788 |
| |
|
1789 |
137
| for (int i = 0; i < that.getTypes().length; i++) {
|
|
1790 |
174
| if (that.getTypes()[i] instanceof ClassDef) {
|
|
1791 |
160
| ClassDef c = (ClassDef) that.getTypes()[i];
|
|
1792 |
160
| String superName = c.getSuperclass().getName();
|
|
1793 |
160
| if (superName.equals("TestCase") || superName.equals("junit.framework.TestCase")) {
|
|
1794 |
| |
|
1795 |
5
| if (that.getTypes().length > 1) {
|
|
1796 |
0
| _addAndIgnoreError("TestCases must appear in files by themselves in functional code", c);
|
|
1797 |
| } |
|
1798 |
| } |
|
1799 |
| } |
|
1800 |
| } |
|
1801 |
137
| return null;
|
|
1802 |
| } |
|
1803 |
| |
|
1804 |
| |
|
1805 |
| |
|
1806 |
| |
|
1807 |
| |
|
1808 |
| |
|
1809 |
| |
|
1810 |
137
| public Void forSourceFile(SourceFile that) {
|
|
1811 |
| |
|
1812 |
137
| forSourceFileDoFirst(that);
|
|
1813 |
0
| if (prune(that)) return null;
|
|
1814 |
| |
|
1815 |
| |
|
1816 |
13
| for (int i = 0; i < that.getPackageStatements().length; i++) that.getPackageStatements()[i].visit(this);
|
|
1817 |
13
| for (int i = 0; i < that.getImportStatements().length; i++) that.getImportStatements()[i].visit(this);
|
|
1818 |
0
| if (! _importedPackages.contains("java.lang")) _importedPackages.addFirst("java.lang");
|
|
1819 |
| |
|
1820 |
137
| TypeDefBase[] types = that.getTypes();
|
|
1821 |
| |
|
1822 |
137
| _classesInThisFile = new HashSet<String>();
|
|
1823 |
137
| for (int i = 0; i < types.length; i++) {
|
|
1824 |
| |
|
1825 |
| |
|
1826 |
174
| String qualifiedClassName = getQualifiedClassName(types[i].getName().getText());
|
|
1827 |
174
| _classesInThisFile.add(qualifiedClassName);
|
|
1828 |
| |
|
1829 |
174
| _log.log("Adding " + qualifiedClassName + " to _classesInThisFile");
|
|
1830 |
| } |
|
1831 |
| |
|
1832 |
137
| for (int i = 0; i < types.length; i++) {
|
|
1833 |
| |
|
1834 |
174
| String qualifiedClassName = getQualifiedClassName(types[i].getName().getText());
|
|
1835 |
| |
|
1836 |
| |
|
1837 |
174
| if (_classesInThisFile.contains(qualifiedClassName)) {
|
|
1838 |
174
| types[i].visit(this);
|
|
1839 |
| } |
|
1840 |
| } |
|
1841 |
| |
|
1842 |
137
| return forSourceFileOnly(that);
|
|
1843 |
| } |
|
1844 |
| |
|
1845 |
| |
|
1846 |
185
| public Void forSimpleNameReference(SimpleNameReference that) {
|
|
1847 |
185
| that.visit(new ResolveNameVisitor());
|
|
1848 |
185
| return null;
|
|
1849 |
| } |
|
1850 |
| |
|
1851 |
| |
|
1852 |
20
| public Void forComplexNameReference(ComplexNameReference that) {
|
|
1853 |
20
| that.visit(new ResolveNameVisitor());
|
|
1854 |
20
| return null;
|
|
1855 |
| } |
|
1856 |
| |
|
1857 |
| |
|
1858 |
175
| public Void forVariableDeclaration(VariableDeclaration that) {
|
|
1859 |
| |
|
1860 |
175
| forVariableDeclarationDoFirst(that);
|
|
1861 |
| |
|
1862 |
1
| if (prune(that)) return null;
|
|
1863 |
| |
|
1864 |
174
| that.getMav().visit(this);
|
|
1865 |
| |
|
1866 |
174
| return forVariableDeclarationOnly(that);
|
|
1867 |
| } |
|
1868 |
| |
|
1869 |
| |
|
1870 |
| |
|
1871 |
| |
|
1872 |
599
| protected static void addGeneratedMethod(SymbolData sd, MethodData md) {
|
|
1873 |
599
| MethodData rmd = SymbolData.repeatedSignature(sd.getMethods(), md);
|
|
1874 |
599
| if (rmd == null) {
|
|
1875 |
589
| sd.addMethod(md, true);
|
|
1876 |
589
| md.setGenerated(true);
|
|
1877 |
| } |
|
1878 |
| |
|
1879 |
10
| else if (!(getUnqualifiedClassName(sd.getName()).equals(md.getName()))) {
|
|
1880 |
| |
|
1881 |
1
| _addAndIgnoreError("The method " + md.getName() + " is automatically generated, and thus you cannot override it",
|
|
1882 |
| rmd.getJExpression()); |
|
1883 |
| } |
|
1884 |
| } |
|
1885 |
| |
|
1886 |
| |
|
1887 |
| |
|
1888 |
| |
|
1889 |
| |
|
1890 |
| |
|
1891 |
111
| public void createConstructor(SymbolData sd) {
|
|
1892 |
0
| if (LanguageLevelConverter.isAdvancedFile(_file)) return;
|
|
1893 |
| |
|
1894 |
| |
|
1895 |
| |
|
1896 |
| |
|
1897 |
| |
|
1898 |
| |
|
1899 |
| |
|
1900 |
| |
|
1901 |
111
| if (sd.isContinuation()) {
|
|
1902 |
0
| _addAndIgnoreError("Could not generate constructor for class " + sd + " because it has no definition",
|
|
1903 |
| new NullLiteral(SourceInfo.NONE)); |
|
1904 |
0
| return;
|
|
1905 |
| } |
|
1906 |
| |
|
1907 |
111
| SymbolData superSd = sd.getSuperClass();
|
|
1908 |
111
| if (superSd == null) {
|
|
1909 |
2
| _addAndIgnoreError("Could not generate constructor for class " + sd + " because it has no superclass",
|
|
1910 |
| new NullLiteral(SourceInfo.NONE)); |
|
1911 |
2
| return;
|
|
1912 |
| } |
|
1913 |
| |
|
1914 |
| else { |
|
1915 |
109
| LinkedList<MethodData> superMethods = superSd.getMethods();
|
|
1916 |
109
| String superUnqualifiedName = getUnqualifiedClassName(superSd.getName());
|
|
1917 |
| |
|
1918 |
109
| LanguageLevelVisitor sslv = LanguageLevelConverter._newSDs.remove(superSd);
|
|
1919 |
| |
|
1920 |
| |
|
1921 |
| |
|
1922 |
109
| if (sslv != null) {
|
|
1923 |
8
| sslv.createConstructor(superSd);
|
|
1924 |
| |
|
1925 |
| } |
|
1926 |
| |
|
1927 |
| |
|
1928 |
109
| MethodData superConstructor = null;
|
|
1929 |
109
| for (MethodData superMd: superMethods) {
|
|
1930 |
| |
|
1931 |
| |
|
1932 |
| |
|
1933 |
1234
| if (superMd.getName().equals(superUnqualifiedName)) {
|
|
1934 |
110
| if (superConstructor == null || superMd.getParams().length < superConstructor.getParams().length) {
|
|
1935 |
106
| superConstructor = superMd;
|
|
1936 |
| } |
|
1937 |
| } |
|
1938 |
| } |
|
1939 |
109
| if (superConstructor == null) {
|
|
1940 |
4
| _addAndIgnoreError("Could not generate constructor for class " + sd + " superclass has no constructor, perhaps"
|
|
1941 |
| + " because the class hierarchy is cyclic.", |
|
1942 |
| new NullLiteral(SourceInfo.NONE)); |
|
1943 |
4
| return;
|
|
1944 |
| } |
|
1945 |
| |
|
1946 |
| |
|
1947 |
| |
|
1948 |
105
| String name = getUnqualifiedClassName(sd.getName());
|
|
1949 |
105
| MethodData md = new MethodData(name,
|
|
1950 |
| PUBLIC_MAV, |
|
1951 |
| new TypeParameter[0], |
|
1952 |
| sd, |
|
1953 |
| new VariableData[0], |
|
1954 |
| new String[0], |
|
1955 |
| sd, |
|
1956 |
| null); |
|
1957 |
| |
|
1958 |
105
| LinkedList<VariableData> params = new LinkedList<VariableData>();
|
|
1959 |
| |
|
1960 |
105
| for (VariableData superParam : superConstructor.getParams()) {
|
|
1961 |
10
| String paramName = md.createUniqueName("super_" + superParam.getName());
|
|
1962 |
10
| SymbolData superParamSD = superParam.getType();
|
|
1963 |
10
| assert superParamSD != null;
|
|
1964 |
10
| VariableData newParam = new VariableData(paramName, PACKAGE_MAV, superParamSD, true, sd);
|
|
1965 |
10
| newParam.setGenerated(true);
|
|
1966 |
10
| params.add(newParam);
|
|
1967 |
| |
|
1968 |
10
| md.addVar(newParam);
|
|
1969 |
| } |
|
1970 |
| |
|
1971 |
| |
|
1972 |
| |
|
1973 |
105
| boolean hasOtherConstructor = sd.hasMethod(name);
|
|
1974 |
| |
|
1975 |
105
| for (VariableData field : sd.getVars()) {
|
|
1976 |
| |
|
1977 |
87
| if (! field.hasInitializer() && ! field.hasModifier("static")) {
|
|
1978 |
63
| if (! hasOtherConstructor) { field.gotValue(); }
|
|
1979 |
| |
|
1980 |
| |
|
1981 |
72
| VariableData param = field.copyWithoutVisibility();
|
|
1982 |
72
| params.add(param);
|
|
1983 |
| } |
|
1984 |
| } |
|
1985 |
| |
|
1986 |
| |
|
1987 |
105
| md.setParams(params.toArray(new VariableData[params.size()]));
|
|
1988 |
105
| md.setVars(params);
|
|
1989 |
| |
|
1990 |
| |
|
1991 |
| |
|
1992 |
| |
|
1993 |
105
| addGeneratedMethod(sd, md);
|
|
1994 |
| } |
|
1995 |
105
| LanguageLevelConverter._newSDs.remove(sd);
|
|
1996 |
| } |
|
1997 |
| |
|
1998 |
| |
|
1999 |
| |
|
2000 |
| |
|
2001 |
| |
|
2002 |
| |
|
2003 |
132
| protected static void createAccessors(SymbolData sd, File file) {
|
|
2004 |
0
| if (LanguageLevelConverter.isAdvancedFile(file)) return;
|
|
2005 |
132
| LinkedList<VariableData> fields = sd.getVars();
|
|
2006 |
132
| for (final VariableData vd: fields) {
|
|
2007 |
85
| if (! vd.hasModifier("static")) {
|
|
2008 |
74
| String name = getFieldAccessorName(vd.getName());
|
|
2009 |
74
| SymbolData returnTypeSD = vd.getType();
|
|
2010 |
74
| final MethodData md = new MethodData(name,
|
|
2011 |
| PUBLIC_MAV, |
|
2012 |
| new TypeParameter[0], |
|
2013 |
| returnTypeSD, |
|
2014 |
| new VariableData[0], |
|
2015 |
| new String[0], |
|
2016 |
| sd, |
|
2017 |
| null); |
|
2018 |
74
| addGeneratedMethod(sd, md);
|
|
2019 |
74
| if (returnTypeSD == null) {
|
|
2020 |
3
| Command fixUp = new Command() {
|
|
2021 |
3
| public void execute() { md.setReturnType(vd.getType()); }
|
|
2022 |
| }; |
|
2023 |
3
| fixUps.add(fixUp);
|
|
2024 |
| } |
|
2025 |
| } |
|
2026 |
| } |
|
2027 |
| } |
|
2028 |
| |
|
2029 |
| |
|
2030 |
| |
|
2031 |
| |
|
2032 |
119
| protected void createToString(SymbolData sd) {
|
|
2033 |
119
| String name = "toString";
|
|
2034 |
119
| MethodData md = new MethodData(name,
|
|
2035 |
| PUBLIC_MAV, |
|
2036 |
| new TypeParameter[0], |
|
2037 |
| getSymbolData("java.lang.String", SourceInfo.make("java.lang.String")), |
|
2038 |
| new VariableData[0], |
|
2039 |
| new String[0], |
|
2040 |
| sd, |
|
2041 |
| null); |
|
2042 |
119
| addGeneratedMethod(sd, md);
|
|
2043 |
| } |
|
2044 |
| |
|
2045 |
| |
|
2046 |
| |
|
2047 |
| |
|
2048 |
119
| protected void createHashCode(SymbolData sd) {
|
|
2049 |
119
| String name = "hashCode";
|
|
2050 |
119
| MethodData md = new MethodData(name,
|
|
2051 |
| PUBLIC_MAV, |
|
2052 |
| new TypeParameter[0], |
|
2053 |
| SymbolData.INT_TYPE, |
|
2054 |
| new VariableData[0], |
|
2055 |
| new String[0], |
|
2056 |
| sd, |
|
2057 |
| null); |
|
2058 |
119
| addGeneratedMethod(sd, md);
|
|
2059 |
| } |
|
2060 |
| |
|
2061 |
| |
|
2062 |
| |
|
2063 |
| |
|
2064 |
119
| protected void createEquals(SymbolData sd) {
|
|
2065 |
119
| String name = "equals";
|
|
2066 |
119
| SymbolData type = getSymbolData("java.lang.Object", SourceInfo.make("java.lang.Object"));
|
|
2067 |
119
| VariableData param = new VariableData(type);
|
|
2068 |
119
| MethodData md = new MethodData(name,
|
|
2069 |
| PUBLIC_MAV, |
|
2070 |
| new TypeParameter[0], |
|
2071 |
| SymbolData.BOOLEAN_TYPE, |
|
2072 |
| new VariableData[] {param}, |
|
2073 |
| new String[0], |
|
2074 |
| sd, |
|
2075 |
| null); |
|
2076 |
119
| param.setEnclosingData(md);
|
|
2077 |
119
| addGeneratedMethod(sd, md);
|
|
2078 |
| } |
|
2079 |
| |
|
2080 |
| |
|
2081 |
| |
|
2082 |
| |
|
2083 |
| |
|
2084 |
| |
|
2085 |
4
| public Void forMemberType(MemberType that) {
|
|
2086 |
4
| forMemberTypeDoFirst(that);
|
|
2087 |
0
| if (prune(that)) return null;
|
|
2088 |
4
| return forMemberTypeOnly(that);
|
|
2089 |
| } |
|
2090 |
| |
|
2091 |
| |
|
2092 |
49
| public Void forStringLiteralOnly(StringLiteral that) {
|
|
2093 |
49
| getQualifiedSymbolData("java.lang.String", that.getSourceInfo(), true);
|
|
2094 |
49
| return null;
|
|
2095 |
| } |
|
2096 |
| |
|
2097 |
| |
|
2098 |
45
| public Void forSimpleNamedClassInstantiation(SimpleNamedClassInstantiation that) {
|
|
2099 |
45
| forSimpleNamedClassInstantiationDoFirst(that);
|
|
2100 |
0
| if (prune(that)) return null;
|
|
2101 |
45
| that.getType().visit(this);
|
|
2102 |
45
| that.getArguments().visit(this);
|
|
2103 |
| |
|
2104 |
| |
|
2105 |
| |
|
2106 |
| |
|
2107 |
| |
|
2108 |
45
| getSymbolData(that.getType().getName(), that.getSourceInfo());
|
|
2109 |
| |
|
2110 |
| |
|
2111 |
| |
|
2112 |
45
| return forSimpleNamedClassInstantiationOnly(that);
|
|
2113 |
| } |
|
2114 |
| |
|
2115 |
| |
|
2116 |
| |
|
2117 |
| |
|
2118 |
| |
|
2119 |
89993
| public static boolean arrayEquals(Object[] array1, Object[] array2) {
|
|
2120 |
| |
|
2121 |
89993
| int n = array1.length;
|
|
2122 |
7
| if (n != array2.length) return false;
|
|
2123 |
89986
| for (int i = 0; i < n; i++) {
|
|
2124 |
36
| Object o1 = array1[i];
|
|
2125 |
36
| Object o2 = array2[i];
|
|
2126 |
0
| if (o1 == null && o2 != null) return false;
|
|
2127 |
2
| if (! o1.equals(o2)) return false;
|
|
2128 |
| }; |
|
2129 |
89984
| return true;
|
|
2130 |
| } |
|
2131 |
| |
|
2132 |
| |
|
2133 |
| private class ResolveNameVisitor extends JExpressionIFAbstractVisitor<TypeData> { |
|
2134 |
| |
|
2135 |
205
| public ResolveNameVisitor() { }
|
|
2136 |
| |
|
2137 |
| |
|
2138 |
2
| public TypeData defaultCase(JExpressionIF that) {
|
|
2139 |
2
| that.visit(LanguageLevelVisitor.this);
|
|
2140 |
2
| return null;
|
|
2141 |
| } |
|
2142 |
| |
|
2143 |
| |
|
2144 |
| |
|
2145 |
| |
|
2146 |
| |
|
2147 |
203
| public TypeData forSimpleNameReference(SimpleNameReference that) {
|
|
2148 |
203
| SymbolData result = getSymbolData(that.getName().getText(), that.getSourceInfo());
|
|
2149 |
| |
|
2150 |
| |
|
2151 |
203
| if (result == SymbolData.NOT_FOUND) {
|
|
2152 |
0
| return new PackageData(that.getName().getText());
|
|
2153 |
| } |
|
2154 |
203
| return result;
|
|
2155 |
| } |
|
2156 |
| |
|
2157 |
| |
|
2158 |
| |
|
2159 |
| |
|
2160 |
| |
|
2161 |
21
| public TypeData forComplexNameReference(ComplexNameReference that) {
|
|
2162 |
21
| TypeData lhs = that.getEnclosing().visit(this);
|
|
2163 |
21
| SymbolData result = getSymbolData(lhs, that.getName().getText(), that.getSourceInfo(), true);
|
|
2164 |
| |
|
2165 |
| |
|
2166 |
21
| if (result == SymbolData.NOT_FOUND) {
|
|
2167 |
0
| if (lhs instanceof PackageData) {
|
|
2168 |
0
| return new PackageData((PackageData) lhs, that.getName().getText());
|
|
2169 |
| } |
|
2170 |
0
| return null;
|
|
2171 |
| } |
|
2172 |
21
| return result;
|
|
2173 |
| } |
|
2174 |
| } |
|
2175 |
| |
|
2176 |
| |
|
2177 |
| public static class LanguageLevelVisitorTest extends TestCase { |
|
2178 |
| |
|
2179 |
| private LanguageLevelVisitor testLLVisitor; |
|
2180 |
| private Hashtable<SymbolData, LanguageLevelVisitor> testNewSDs; |
|
2181 |
| |
|
2182 |
| private SymbolData _sd1; |
|
2183 |
| private SymbolData _sd2; |
|
2184 |
| private SymbolData _sd3; |
|
2185 |
| private SymbolData _sd4; |
|
2186 |
| private SymbolData _sd5; |
|
2187 |
| private SymbolData _sd6; |
|
2188 |
| |
|
2189 |
0
| public LanguageLevelVisitorTest() { this(""); }
|
|
2190 |
27
| public LanguageLevelVisitorTest(String name) { super(name); }
|
|
2191 |
| |
|
2192 |
27
| public void setUp() {
|
|
2193 |
27
| Hashtable<String, Triple<SourceInfo, LanguageLevelVisitor, SymbolData>> continuations =
|
|
2194 |
| new Hashtable<String, Triple<SourceInfo, LanguageLevelVisitor, SymbolData>>(); |
|
2195 |
27
| LinkedList<Command> fixUps = new LinkedList<Command>();
|
|
2196 |
| |
|
2197 |
| |
|
2198 |
27
| testLLVisitor = new LanguageLevelVisitor(new File(""),
|
|
2199 |
| "", |
|
2200 |
| "i.like.monkey", |
|
2201 |
| new LinkedList<String>(), |
|
2202 |
| new LinkedList<String>(), |
|
2203 |
| new HashSet<String>(), |
|
2204 |
| continuations, |
|
2205 |
| fixUps); |
|
2206 |
27
| errors = new LinkedList<Pair<String, JExpressionIF>>();
|
|
2207 |
27
| _errorAdded = false;
|
|
2208 |
| |
|
2209 |
27
| visitedFiles = new LinkedList<Pair<LanguageLevelVisitor, SourceFile>>();
|
|
2210 |
| |
|
2211 |
27
| testLLVisitor._classesInThisFile = new HashSet<String>();
|
|
2212 |
0
| if (! testLLVisitor._importedPackages.contains("java.lang")) testLLVisitor._importedPackages.add("java.lang");
|
|
2213 |
| |
|
2214 |
27
| _sd1 = new SymbolData("i.like.monkey");
|
|
2215 |
27
| _sd2 = new SymbolData("i.like.giraffe");
|
|
2216 |
27
| _sd3 = new SymbolData("zebra");
|
|
2217 |
27
| _sd4 = new SymbolData("u.like.emu");
|
|
2218 |
27
| _sd5 = new SymbolData("");
|
|
2219 |
27
| _sd6 = new SymbolData("cebu");
|
|
2220 |
| } |
|
2221 |
| |
|
2222 |
| |
|
2223 |
1
| public void testGetUnqualifiedClassName() {
|
|
2224 |
1
| assertEquals("getUnqualifiedClassName with a qualified name with an inner class", "innermonkey",
|
|
2225 |
| testLLVisitor.getUnqualifiedClassName("i.like.monkey$innermonkey")); |
|
2226 |
1
| assertEquals("getUnqualifiedClassName with a qualified name", "monkey",
|
|
2227 |
| testLLVisitor.getUnqualifiedClassName("i.like.monkey")); |
|
2228 |
1
| assertEquals("getUnqualifiedClassName with an unqualified name", "monkey",
|
|
2229 |
| testLLVisitor.getUnqualifiedClassName("monkey")); |
|
2230 |
1
| assertEquals("getUnqualifiedClassName with an empty string", "", testLLVisitor.getUnqualifiedClassName(""));
|
|
2231 |
| } |
|
2232 |
| |
|
2233 |
1
| public void testClassFile2SymbolData() {
|
|
2234 |
| |
|
2235 |
| |
|
2236 |
1
| SymbolData objectSD = LanguageLevelConverter._classFile2SymbolData("java.lang.Object", "");
|
|
2237 |
1
| SymbolData stringSD = LanguageLevelConverter._classFile2SymbolData("java.lang.String", "");
|
|
2238 |
1
| MethodData md = new MethodData("substring", PUBLIC_MAV, new TypeParameter[0], stringSD,
|
|
2239 |
| new VariableData[] {new VariableData(SymbolData.INT_TYPE)}, |
|
2240 |
| new String[0], stringSD, null); |
|
2241 |
1
| assertTrue("java.lang.String should have been converted successfully",
|
|
2242 |
| stringSD.getName().equals("java.lang.String")); |
|
2243 |
1
| assertEquals("java.lang.String's superSD should should be java.lang.Object",
|
|
2244 |
| objectSD, |
|
2245 |
| stringSD.getSuperClass()); |
|
2246 |
| |
|
2247 |
1
| LinkedList<MethodData> methods = stringSD.getMethods();
|
|
2248 |
1
| Iterator<MethodData> iter = methods.iterator();
|
|
2249 |
1
| boolean found = false;
|
|
2250 |
| |
|
2251 |
32
| while (iter.hasNext()) {
|
|
2252 |
32
| MethodData currMd = iter.next();
|
|
2253 |
32
| if (currMd.getName().equals("substring") && currMd.getParams().length == 1 &&
|
|
2254 |
| currMd.getParams()[0].getInstanceData() == SymbolData.INT_TYPE.getInstanceData()) { |
|
2255 |
| |
|
2256 |
1
| found = true;
|
|
2257 |
1
| md.getParams()[0].setEnclosingData(currMd);
|
|
2258 |
1
| break;
|
|
2259 |
| } |
|
2260 |
| } |
|
2261 |
| |
|
2262 |
1
| assertTrue("Should have found method substring(int) in java.lang.String", found);
|
|
2263 |
| |
|
2264 |
1
| assertEquals("java.lang.String should be packaged correctly", "java.lang",
|
|
2265 |
| testLLVisitor.getSymbolData("java.lang.String", SourceInfo.NONE).getPackage()); |
|
2266 |
| |
|
2267 |
| |
|
2268 |
1
| SymbolData newStringSD = LanguageLevelConverter._classFile2SymbolData("java.lang.String", "");
|
|
2269 |
1
| assertTrue("Second call to classFileToSymbolData should not change sd in hash table.",
|
|
2270 |
| stringSD == LanguageLevelConverter.symbolTable.get("java.lang.String")); |
|
2271 |
1
| assertTrue("Second call to classFileToSymbolData should return same SD.",
|
|
2272 |
| newStringSD == LanguageLevelConverter.symbolTable.get("java.lang.String")); |
|
2273 |
| |
|
2274 |
| |
|
2275 |
1
| SymbolData bartSD = LanguageLevelConverter._classFile2SymbolData("Bart", "testFiles");
|
|
2276 |
1
| assertFalse("bartSD should not be null", bartSD == null);
|
|
2277 |
1
| assertFalse("bartSD should not be a continuation", bartSD.isContinuation());
|
|
2278 |
1
| MethodData md1 =
|
|
2279 |
| new MethodData("myMethod", PROTECTED_MAV, |
|
2280 |
| new TypeParameter[0], SymbolData.BOOLEAN_TYPE, |
|
2281 |
| new VariableData[] { new VariableData(SymbolData.INT_TYPE) }, |
|
2282 |
| new String[] {"java.lang.Exception"}, bartSD, null); |
|
2283 |
| |
|
2284 |
1
| md1.getParams()[0].setEnclosingData(bartSD.getMethods().getLast());
|
|
2285 |
1
| MethodData md2 = new MethodData("Bart", PUBLIC_MAV, new TypeParameter[0], bartSD,
|
|
2286 |
| new VariableData[0], new String[0], bartSD, null); |
|
2287 |
| |
|
2288 |
1
| VariableData vd1 = new VariableData("i", PUBLIC_MAV, SymbolData.INT_TYPE, true, bartSD);
|
|
2289 |
| |
|
2290 |
1
| LinkedList<MethodData> bartsMD = new LinkedList<MethodData>();
|
|
2291 |
1
| bartsMD.addFirst(md1);
|
|
2292 |
1
| bartsMD.addFirst(md2);
|
|
2293 |
| |
|
2294 |
1
| LinkedList<VariableData> bartsVD = new LinkedList<VariableData>();
|
|
2295 |
1
| bartsVD.addLast(vd1);
|
|
2296 |
| |
|
2297 |
1
| assertEquals("Bart's super class should be java.lang.Object: errors = " + errors, objectSD,
|
|
2298 |
| bartSD.getSuperClass()); |
|
2299 |
1
| assertEquals("Bart's Variable Data should be a linked list containing only vd1", bartsVD, bartSD.getVars());
|
|
2300 |
1
| assertEquals("The first method data of bart's should be correct", md2, bartSD.getMethods().getFirst());
|
|
2301 |
| |
|
2302 |
1
| assertEquals("The second method data of bart's should be correct", md1, bartSD.getMethods().getLast());
|
|
2303 |
1
| assertEquals("Bart's Method Data should be a linked list containing only md1", bartsMD, bartSD.getMethods());
|
|
2304 |
| } |
|
2305 |
| |
|
2306 |
| |
|
2307 |
| |
|
2308 |
| |
|
2309 |
| |
|
2310 |
| |
|
2311 |
| |
|
2312 |
| |
|
2313 |
| |
|
2314 |
| |
|
2315 |
| |
|
2316 |
| |
|
2317 |
| |
|
2318 |
| |
|
2319 |
| |
|
2320 |
| |
|
2321 |
| |
|
2322 |
| |
|
2323 |
| |
|
2324 |
| |
|
2325 |
| |
|
2326 |
| |
|
2327 |
| |
|
2328 |
| |
|
2329 |
| |
|
2330 |
| |
|
2331 |
| |
|
2332 |
| |
|
2333 |
| |
|
2334 |
| |
|
2335 |
| |
|
2336 |
| |
|
2337 |
| |
|
2338 |
| |
|
2339 |
| |
|
2340 |
| |
|
2341 |
| |
|
2342 |
| |
|
2343 |
| |
|
2344 |
| |
|
2345 |
| |
|
2346 |
1
| public void testGetSymbolDataForClassFile() {
|
|
2347 |
| |
|
2348 |
1
| assertFalse("Should return a non-continuation",
|
|
2349 |
| LanguageLevelConverter.getSymbolDataForClassFile("java.lang.String", null).isContinuation()); |
|
2350 |
| |
|
2351 |
| |
|
2352 |
1
| assertNull("Should return null with a user class that can't be found",
|
|
2353 |
| LanguageLevelConverter.getSymbolDataForClassFile("Marge", null)); |
|
2354 |
| |
|
2355 |
| |
|
2356 |
| } |
|
2357 |
| |
|
2358 |
| |
|
2359 |
1
| public void testGetSymbolData_Primitive() {
|
|
2360 |
1
| assertEquals("should be boolean type", SymbolData.BOOLEAN_TYPE,
|
|
2361 |
| LanguageLevelConverter._getPrimitiveSymbolData("boolean")); |
|
2362 |
1
| assertEquals("should be char type", SymbolData.CHAR_TYPE, LanguageLevelConverter._getPrimitiveSymbolData("char"));
|
|
2363 |
1
| assertEquals("should be byte type", SymbolData.BYTE_TYPE, LanguageLevelConverter._getPrimitiveSymbolData("byte"));
|
|
2364 |
1
| assertEquals("should be short type", SymbolData.SHORT_TYPE, LanguageLevelConverter._getPrimitiveSymbolData("short"));
|
|
2365 |
1
| assertEquals("should be int type", SymbolData.INT_TYPE, LanguageLevelConverter._getPrimitiveSymbolData("int"));
|
|
2366 |
1
| assertEquals("should be long type", SymbolData.LONG_TYPE, LanguageLevelConverter._getPrimitiveSymbolData("long"));
|
|
2367 |
1
| assertEquals("should be float type", SymbolData.FLOAT_TYPE, LanguageLevelConverter._getPrimitiveSymbolData("float"));
|
|
2368 |
1
| assertEquals("should be double type", SymbolData.DOUBLE_TYPE, LanguageLevelConverter._getPrimitiveSymbolData("double"));
|
|
2369 |
1
| assertEquals("should be void type", SymbolData.VOID_TYPE, LanguageLevelConverter._getPrimitiveSymbolData("void"));
|
|
2370 |
1
| assertEquals("should be null type", SymbolData.NULL_TYPE, LanguageLevelConverter._getPrimitiveSymbolData("null"));
|
|
2371 |
1
| assertEquals("should return null--not a primitive", null,
|
|
2372 |
| LanguageLevelConverter._getPrimitiveSymbolData("java.lang.String")); |
|
2373 |
| } |
|
2374 |
| |
|
2375 |
| |
|
2376 |
| |
|
2377 |
| |
|
2378 |
| |
|
2379 |
| |
|
2380 |
| |
|
2381 |
| |
|
2382 |
| |
|
2383 |
| |
|
2384 |
| |
|
2385 |
| |
|
2386 |
| |
|
2387 |
| |
|
2388 |
| |
|
2389 |
| |
|
2390 |
| |
|
2391 |
| |
|
2392 |
| |
|
2393 |
| |
|
2394 |
| |
|
2395 |
| |
|
2396 |
| |
|
2397 |
| |
|
2398 |
| |
|
2399 |
| |
|
2400 |
| |
|
2401 |
| |
|
2402 |
| |
|
2403 |
| |
|
2404 |
| |
|
2405 |
| |
|
2406 |
| |
|
2407 |
| |
|
2408 |
| |
|
2409 |
| |
|
2410 |
| |
|
2411 |
| |
|
2412 |
| |
|
2413 |
| |
|
2414 |
| |
|
2415 |
| |
|
2416 |
| |
|
2417 |
| |
|
2418 |
| |
|
2419 |
| |
|
2420 |
| |
|
2421 |
| |
|
2422 |
| |
|
2423 |
| |
|
2424 |
| |
|
2425 |
| |
|
2426 |
| |
|
2427 |
| |
|
2428 |
| |
|
2429 |
| |
|
2430 |
| |
|
2431 |
1
| public void testGetArraySymbolData() {
|
|
2432 |
| |
|
2433 |
1
| assertEquals("Should return null, because inner sd is null.", null,
|
|
2434 |
| testLLVisitor.getArraySymbolData("TestFile", SourceInfo.NONE, false, false)); |
|
2435 |
| |
|
2436 |
| |
|
2437 |
1
| SymbolData sd = new SymbolData("Iexist");
|
|
2438 |
1
| LanguageLevelConverter.symbolTable.put("Iexist", sd);
|
|
2439 |
1
| testLLVisitor.getArraySymbolData("Iexist", SourceInfo.NONE, false, false).getName();
|
|
2440 |
1
| assertTrue("Should have created an array data and add it to symbol table.",
|
|
2441 |
| LanguageLevelConverter.symbolTable.containsKey("Iexist[]")); |
|
2442 |
1
| SymbolData ad = LanguageLevelConverter.symbolTable.get("Iexist[]");
|
|
2443 |
| |
|
2444 |
| |
|
2445 |
1
| assertEquals("Should only have field 'length'", 1, ad.getVars().size());
|
|
2446 |
1
| assertNotNull("Should contain field 'length'", ad.getVar("length"));
|
|
2447 |
| |
|
2448 |
1
| assertEquals("Should only have one method-clone", 1, ad.getMethods().size());
|
|
2449 |
1
| assertTrue("Should contain method clone", ad.hasMethod("clone"));
|
|
2450 |
| |
|
2451 |
1
| assertEquals("Should have Object as super class",
|
|
2452 |
| LanguageLevelConverter.symbolTable.get("java.lang.Object"), |
|
2453 |
| ad.getSuperClass()); |
|
2454 |
1
| assertEquals("Should have 2 interfaces", 2, ad.getInterfaces().size());
|
|
2455 |
1
| assertEquals("Interface 1 should be java.lang.Cloneable", "java.lang.Cloneable",
|
|
2456 |
| ad.getInterfaces().get(0).getName()); |
|
2457 |
1
| assertEquals("Interface 2 should be java.io.Serializable", "java.io.Serializable",
|
|
2458 |
| ad.getInterfaces().get(1).getName()); |
|
2459 |
| |
|
2460 |
| |
|
2461 |
| |
|
2462 |
1
| assertEquals("Since it's already in symbol table now, should just return it.", ad,
|
|
2463 |
| testLLVisitor.getArraySymbolData("Iexist", SourceInfo.NONE, false, false)); |
|
2464 |
| |
|
2465 |
| |
|
2466 |
1
| testLLVisitor.getArraySymbolData("Iexist[]", SourceInfo.NONE, false, false);
|
|
2467 |
1
| assertTrue("Should have added a multidimensional array to the table.",
|
|
2468 |
| LanguageLevelConverter.symbolTable.containsKey("Iexist[][]")); |
|
2469 |
| |
|
2470 |
1
| SymbolData sd2 = new SymbolData("java.lang.String");
|
|
2471 |
1
| LanguageLevelConverter.symbolTable.put("java.lang.String", sd2);
|
|
2472 |
1
| testLLVisitor.getArraySymbolData("String[]", SourceInfo.NONE, false, true);
|
|
2473 |
1
| assertTrue("Should have added java.lang.String[] to table",
|
|
2474 |
| LanguageLevelConverter.symbolTable.containsKey("java.lang.String[]")); |
|
2475 |
1
| assertTrue("Should have added java.lang.String[][] to table",
|
|
2476 |
| LanguageLevelConverter.symbolTable.containsKey("java.lang.String[][]")); |
|
2477 |
| } |
|
2478 |
| |
|
2479 |
1
| public void testGetSymbolDataFromFileSystem() {
|
|
2480 |
1
| _sd4.setIsContinuation(false);
|
|
2481 |
1
| _sd6.setIsContinuation(true);
|
|
2482 |
1
| LanguageLevelConverter.symbolTable.put("u.like.emu", _sd4);
|
|
2483 |
1
| LanguageLevelConverter.symbolTable.put("cebu", _sd6);
|
|
2484 |
| |
|
2485 |
| |
|
2486 |
| |
|
2487 |
1
| assertEquals("symbol data is a not a continuation, but resolve is false so should just be returned", _sd6,
|
|
2488 |
| testLLVisitor._getSymbolDataFromFileSystem("cebu", SourceInfo.NONE, false, true)); |
|
2489 |
1
| assertEquals("symbol data is a continuation, but resolve is false, so should just be returned.", _sd4,
|
|
2490 |
| testLLVisitor._getSymbolDataFromFileSystem("u.like.emu", SourceInfo.NONE, false, true)); |
|
2491 |
| |
|
2492 |
| |
|
2493 |
| |
|
2494 |
1
| assertEquals("Should return SymbolData.NOT_FOUND", SymbolData.NOT_FOUND,
|
|
2495 |
| testLLVisitor._getSymbolDataFromFileSystem("Corky", SourceInfo.NONE, false, true)); |
|
2496 |
| |
|
2497 |
| |
|
2498 |
| |
|
2499 |
| |
|
2500 |
| |
|
2501 |
1
| ClassDef cd =
|
|
2502 |
| new ClassDef(SourceInfo.NONE, PUBLIC_MAV, |
|
2503 |
| new Word(SourceInfo.NONE, "Lisa"), |
|
2504 |
| new TypeParameter[0], |
|
2505 |
| new ClassOrInterfaceType(SourceInfo.NONE, "java.lang.Object", new Type[0]), |
|
2506 |
| new ReferenceType[0], |
|
2507 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
2508 |
| |
|
2509 |
| |
|
2510 |
1
| IntermediateVisitor bv = new IntermediateVisitor(new File(""));
|
|
2511 |
| |
|
2512 |
1
| testLLVisitor._classesInThisFile.add("Lisa" );
|
|
2513 |
1
| assert testLLVisitor._classesInThisFile.contains("Lisa");
|
|
2514 |
1
| SymbolData matchLisa =
|
|
2515 |
| testLLVisitor.getQualifiedSymbolData("Lisa", SourceInfo.NONE, true); |
|
2516 |
1
| assertTrue("Should return a continuation", matchLisa.isContinuation());
|
|
2517 |
| } |
|
2518 |
| |
|
2519 |
1
| public void testGetSymbolDataFromFileSystem2() {
|
|
2520 |
| |
|
2521 |
| |
|
2522 |
| |
|
2523 |
1
| testLLVisitor._package="fully.qualified";
|
|
2524 |
1
| testLLVisitor._file = new File("testFiles/fully/qualified/Fake.dj0");
|
|
2525 |
1
| SymbolData sd2 = new SymbolData("fully.qualified.Woah");
|
|
2526 |
1
| testLLVisitor.symbolTable.put("fully.qualified.Woah", sd2);
|
|
2527 |
| |
|
2528 |
1
| SymbolData result =
|
|
2529 |
| testLLVisitor._getSymbolDataFromFileSystem("fully.qualified.Woah", SourceInfo.NONE, false, true); |
|
2530 |
| |
|
2531 |
1
| assertEquals("Should return sd2, unresolved.", sd2, result);
|
|
2532 |
1
| assertTrue("sd2 should still be unresolved", sd2.isContinuation());
|
|
2533 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
2534 |
| |
|
2535 |
| |
|
2536 |
| |
|
2537 |
| |
|
2538 |
| |
|
2539 |
| |
|
2540 |
| |
|
2541 |
| |
|
2542 |
| |
|
2543 |
| |
|
2544 |
| |
|
2545 |
| |
|
2546 |
| |
|
2547 |
1
| testLLVisitor.symbolTable.remove("fully.qualified.Woah");
|
|
2548 |
1
| testLLVisitor.visitedFiles.clear();
|
|
2549 |
1
| testLLVisitor._package="another.package";
|
|
2550 |
1
| testLLVisitor._file = new File("testFiles/another/package/Wowsers.dj0");
|
|
2551 |
1
| sd2 = new SymbolData("fully.qualified.Woah");
|
|
2552 |
1
| testLLVisitor.symbolTable.put("fully.qualified.Woah", sd2);
|
|
2553 |
| |
|
2554 |
1
| result = testLLVisitor._getSymbolDataFromFileSystem("fully.qualified.Woah", SourceInfo.NONE, false, true);
|
|
2555 |
| |
|
2556 |
1
| assertEquals("Should return sd2, unresolved.", sd2, result);
|
|
2557 |
1
| assertTrue("sd2 should still be unresolved", sd2.isContinuation());
|
|
2558 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
2559 |
| |
|
2560 |
| |
|
2561 |
| |
|
2562 |
| |
|
2563 |
| |
|
2564 |
| |
|
2565 |
| |
|
2566 |
| |
|
2567 |
| |
|
2568 |
1
| testLLVisitor._package = "";
|
|
2569 |
1
| testLLVisitor._file = new File ("testFiles/Cool.dj0");
|
|
2570 |
| |
|
2571 |
| |
|
2572 |
1
| SymbolData sd1 = new SymbolData("Wow");
|
|
2573 |
1
| SymbolData obj = testLLVisitor._getSymbolDataFromFileSystem("java.lang.Object", SourceInfo.NONE, true, true);
|
|
2574 |
1
| sd1.setSuperClass(obj);
|
|
2575 |
1
| testLLVisitor.symbolTable.put("Wow", sd1);
|
|
2576 |
| |
|
2577 |
1
| result = testLLVisitor._getSymbolDataFromFileSystem("Wow", SourceInfo.NONE, false, true);
|
|
2578 |
1
| assertEquals("Should return sd1, unresolved.", sd1, result);
|
|
2579 |
1
| assertTrue("sd1 should still be unresolved.", sd1.isContinuation());
|
|
2580 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
2581 |
| |
|
2582 |
1
| result = testLLVisitor._getSymbolDataFromFileSystem("Wow", SourceInfo.NONE, true, true);
|
|
2583 |
1
| assertEquals("Should return sd1, resolved.", sd1, result);
|
|
2584 |
1
| assertFalse("sd1 should be resolved.", sd1.isContinuation());
|
|
2585 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
2586 |
| |
|
2587 |
1
| result = testLLVisitor._getSymbolDataFromFileSystem("Wow", SourceInfo.NONE, true, true);
|
|
2588 |
1
| assertEquals("Should return sd1.", sd1, result);
|
|
2589 |
1
| assertFalse("sd1 should still be resolved.", sd1.isContinuation());
|
|
2590 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
2591 |
| |
|
2592 |
| |
|
2593 |
| |
|
2594 |
1
| result = testLLVisitor._getSymbolDataFromFileSystem("James", SourceInfo.NONE, true, true);
|
|
2595 |
1
| assertEquals("Search for James should fail", null, result);
|
|
2596 |
| |
|
2597 |
| |
|
2598 |
| |
|
2599 |
| |
|
2600 |
1
| testLLVisitor._package = "myPackage";
|
|
2601 |
1
| assertEquals("Should return NOT_FOUND-does not exist.",
|
|
2602 |
| SymbolData.NOT_FOUND, |
|
2603 |
| testLLVisitor._getSymbolDataFromFileSystem("WrongPackage.className", |
|
2604 |
| SourceInfo.NONE, true, false)); |
|
2605 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
2606 |
| |
|
2607 |
| |
|
2608 |
1
| testLLVisitor._package = "";
|
|
2609 |
1
| testLLVisitor._file = new File("testFiles/Fake.dj0");
|
|
2610 |
1
| LinkedList<VariableData> vds = new LinkedList<VariableData>();
|
|
2611 |
1
| result = testLLVisitor._getSymbolDataFromFileSystem("Doh", SourceInfo.NONE, true, true);
|
|
2612 |
1
| vds.addLast(new VariableData("i", PACKAGE_MAV, SymbolData.INT_TYPE, true, result));
|
|
2613 |
1
| vds.addLast(new VariableData("o", PACKAGE_MAV, obj, true, result));
|
|
2614 |
| |
|
2615 |
| |
|
2616 |
| |
|
2617 |
| |
|
2618 |
| |
|
2619 |
| |
|
2620 |
| } |
|
2621 |
| |
|
2622 |
1
| public void testGetSymbolData() {
|
|
2623 |
1
| testLLVisitor._package="";
|
|
2624 |
1
| testLLVisitor._file = new File("testFiles/akdjskj");
|
|
2625 |
| |
|
2626 |
| |
|
2627 |
1
| SymbolData sd1 = new SymbolData("Wow");
|
|
2628 |
1
| testLLVisitor.symbolTable.put("Wow", sd1);
|
|
2629 |
1
| assertEquals("Should return an equal SymbolData",
|
|
2630 |
| sd1, testLLVisitor.getQualifiedSymbolData("Wow", SourceInfo.NONE, true)); |
|
2631 |
1
| assertFalse("Should not be a continuation", sd1.isContinuation());
|
|
2632 |
| |
|
2633 |
| |
|
2634 |
1
| SymbolData result = testLLVisitor.getSymbolData("ima.invalid", SourceInfo.NONE, true, false);
|
|
2635 |
1
| assertEquals("Should return null-invalid class name", null, result);
|
|
2636 |
1
| assertEquals("There should not be any errors", 0, testLLVisitor.errors.size());
|
|
2637 |
| |
|
2638 |
| |
|
2639 |
1
| testLLVisitor._package="fully.qualified";
|
|
2640 |
1
| testLLVisitor._file = new File("testFiles/fully/qualified/Fake.dj0");
|
|
2641 |
1
| SymbolData sd2 = new SymbolData("fully.qualified.Symbol");
|
|
2642 |
1
| testLLVisitor.symbolTable.put("fully.qualified.Symbol", sd2);
|
|
2643 |
| |
|
2644 |
1
| result = testLLVisitor.getSymbolData("fully.qualified.Symbol", SourceInfo.NONE, true, false);
|
|
2645 |
| |
|
2646 |
1
| assertEquals("Should return sd2, resolved.", sd2, result);
|
|
2647 |
1
| assertTrue("sd2 should be resolved", sd2.isContinuation());
|
|
2648 |
| |
|
2649 |
| |
|
2650 |
1
| sd1.setName("fully.qualified.Woah.Wow");
|
|
2651 |
1
| sd2.addInnerClass(sd1);
|
|
2652 |
1
| sd1.setOuterData(sd2);
|
|
2653 |
1
| testLLVisitor.symbolTable.put("fully.qualified.Woah.Wow", sd1);
|
|
2654 |
1
| testLLVisitor.symbolTable.remove("Wow");
|
|
2655 |
1
| sd1.setIsContinuation(false);
|
|
2656 |
1
| result = testLLVisitor.getSymbolData("fully.qualified.Woah.Wow", SourceInfo.NONE, true, false);
|
|
2657 |
1
| assertEquals("Should return sd1 (the inner class!)", sd1, result);
|
|
2658 |
| |
|
2659 |
| |
|
2660 |
1
| SymbolData sd3 = new SymbolData("fully.qualified.Woah.Wow.James");
|
|
2661 |
1
| sd1.addInnerClass(sd3);
|
|
2662 |
| |
|
2663 |
| |
|
2664 |
1
| sd3.setOuterData(sd1);
|
|
2665 |
| |
|
2666 |
1
| result = testLLVisitor.getSymbolData("fully.qualified.Woah.Wow.James", SourceInfo.NONE, true, false);
|
|
2667 |
1
| assertEquals("Should return sd3", sd3, result);
|
|
2668 |
| } |
|
2669 |
| |
|
2670 |
1
| public void testGetQualifiedSymbolData() {
|
|
2671 |
| |
|
2672 |
1
| assertEquals("should return the int SymbolData", SymbolData.INT_TYPE,
|
|
2673 |
| testLLVisitor.getQualifiedSymbolData("int", SourceInfo.NONE, true, true, true)); |
|
2674 |
1
| assertEquals("should return the byte SymbolData", SymbolData.BYTE_TYPE,
|
|
2675 |
| testLLVisitor.getQualifiedSymbolData("byte", SourceInfo.NONE, false, false, false)); |
|
2676 |
| |
|
2677 |
| |
|
2678 |
1
| ArrayData ad = new ArrayData(SymbolData.INT_TYPE, testLLVisitor, SourceInfo.NONE);
|
|
2679 |
1
| SymbolData result = testLLVisitor.getQualifiedSymbolData("int[]", SourceInfo.NONE, true, true, true);
|
|
2680 |
1
| ad.getVars().get(0).setEnclosingData(result);
|
|
2681 |
1
| ad.getMethods().get(0).setEnclosingData(result.getMethods().get(0).getEnclosingData());
|
|
2682 |
1
| assertEquals("should return the array type", ad, result);
|
|
2683 |
| |
|
2684 |
| |
|
2685 |
1
| SymbolData sd = new SymbolData("java.lang.System");
|
|
2686 |
1
| LanguageLevelConverter.symbolTable.put("java.lang.System", sd);
|
|
2687 |
1
| assertEquals("should return the same sd", sd,
|
|
2688 |
| testLLVisitor.getQualifiedSymbolData("java.lang.System", SourceInfo.NONE, false, true, true)); |
|
2689 |
1
| assertTrue("should be a continuation", sd.isContinuation());
|
|
2690 |
1
| assertEquals("should return the now resolved sd", sd,
|
|
2691 |
| testLLVisitor.getQualifiedSymbolData("java.lang.System", SourceInfo.NONE, true, false, true)); |
|
2692 |
1
| assertFalse("should not be a continuation", sd.isContinuation());
|
|
2693 |
| |
|
2694 |
| |
|
2695 |
1
| sd = new SymbolData("fully.qualified.Qwerty");
|
|
2696 |
1
| LanguageLevelConverter.symbolTable.put("fully.qualified.Qwerty", sd);
|
|
2697 |
1
| testLLVisitor._classesInThisFile.add("fully.qualified.Qwerty");
|
|
2698 |
| |
|
2699 |
1
| IntermediateVisitor bv = new IntermediateVisitor(new File(""),
|
|
2700 |
| errors, |
|
2701 |
| continuations, |
|
2702 |
| fixUps, |
|
2703 |
| new LinkedList<Pair<LanguageLevelVisitor, SourceFile>>()); |
|
2704 |
1
| bv._package = "fully.qualified";
|
|
2705 |
1
| bv._file = new File("testFiles/fully/qualified/Fake.dj0");
|
|
2706 |
1
| ClassDef cd = new ClassDef(SourceInfo.NONE,
|
|
2707 |
| PACKAGE_MAV, |
|
2708 |
| new Word(SourceInfo.NONE, "Qwerty"), |
|
2709 |
| new TypeParameter[0], |
|
2710 |
| new ClassOrInterfaceType(SourceInfo.NONE, "java.lang.Object", new Type[0]), |
|
2711 |
| new ReferenceType[0], |
|
2712 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
2713 |
1
| bv._classesInThisFile.add("fully.qualified.Qwerty" );
|
|
2714 |
1
| assertEquals("should return sd the continuation", sd,
|
|
2715 |
| bv.getSymbolData("Qwerty", SourceInfo.NONE, true, true)); |
|
2716 |
1
| assertTrue("should be a continuation", sd.isContinuation());
|
|
2717 |
1
| assertEquals("should also return a continuation", sd,
|
|
2718 |
| bv.getQualifiedSymbolData("fully.qualified.Qwerty", SourceInfo.NONE, false, false, true)); |
|
2719 |
1
| assertTrue("should be a continuation", sd.isContinuation());
|
|
2720 |
| |
|
2721 |
| |
|
2722 |
1
| testLLVisitor._importedFiles.addLast("a.b.c");
|
|
2723 |
1
| sd = new SymbolData("a.b.c");
|
|
2724 |
| |
|
2725 |
1
| LanguageLevelConverter.symbolTable.put("a.b.c", sd);
|
|
2726 |
| |
|
2727 |
| |
|
2728 |
| |
|
2729 |
1
| assertEquals("should find the continuation in the symbol table", sd,
|
|
2730 |
| testLLVisitor.getQualifiedSymbolData("a.b.c", SourceInfo.NONE, false, true, true)); |
|
2731 |
| |
|
2732 |
1
| assertTrue("should be a continuation", sd.isContinuation());
|
|
2733 |
| |
|
2734 |
1
| testLLVisitor._package="fully.qualified";
|
|
2735 |
1
| testLLVisitor._file = new File("testFiles/fully/qualified/Fake.dj0");
|
|
2736 |
1
| testLLVisitor._importedFiles.addLast("fully.qualified.Woah");
|
|
2737 |
1
| SymbolData sd2 = new SymbolData("fully.qualified.Woah");
|
|
2738 |
1
| sd2.setIsContinuation(false);
|
|
2739 |
1
| LanguageLevelConverter.symbolTable.put("fully.qualified.Woah", sd2);
|
|
2740 |
1
| result = testLLVisitor.getQualifiedSymbolData("fully.qualified.Woah", SourceInfo.NONE, true, false, true);
|
|
2741 |
| |
|
2742 |
1
| assertEquals("should find the resolved symbol data in the symbol table", sd2, result);
|
|
2743 |
1
| assertFalse("should not be a continuation", sd2.isContinuation());
|
|
2744 |
| |
|
2745 |
| |
|
2746 |
1
| testLLVisitor._importedFiles.clear();
|
|
2747 |
1
| testLLVisitor.visitedFiles.clear();
|
|
2748 |
1
| LanguageLevelConverter.symbolTable.remove("fully.qualified.Woah");
|
|
2749 |
1
| sd2 = new SymbolData("fully.qualified.Woah");
|
|
2750 |
1
| LanguageLevelConverter.symbolTable.put("fully.qualified.Woah", sd2);
|
|
2751 |
| |
|
2752 |
| |
|
2753 |
| |
|
2754 |
| |
|
2755 |
| |
|
2756 |
1
| result = testLLVisitor.getQualifiedSymbolData("fully.qualified.Woah", SourceInfo.NONE, false, false, true);
|
|
2757 |
| |
|
2758 |
1
| assertEquals("Should return sd2, unresolved.", sd2, result);
|
|
2759 |
1
| assertTrue("sd2 should still be unresolved", sd2.isContinuation());
|
|
2760 |
| |
|
2761 |
1
| result = testLLVisitor.getQualifiedSymbolData("fully.qualified.Woah", SourceInfo.NONE, false, false, true);
|
|
2762 |
1
| assertEquals("Should return sd2, now unresolved.", sd2, result);
|
|
2763 |
1
| assertTrue("sd2 should not be resolved", sd2.isContinuation());
|
|
2764 |
| |
|
2765 |
| |
|
2766 |
| |
|
2767 |
1
| result = testLLVisitor.getQualifiedSymbolData("fully.qualified.Woah", SourceInfo.NONE, true, false, true);
|
|
2768 |
1
| assertEquals("Should return sd2, now resolved.", sd2, result);
|
|
2769 |
1
| assertFalse("sd2 should now be resolved", sd2.isContinuation());
|
|
2770 |
| |
|
2771 |
| |
|
2772 |
1
| LanguageLevelConverter.symbolTable.remove("fully.qualified.Woah");
|
|
2773 |
1
| testLLVisitor.visitedFiles.clear();
|
|
2774 |
1
| testLLVisitor._file = new File("testFiles/Fake.dj0");
|
|
2775 |
1
| testLLVisitor._package = "";
|
|
2776 |
1
| testLLVisitor._importedPackages.addLast("fully.qualified");
|
|
2777 |
1
| sd2 = new SymbolData("fully.qualified.Woah");
|
|
2778 |
1
| LanguageLevelConverter.symbolTable.put("fully.qualified.Woah", sd2);
|
|
2779 |
1
| assertEquals("should find the unresolved symbol data in the symbol table", sd2,
|
|
2780 |
| testLLVisitor.getQualifiedSymbolData("fully.qualified.Woah", SourceInfo.NONE, false, false, true)); |
|
2781 |
1
| assertTrue("should not be a continuation", sd2.isContinuation());
|
|
2782 |
| |
|
2783 |
1
| sd2.setIsContinuation(false);
|
|
2784 |
1
| result = testLLVisitor.getQualifiedSymbolData("fully.qualified.Woah", SourceInfo.NONE, true, false, true);
|
|
2785 |
1
| assertEquals("should find the resolved symbol data in the symbol table", sd2, result);
|
|
2786 |
1
| assertFalse("should not be a continuation", sd2.isContinuation());
|
|
2787 |
| |
|
2788 |
| |
|
2789 |
| |
|
2790 |
1
| SymbolData stringSD = new SymbolData("java.lang.String");
|
|
2791 |
1
| SymbolData newsd1 = testLLVisitor.getQualifiedSymbolData("java.lang.String", SourceInfo.NONE, true, true, true);
|
|
2792 |
1
| assertEquals("should have correct name.", stringSD.getName(), newsd1.getName());
|
|
2793 |
1
| assertFalse("should not be a continuation", newsd1.isContinuation());
|
|
2794 |
| |
|
2795 |
| |
|
2796 |
1
| LanguageLevelConverter.symbolTable.put("random.package.String", new SymbolData("random.package.String"));
|
|
2797 |
| |
|
2798 |
1
| testLLVisitor._importedPackages.addLast("random.package");
|
|
2799 |
1
| result = testLLVisitor.getSymbolData("String", SourceInfo.NONE);
|
|
2800 |
1
| assertEquals("Result should be null", null, result);
|
|
2801 |
1
| assertEquals("There should be 1 error", 1, errors.size());
|
|
2802 |
1
| assertEquals("The error message should be correct", "The class name String is ambiguous." +
|
|
2803 |
| " It could be java.lang.String or random.package.String", |
|
2804 |
| errors.get(0).getFirst()); |
|
2805 |
| |
|
2806 |
1
| LanguageLevelConverter.symbolTable.remove("random.package.String");
|
|
2807 |
| |
|
2808 |
| } |
|
2809 |
| |
|
2810 |
1
| public void test_forModifiersAndVisibility() {
|
|
2811 |
| |
|
2812 |
1
| testLLVisitor.forModifiersAndVisibility(PUBLIC_MAV);
|
|
2813 |
1
| testLLVisitor.forModifiersAndVisibility(PROTECTED_MAV);
|
|
2814 |
1
| testLLVisitor.forModifiersAndVisibility(PRIVATE_MAV);
|
|
2815 |
1
| testLLVisitor.forModifiersAndVisibility(PACKAGE_MAV);
|
|
2816 |
| |
|
2817 |
| |
|
2818 |
1
| assertEquals("There should be no errors.", 0, errors.size());
|
|
2819 |
| |
|
2820 |
| |
|
2821 |
1
| ModifiersAndVisibility testMav =
|
|
2822 |
| new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"public", "private"}); |
|
2823 |
1
| testLLVisitor.forModifiersAndVisibility(testMav);
|
|
2824 |
1
| assertEquals("There should be one error.", 1, errors.size());
|
|
2825 |
1
| assertEquals("The error message should be correct.", "Illegal combination of modifiers." +
|
|
2826 |
| " Can't use private and public together.", errors.get(0).getFirst()); |
|
2827 |
| |
|
2828 |
| |
|
2829 |
1
| testMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"public", "abstract"});
|
|
2830 |
1
| testLLVisitor.forModifiersAndVisibility(testMav);
|
|
2831 |
1
| assertEquals("Still only one error.", 1, errors.size());
|
|
2832 |
| |
|
2833 |
| |
|
2834 |
1
| testMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"abstract", "final"});
|
|
2835 |
1
| testLLVisitor.forModifiersAndVisibility(testMav);
|
|
2836 |
1
| assertEquals("There should be two errors.", 2, errors.size());
|
|
2837 |
1
| assertEquals("The error message should be correct.", "Illegal combination of modifiers." +
|
|
2838 |
| " Can't use final and abstract together.", errors.get(1).getFirst()); |
|
2839 |
| |
|
2840 |
| |
|
2841 |
1
| testMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"final", "abstract"});
|
|
2842 |
1
| testLLVisitor.forModifiersAndVisibility(testMav);
|
|
2843 |
1
| assertEquals("There should still be two errors.", 2, errors.size());
|
|
2844 |
1
| assertEquals("The error message should be correct.", "Illegal combination of modifiers." +
|
|
2845 |
| " Can't use final and abstract together.", errors.get(1).getFirst()); |
|
2846 |
| |
|
2847 |
| |
|
2848 |
1
| testMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"volatile", "final"});
|
|
2849 |
1
| testLLVisitor.forModifiersAndVisibility(testMav);
|
|
2850 |
1
| assertEquals("There should be three errors.", 3, errors.size());
|
|
2851 |
1
| assertEquals("The error message should be correct.", "Illegal combination of modifiers." +
|
|
2852 |
| " Can't use final and volatile together.", errors.get(2).getFirst()); |
|
2853 |
| |
|
2854 |
| |
|
2855 |
1
| testMav = new ModifiersAndVisibility(SourceInfo.NONE, new String[] {"static", "final", "static"});
|
|
2856 |
1
| testLLVisitor.forModifiersAndVisibility(testMav);
|
|
2857 |
1
| assertEquals("There should be four errors.", 4, errors.size());
|
|
2858 |
1
| assertEquals("The error message should be correct.", "Duplicate modifier: static", errors.get(3).getFirst());
|
|
2859 |
| } |
|
2860 |
| |
|
2861 |
1
| public void testGetQualifiedClassName() {
|
|
2862 |
| |
|
2863 |
1
| testLLVisitor._package="";
|
|
2864 |
1
| assertEquals("Should not change qualified name.", "simpson.Bart",
|
|
2865 |
| testLLVisitor.getQualifiedClassName("simpson.Bart")); |
|
2866 |
1
| assertEquals("Should not change unqualified name.", "Lisa", testLLVisitor.getQualifiedClassName("Lisa"));
|
|
2867 |
| |
|
2868 |
| |
|
2869 |
1
| testLLVisitor._package="myPackage";
|
|
2870 |
1
| assertEquals("Should not change properly packaged qualified name.", "myPackage.Snowball",
|
|
2871 |
| testLLVisitor.getQualifiedClassName("myPackage.Snowball")); |
|
2872 |
1
| assertEquals("Should append package to front of not fully packaged name", "myPackage.simpson.Snowball",
|
|
2873 |
| testLLVisitor.getQualifiedClassName("simpson.Snowball")); |
|
2874 |
1
| assertEquals("Should append package to front of unqualified class name.", "myPackage.Grandpa",
|
|
2875 |
| testLLVisitor.getQualifiedClassName("Grandpa")); |
|
2876 |
| } |
|
2877 |
| |
|
2878 |
1
| public void testAddSymbolData() {
|
|
2879 |
| |
|
2880 |
1
| SymbolData obj = LanguageLevelConverter.symbolTable.get("java.lang.Object");
|
|
2881 |
| |
|
2882 |
| |
|
2883 |
| |
|
2884 |
1
| ClassDef cd =
|
|
2885 |
| new ClassDef(SourceInfo.NONE, PUBLIC_MAV, new Word(SourceInfo.NONE, "Awesome"), |
|
2886 |
| new TypeParameter[0], |
|
2887 |
| new ClassOrInterfaceType(SourceInfo.NONE, "java.lang.Object", new Type[0]), |
|
2888 |
| new ReferenceType[0], |
|
2889 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
2890 |
| |
|
2891 |
1
| SymbolData sd = new SymbolData("Awesome");
|
|
2892 |
1
| sd.setSuperClass(LanguageLevelConverter.symbolTable.get("java.lang.Object"));
|
|
2893 |
1
| LanguageLevelConverter.symbolTable.put("Awesome", sd);
|
|
2894 |
1
| SymbolData result = testLLVisitor.defineSymbolData(cd, "Awesome");
|
|
2895 |
1
| assertFalse("result should not be a continuation.", result.isContinuation());
|
|
2896 |
1
| assertFalse("sd should also no longer be a continuation.", sd.isContinuation());
|
|
2897 |
1
| assertEquals("result and sd should be equal.", sd, result);
|
|
2898 |
| |
|
2899 |
| |
|
2900 |
| |
|
2901 |
| |
|
2902 |
| |
|
2903 |
1
| assertEquals("Should return null, because it is already in the SymbolTable.", null,
|
|
2904 |
| testLLVisitor.defineSymbolData(cd, "Awesome")); |
|
2905 |
1
| assertEquals("Length of errors should now be 1.", 1, errors.size());
|
|
2906 |
1
| assertEquals("Error message should be correct.", "The class or interface Awesome has already been defined.",
|
|
2907 |
| errors.get(0).getFirst()); |
|
2908 |
| |
|
2909 |
| |
|
2910 |
| } |
|
2911 |
| |
|
2912 |
1
| public void test_variableDeclaration2VariableData() {
|
|
2913 |
1
| VariableDeclarator[] d1 = {
|
|
2914 |
| new UninitializedVariableDeclarator(SourceInfo.NONE, |
|
2915 |
| new PrimitiveType(SourceInfo.NONE, "int"), |
|
2916 |
| new Word(SourceInfo.NONE, "i")) }; |
|
2917 |
1
| VariableDeclaration vd1 = new VariableDeclaration(SourceInfo.NONE,PUBLIC_MAV, d1);
|
|
2918 |
1
| VariableData[] vdata1 = { new VariableData("i", PUBLIC_MAV, SymbolData.INT_TYPE, false, _sd1) };
|
|
2919 |
| |
|
2920 |
1
| assertTrue("Should properly recognize a basic VariableDeclaration",
|
|
2921 |
| arrayEquals(vdata1, testLLVisitor._variableDeclaration2VariableData(vd1, _sd1))); |
|
2922 |
| |
|
2923 |
1
| VariableDeclarator[] d2 = {
|
|
2924 |
| new UninitializedVariableDeclarator(SourceInfo.NONE, |
|
2925 |
| new PrimitiveType(SourceInfo.NONE, "int"), |
|
2926 |
| new Word(SourceInfo.NONE, "i")), |
|
2927 |
| new InitializedVariableDeclarator(SourceInfo.NONE, |
|
2928 |
| new PrimitiveType(SourceInfo.NONE, "boolean"), |
|
2929 |
| new Word(SourceInfo.NONE, "b"), |
|
2930 |
| new BooleanLiteral(SourceInfo.NONE, true)) }; |
|
2931 |
1
| VariableDeclaration vd2 = new VariableDeclaration(SourceInfo.NONE,PRIVATE_MAV, d2);
|
|
2932 |
1
| VariableData bData = new VariableData("b", PRIVATE_MAV, SymbolData.BOOLEAN_TYPE, true, _sd1);
|
|
2933 |
1
| bData.setHasInitializer(true);
|
|
2934 |
1
| VariableData[] vdata2 = {new VariableData("i", PRIVATE_MAV, SymbolData.INT_TYPE, false, _sd1),
|
|
2935 |
| bData}; |
|
2936 |
| |
|
2937 |
1
| assertTrue("Should properly recognize a more complicated VariableDeclaration",
|
|
2938 |
| arrayEquals(vdata2, testLLVisitor._variableDeclaration2VariableData(vd2, _sd1))); |
|
2939 |
| |
|
2940 |
| |
|
2941 |
1
| VariableDeclarator[] d3 = {
|
|
2942 |
| new UninitializedVariableDeclarator(SourceInfo.NONE, |
|
2943 |
| new ClassOrInterfaceType(SourceInfo.NONE, "LinkedList", new Type[0]), |
|
2944 |
| new Word(SourceInfo.NONE, "myList"))}; |
|
2945 |
1
| VariableDeclaration vd3 = new VariableDeclaration(SourceInfo.NONE, PRIVATE_MAV, d3);
|
|
2946 |
1
| testLLVisitor._variableDeclaration2VariableData(vd3, _sd1);
|
|
2947 |
1
| assertEquals("There should now be no errors", 0, errors.size());
|
|
2948 |
| |
|
2949 |
| |
|
2950 |
| |
|
2951 |
| } |
|
2952 |
| |
|
2953 |
1
| public void test_addError() {
|
|
2954 |
1
| LinkedList<Pair<String, JExpressionIF>> e = new LinkedList<Pair<String, JExpressionIF>>();
|
|
2955 |
| |
|
2956 |
1
| NullLiteral nl = new NullLiteral(SourceInfo.NONE);
|
|
2957 |
1
| NullLiteral nl2 = new NullLiteral(SourceInfo.NONE);
|
|
2958 |
| |
|
2959 |
1
| e.addLast(new Pair<String,JExpressionIF>("Boy, is this an error!", nl));
|
|
2960 |
1
| _addError("Boy, is this an error!", nl);
|
|
2961 |
| |
|
2962 |
1
| assertTrue("An error should have been added.", _errorAdded);
|
|
2963 |
1
| assertEquals("The errors list should be correct.", e, errors);
|
|
2964 |
| |
|
2965 |
1
| e.addLast(new Pair<String,JExpressionIF>("Error again!", nl2));
|
|
2966 |
1
| _addError("Error again!", nl2);
|
|
2967 |
| |
|
2968 |
1
| assertTrue("Another error should have been aded.", _errorAdded);
|
|
2969 |
1
| assertEquals("The new errors list should be correct.", e, errors);
|
|
2970 |
| } |
|
2971 |
| |
|
2972 |
1
| public void test_addAndIgnoreError() {
|
|
2973 |
1
| LinkedList<Pair<String, JExpressionIF>> e = new LinkedList<Pair<String, JExpressionIF>>();
|
|
2974 |
| |
|
2975 |
1
| NullLiteral nl = new NullLiteral(SourceInfo.NONE);
|
|
2976 |
1
| NullLiteral nl2 = new NullLiteral(SourceInfo.NONE);
|
|
2977 |
| |
|
2978 |
1
| _errorAdded = false;
|
|
2979 |
| |
|
2980 |
1
| e.addLast(new Pair<String,JExpressionIF>("Nobody pays attention to me!", nl));
|
|
2981 |
1
| _addAndIgnoreError("Nobody pays attention to me!", nl);
|
|
2982 |
| |
|
2983 |
1
| assertFalse("_errorAdded should be false.", _errorAdded);
|
|
2984 |
1
| assertEquals("The errors list should be correct.", e, errors);
|
|
2985 |
| |
|
2986 |
1
| e.addLast(new Pair<String,JExpressionIF>("Cellophane, I'm Mr. Cellophane", nl2));
|
|
2987 |
1
| _addAndIgnoreError("Cellophane, I'm Mr. Cellophane", nl2);
|
|
2988 |
| |
|
2989 |
1
| assertFalse("errorAdded should still be false.", _errorAdded);
|
|
2990 |
1
| assertEquals("The new errors list should be correct.", e, errors);
|
|
2991 |
| |
|
2992 |
1
| _errorAdded = true;
|
|
2993 |
1
| try {
|
|
2994 |
1
| _addAndIgnoreError("This should throw an exception, because _errorAdded is true.", nl);
|
|
2995 |
0
| assertTrue("An error should have been thrown!", false);
|
|
2996 |
| } |
|
2997 |
| catch (RuntimeException exc) { |
|
2998 |
1
| assertEquals("Make sure runtime exception message is correct.",
|
|
2999 |
| "Internal Program Error: _addAndIgnoreError called while _errorAdded was true." + |
|
3000 |
| " Please report this bug.", |
|
3001 |
| exc.getMessage()); |
|
3002 |
| } |
|
3003 |
1
| _errorAdded = false;
|
|
3004 |
| } |
|
3005 |
| |
|
3006 |
1
| public void test_checkError() {
|
|
3007 |
1
| _errorAdded = false;
|
|
3008 |
1
| assertFalse("_checkError should return false", _checkError());
|
|
3009 |
| |
|
3010 |
1
| _errorAdded = true;
|
|
3011 |
1
| assertTrue("_checkError should return true", _checkError());
|
|
3012 |
1
| assertFalse("_checkError should have set _errorAdded to false.", _errorAdded);
|
|
3013 |
| } |
|
3014 |
| |
|
3015 |
1
| public void testForClassDefDoFirst() {
|
|
3016 |
1
| ClassDef cd =
|
|
3017 |
| new ClassDef(SourceInfo.NONE, PUBLIC_MAV, |
|
3018 |
| new Word(SourceInfo.NONE, "Awesome"), |
|
3019 |
| new TypeParameter[0], |
|
3020 |
| new ClassOrInterfaceType(SourceInfo.NONE, "java.lang.Object", new Type[0]), |
|
3021 |
| new ReferenceType[0], |
|
3022 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3023 |
1
| testLLVisitor.forClassDefDoFirst(cd);
|
|
3024 |
1
| assertEquals("There should be no errors.", 0, errors.size());
|
|
3025 |
1
| testLLVisitor._importedFiles.addLast(new File("Awesome").getAbsolutePath());
|
|
3026 |
1
| testLLVisitor.forClassDefDoFirst(cd);
|
|
3027 |
1
| assertEquals("There should be one error.", 1, errors.size());
|
|
3028 |
1
| assertEquals("The error message should be correct.", "The class Awesome was already imported.",
|
|
3029 |
| errors.get(0).getFirst()); |
|
3030 |
| |
|
3031 |
1
| ClassDef cd2 = new ClassDef(SourceInfo.NONE, PRIVATE_MAV,
|
|
3032 |
| new Word(SourceInfo.NONE, "privateClass"), |
|
3033 |
| new TypeParameter[0], |
|
3034 |
| new ClassOrInterfaceType(SourceInfo.NONE, "java.lang.Object", new Type[0]), |
|
3035 |
| new ReferenceType[0], |
|
3036 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3037 |
1
| testLLVisitor.forClassDefDoFirst(cd2);
|
|
3038 |
1
| assertEquals("There should be 2 errors", 2, errors.size());
|
|
3039 |
1
| assertEquals("The 2nd error message should be correct", "Top level classes cannot be private",
|
|
3040 |
| errors.get(1).getFirst()); |
|
3041 |
| |
|
3042 |
| } |
|
3043 |
| |
|
3044 |
1
| public void testForInterfaceDefDoFirst() {
|
|
3045 |
1
| InterfaceDef id = new InterfaceDef(SourceInfo.NONE, PUBLIC_MAV,
|
|
3046 |
| new Word(SourceInfo.NONE, "Awesome"), |
|
3047 |
| new TypeParameter[0], new ReferenceType[0], |
|
3048 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3049 |
1
| testLLVisitor.forInterfaceDefDoFirst(id);
|
|
3050 |
1
| assertEquals("There should be no errors.", 0, errors.size());
|
|
3051 |
| |
|
3052 |
1
| InterfaceDef id2 = new InterfaceDef(SourceInfo.NONE, PRIVATE_MAV,
|
|
3053 |
| new Word(SourceInfo.NONE, "privateinterface"), |
|
3054 |
| new TypeParameter[0], new ReferenceType[0], |
|
3055 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3056 |
1
| testLLVisitor.forInterfaceDefDoFirst(id2);
|
|
3057 |
1
| assertEquals("There should be 1 errors", 1, errors.size());
|
|
3058 |
1
| assertEquals("The error message should be correct", "Top level interfaces cannot be private",
|
|
3059 |
| errors.get(0).getFirst()); |
|
3060 |
| |
|
3061 |
1
| InterfaceDef id3 = new InterfaceDef(SourceInfo.NONE, FINAL_MAV,
|
|
3062 |
| new Word(SourceInfo.NONE, "finalinterface"), |
|
3063 |
| new TypeParameter[0], new ReferenceType[0], |
|
3064 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3065 |
1
| testLLVisitor.forInterfaceDefDoFirst(id3);
|
|
3066 |
1
| assertEquals("There should be 2 errors", 2, errors.size());
|
|
3067 |
1
| assertEquals("The error message should be correct", "Interfaces cannot be final", errors.get(1).getFirst());
|
|
3068 |
| } |
|
3069 |
| |
|
3070 |
1
| public void testForInnerInterfaceDefDoFirst() {
|
|
3071 |
1
| InterfaceDef id = new InterfaceDef(SourceInfo.NONE, PUBLIC_MAV,
|
|
3072 |
| new Word(SourceInfo.NONE, "Awesome"), |
|
3073 |
| new TypeParameter[0], new ReferenceType[0], |
|
3074 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3075 |
1
| id.visit(testLLVisitor);
|
|
3076 |
1
| assertEquals("There should be no errors.", 0, errors.size());
|
|
3077 |
| |
|
3078 |
1
| InnerInterfaceDef id2 =
|
|
3079 |
| new InnerInterfaceDef(SourceInfo.NONE, FINAL_MAV, new Word(SourceInfo.NONE, "finalinterface"), |
|
3080 |
| new TypeParameter[0], new ReferenceType[0], |
|
3081 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3082 |
1
| id2.visit(testLLVisitor);
|
|
3083 |
1
| assertEquals("There should be 1 error", 1, errors.size());
|
|
3084 |
1
| assertEquals("The error message should be correct", "Interfaces cannot be final", errors.get(0).getFirst());
|
|
3085 |
| } |
|
3086 |
| |
|
3087 |
1
| public void testForPackageStatementOnly() {
|
|
3088 |
1
| Word[] words = new Word[] {new Word(SourceInfo.NONE, "alpha"),
|
|
3089 |
| new Word(SourceInfo.NONE, "beta")}; |
|
3090 |
1
| CompoundWord cw = new CompoundWord(SourceInfo.NONE, words);
|
|
3091 |
1
| PackageStatement ps = new PackageStatement(SourceInfo.NONE, cw);
|
|
3092 |
1
| testLLVisitor._file = new File("alpha/beta/delta");
|
|
3093 |
1
| testLLVisitor.forPackageStatementOnly(ps);
|
|
3094 |
1
| assertEquals("_package should be set correctly.", "alpha.beta", testLLVisitor._package);
|
|
3095 |
1
| assertEquals("There should be no errors.", 0, errors.size());
|
|
3096 |
1
| testLLVisitor._file = new File("alpha/beta/beta/delta");
|
|
3097 |
1
| testLLVisitor.forPackageStatementOnly(ps);
|
|
3098 |
1
| assertEquals("_package should be set correctly.", "alpha.beta", testLLVisitor._package);
|
|
3099 |
1
| assertEquals("There should be one error.", 1, errors.size());
|
|
3100 |
1
| assertEquals("The error message should be correct.", "The package name must mirror your file's directory.",
|
|
3101 |
| errors.get(0).getFirst()); |
|
3102 |
| } |
|
3103 |
| |
|
3104 |
1
| public void testForClassImportStatementOnly() {
|
|
3105 |
| |
|
3106 |
| |
|
3107 |
1
| Word[] words = new Word[] { new Word(SourceInfo.NONE, "alpha"), new Word(SourceInfo.NONE, "beta")};
|
|
3108 |
1
| CompoundWord cw = new CompoundWord(SourceInfo.NONE, words);
|
|
3109 |
1
| ClassImportStatement cis = new ClassImportStatement(SourceInfo.NONE, cw);
|
|
3110 |
1
| SymbolData sd = new SymbolData("alpha.beta");
|
|
3111 |
1
| testLLVisitor.forClassImportStatementOnly(cis);
|
|
3112 |
1
| assertTrue("imported files should contain alpha.beta", testLLVisitor._importedFiles.contains("alpha.beta"));
|
|
3113 |
| |
|
3114 |
| |
|
3115 |
1
| assertTrue("It should be in continuations.", testLLVisitor.continuations.containsKey("alpha.beta"));
|
|
3116 |
| |
|
3117 |
| |
|
3118 |
| |
|
3119 |
1
| Word[] words2 = new Word[] { new Word(SourceInfo.NONE, "gamma"), new Word(SourceInfo.NONE, "beta")};
|
|
3120 |
1
| CompoundWord cw2 = new CompoundWord(SourceInfo.NONE, words2);
|
|
3121 |
1
| ClassImportStatement cis2 = new ClassImportStatement(SourceInfo.NONE, cw2);
|
|
3122 |
1
| cis2.visit(testLLVisitor);
|
|
3123 |
| |
|
3124 |
1
| assertEquals("There should be one error", 1, errors.size());
|
|
3125 |
1
| assertEquals("The error message should be correct",
|
|
3126 |
| "The class beta has already been imported.", |
|
3127 |
| errors.get(0).getFirst()); |
|
3128 |
| |
|
3129 |
| |
|
3130 |
| |
|
3131 |
| |
|
3132 |
| |
|
3133 |
| |
|
3134 |
| |
|
3135 |
| |
|
3136 |
| |
|
3137 |
| |
|
3138 |
| |
|
3139 |
| |
|
3140 |
| |
|
3141 |
| } |
|
3142 |
| |
|
3143 |
1
| public void testForPackageImportStatementOnly() {
|
|
3144 |
| |
|
3145 |
1
| Word[] words = new Word[] {new Word(SourceInfo.NONE, "alpha"),
|
|
3146 |
| new Word(SourceInfo.NONE, "beta")}; |
|
3147 |
1
| CompoundWord cw = new CompoundWord(SourceInfo.NONE, words);
|
|
3148 |
1
| PackageImportStatement cis = new PackageImportStatement(SourceInfo.NONE, cw);
|
|
3149 |
1
| SymbolData sd = new SymbolData("alpha.beta");
|
|
3150 |
1
| testLLVisitor.forPackageImportStatementOnly(cis);
|
|
3151 |
1
| assertEquals("There should be no errorrs", 0, errors.size());
|
|
3152 |
1
| assertTrue("Imported Packages should now contain alpha.beta",
|
|
3153 |
| testLLVisitor._importedPackages.contains("alpha.beta")); |
|
3154 |
| |
|
3155 |
| |
|
3156 |
1
| testLLVisitor._package = "myPackage";
|
|
3157 |
1
| Word[] words3 = new Word[] {new Word(SourceInfo.NONE, "myPackage"), new Word(SourceInfo.NONE,
|
|
3158 |
| "cookie")}; |
|
3159 |
1
| CompoundWord cw3 = new CompoundWord(SourceInfo.NONE, words3);
|
|
3160 |
1
| PackageImportStatement pis = new PackageImportStatement(SourceInfo.NONE, cw3);
|
|
3161 |
1
| pis.visit(testLLVisitor);
|
|
3162 |
| |
|
3163 |
1
| assertEquals("There should be no errors", 0, errors.size());
|
|
3164 |
1
| assertTrue("Imported Packages should now contain myPackage.cookie",
|
|
3165 |
| testLLVisitor._importedPackages.contains("myPackage.cookie")); |
|
3166 |
| |
|
3167 |
| |
|
3168 |
| |
|
3169 |
| |
|
3170 |
1
| Word[] words2 = new Word[] {new Word(SourceInfo.NONE, "myPackage")};
|
|
3171 |
1
| CompoundWord cw2 = new CompoundWord(SourceInfo.NONE, words2);
|
|
3172 |
1
| PackageImportStatement pis2 = new PackageImportStatement(SourceInfo.NONE, cw2);
|
|
3173 |
1
| pis2.visit(testLLVisitor);
|
|
3174 |
| |
|
3175 |
1
| assertEquals("There should now be 1 errors", 1, errors.size());
|
|
3176 |
1
| assertEquals("The error message should be correct", "You do not need to import package myPackage." +
|
|
3177 |
| " It is your package so all public classes in it are already visible.", errors.get(0).getFirst()); |
|
3178 |
| |
|
3179 |
| } |
|
3180 |
| |
|
3181 |
1
| public void testForSourceFile() {
|
|
3182 |
1
| ClassDef cd = new ClassDef(SourceInfo.NONE, PUBLIC_MAV, new Word(SourceInfo.NONE, "Awesome"),
|
|
3183 |
| new TypeParameter[0], |
|
3184 |
| new ClassOrInterfaceType(SourceInfo.NONE, "java.lang.Object", new Type[0]), |
|
3185 |
| new ReferenceType[0], |
|
3186 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3187 |
1
| ClassDef cd2 = new ClassDef(SourceInfo.NONE, PUBLIC_MAV, new Word(SourceInfo.NONE, "Gnarly"),
|
|
3188 |
| new TypeParameter[0], |
|
3189 |
| new ClassOrInterfaceType(SourceInfo.NONE, "Awesome", new Type[0]), |
|
3190 |
| new ReferenceType[0], |
|
3191 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3192 |
1
| InterfaceDef id = new InterfaceDef(SourceInfo.NONE, PUBLIC_MAV,
|
|
3193 |
| new Word(SourceInfo.NONE, "NiftyWords"), |
|
3194 |
| new TypeParameter[0], |
|
3195 |
| new ReferenceType[0], |
|
3196 |
| new BracedBody(SourceInfo.NONE, new BodyItemI[0])); |
|
3197 |
| |
|
3198 |
1
| SourceFile sf = new SourceFile(SourceInfo.NONE,
|
|
3199 |
| new PackageStatement[0], |
|
3200 |
| new ImportStatement[0], |
|
3201 |
| new TypeDefBase[] {cd, cd2, id}); |
|
3202 |
1
| testLLVisitor.forSourceFile(sf);
|
|
3203 |
| |
|
3204 |
1
| assertTrue("_classesInThisFile should contain the two ClassDefs.",
|
|
3205 |
| testLLVisitor._classesInThisFile.contains("Awesome")); |
|
3206 |
1
| assertTrue("_classesInThisFile should contain the two ClassDefs.",
|
|
3207 |
| testLLVisitor._classesInThisFile.contains("Gnarly")); |
|
3208 |
| |
|
3209 |
1
| assertTrue("_classesInThisFile should contain the InterfaceDef",
|
|
3210 |
| testLLVisitor._classesInThisFile.contains("NiftyWords")); |
|
3211 |
1
| assertTrue("_classesInThisFile should contain the two ClassDefs.",
|
|
3212 |
| testLLVisitor._classesInThisFile.contains("Awesome")); |
|
3213 |
1
| assertTrue("_classesInThisFile should contain the two ClassDefs.",
|
|
3214 |
| testLLVisitor._classesInThisFile.contains("Gnarly")); |
|
3215 |
1
| assertTrue("_classesInThisFile should contain the InterfaceDef",
|
|
3216 |
| testLLVisitor._classesInThisFile.contains("NiftyWords")); |
|
3217 |
| |
|
3218 |
| } |
|
3219 |
| |
|
3220 |
1
| public void testReferenceType2String() {
|
|
3221 |
| |
|
3222 |
1
| TypeVariable tv = new TypeVariable(SourceInfo.NONE, "T");
|
|
3223 |
1
| String[] result = testLLVisitor.referenceType2String(new ReferenceType[] { tv });
|
|
3224 |
1
| assertEquals("There should not be any errors.", 0, errors.size());
|
|
3225 |
1
| assertEquals("Results should have one String.", 1, result.length);
|
|
3226 |
1
| assertEquals("The String should be \"T\".", "T", result[0]);
|
|
3227 |
| |
|
3228 |
| |
|
3229 |
1
| ClassOrInterfaceType coit = new ClassOrInterfaceType(SourceInfo.NONE,
|
|
3230 |
| "MyClass", |
|
3231 |
| new Type[] { new TypeVariable(SourceInfo.NONE, "T"), |
|
3232 |
| new TypeVariable(SourceInfo.NONE, "U")} |
|
3233 |
| ); |
|
3234 |
1
| result = testLLVisitor.referenceType2String(new ReferenceType[] { tv, coit });
|
|
3235 |
1
| assertEquals("There should not be any errors.", 0, errors.size());
|
|
3236 |
1
| assertEquals("Results should have two Strings.", 2, result.length);
|
|
3237 |
1
| assertEquals("The first String should be \"T\".", "T", result[0]);
|
|
3238 |
1
| assertEquals("The second String should be \"MyClass\".", "MyClass", result[1]);
|
|
3239 |
| |
|
3240 |
| |
|
3241 |
1
| MemberType mt = new MemberType(SourceInfo.NONE,
|
|
3242 |
| "MyClass.MyClass2", |
|
3243 |
| coit, |
|
3244 |
| new ClassOrInterfaceType(SourceInfo.NONE, |
|
3245 |
| "MyClass2", |
|
3246 |
| new Type[0])); |
|
3247 |
1
| result = testLLVisitor.referenceType2String(new ReferenceType[] { mt });
|
|
3248 |
1
| assertEquals("There should not be any errors.", 0, errors.size());
|
|
3249 |
1
| assertEquals("Results should have one String.", 1, result.length);
|
|
3250 |
1
| assertEquals("The first String should be \"MyClass.MyClass2\".", "MyClass.MyClass2", result[0]);
|
|
3251 |
| } |
|
3252 |
| |
|
3253 |
| |
|
3254 |
1
| public void testExceptionsInSymbolTable() {
|
|
3255 |
| |
|
3256 |
| |
|
3257 |
1
| ClassOrInterfaceType exceptionType =
|
|
3258 |
| new ClassOrInterfaceType(SourceInfo.NONE, "java.util.prefs.BackingStoreException", new Type[0]); |
|
3259 |
1
| ParenthesizedExpressionList expList = new ParenthesizedExpressionList(SourceInfo.NONE, new Expression[0]);
|
|
3260 |
| |
|
3261 |
1
| BracedBody bb =
|
|
3262 |
| new BracedBody(SourceInfo.NONE, |
|
3263 |
| new BodyItemI[] { new ThrowStatement(SourceInfo.NONE, |
|
3264 |
| new SimpleNamedClassInstantiation(SourceInfo.NONE, |
|
3265 |
| exceptionType, |
|
3266 |
| expList))}); |
|
3267 |
1
| bb.visit(testLLVisitor);
|
|
3268 |
1
| assertNotNull("The SymbolTable should have java.util.prefs.BackingStoreException",
|
|
3269 |
| LanguageLevelConverter.symbolTable.get("java.util.prefs.BackingStoreException")); |
|
3270 |
| |
|
3271 |
| } |
|
3272 |
| |
|
3273 |
1
| public void testShouldBreak() {
|
|
3274 |
| |
|
3275 |
1
| LeftShiftAssignmentExpression shift1 =
|
|
3276 |
| new LeftShiftAssignmentExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3277 |
| new NullLiteral(SourceInfo.NONE)); |
|
3278 |
1
| RightUnsignedShiftAssignmentExpression shift2 =
|
|
3279 |
| new RightUnsignedShiftAssignmentExpression(SourceInfo.NONE, |
|
3280 |
| new NullLiteral(SourceInfo.NONE), |
|
3281 |
| new NullLiteral(SourceInfo.NONE)); |
|
3282 |
1
| RightSignedShiftAssignmentExpression shift3 =
|
|
3283 |
| new RightSignedShiftAssignmentExpression(SourceInfo.NONE, |
|
3284 |
| new NullLiteral(SourceInfo.NONE), |
|
3285 |
| new NullLiteral(SourceInfo.NONE)); |
|
3286 |
| |
|
3287 |
| |
|
3288 |
1
| shift1.visit(testLLVisitor);
|
|
3289 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3290 |
| |
|
3291 |
| |
|
3292 |
| |
|
3293 |
| |
|
3294 |
1
| shift2.visit(testLLVisitor);
|
|
3295 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3296 |
| |
|
3297 |
| |
|
3298 |
| |
|
3299 |
| |
|
3300 |
1
| shift3.visit(testLLVisitor);
|
|
3301 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3302 |
| |
|
3303 |
| |
|
3304 |
| |
|
3305 |
| |
|
3306 |
| |
|
3307 |
1
| BitwiseAndAssignmentExpression bit1 =
|
|
3308 |
| new BitwiseAndAssignmentExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3309 |
| new NullLiteral(SourceInfo.NONE)); |
|
3310 |
1
| BitwiseOrAssignmentExpression bit2 =
|
|
3311 |
| new BitwiseOrAssignmentExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3312 |
| new NullLiteral(SourceInfo.NONE)); |
|
3313 |
1
| BitwiseXorAssignmentExpression bit3 =
|
|
3314 |
| new BitwiseXorAssignmentExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3315 |
| new NullLiteral(SourceInfo.NONE)); |
|
3316 |
| |
|
3317 |
1
| bit1.visit(testLLVisitor);
|
|
3318 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3319 |
| |
|
3320 |
| |
|
3321 |
| |
|
3322 |
1
| bit2.visit(testLLVisitor);
|
|
3323 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3324 |
| |
|
3325 |
| |
|
3326 |
| |
|
3327 |
1
| bit3.visit(testLLVisitor);
|
|
3328 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3329 |
| |
|
3330 |
| |
|
3331 |
| |
|
3332 |
| |
|
3333 |
1
| BitwiseAndExpression bit4 =
|
|
3334 |
| new BitwiseAndExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3335 |
| new NullLiteral(SourceInfo.NONE)); |
|
3336 |
1
| BitwiseOrExpression bit5 =
|
|
3337 |
| new BitwiseOrExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3338 |
| new NullLiteral(SourceInfo.NONE)); |
|
3339 |
1
| BitwiseXorExpression bit6 =
|
|
3340 |
| new BitwiseXorExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3341 |
| new NullLiteral(SourceInfo.NONE)); |
|
3342 |
1
| BitwiseNotExpression bit7 =
|
|
3343 |
| new BitwiseNotExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE)); |
|
3344 |
| |
|
3345 |
| |
|
3346 |
1
| bit4.visit(testLLVisitor);
|
|
3347 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3348 |
| |
|
3349 |
| |
|
3350 |
| |
|
3351 |
| |
|
3352 |
| |
|
3353 |
1
| bit5.visit(testLLVisitor);
|
|
3354 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3355 |
| |
|
3356 |
| |
|
3357 |
| |
|
3358 |
| |
|
3359 |
| |
|
3360 |
1
| bit6.visit(testLLVisitor);
|
|
3361 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3362 |
| |
|
3363 |
| |
|
3364 |
| |
|
3365 |
1
| bit7.visit(testLLVisitor);
|
|
3366 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3367 |
| |
|
3368 |
| |
|
3369 |
| |
|
3370 |
| |
|
3371 |
| |
|
3372 |
| |
|
3373 |
1
| LeftShiftExpression shift4 =
|
|
3374 |
| new LeftShiftExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3375 |
| new NullLiteral(SourceInfo.NONE)); |
|
3376 |
1
| RightUnsignedShiftExpression shift5 =
|
|
3377 |
| new RightUnsignedShiftExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3378 |
| new NullLiteral(SourceInfo.NONE)); |
|
3379 |
1
| RightSignedShiftExpression shift6 =
|
|
3380 |
| new RightSignedShiftExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3381 |
| new NullLiteral(SourceInfo.NONE)); |
|
3382 |
| |
|
3383 |
1
| shift4.visit(testLLVisitor);
|
|
3384 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3385 |
| |
|
3386 |
| |
|
3387 |
| |
|
3388 |
1
| shift5.visit(testLLVisitor);
|
|
3389 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3390 |
| |
|
3391 |
| |
|
3392 |
| |
|
3393 |
1
| shift6.visit(testLLVisitor);
|
|
3394 |
1
| assertEquals("Should be no errors", 0, errors.size());
|
|
3395 |
| |
|
3396 |
| |
|
3397 |
| |
|
3398 |
| |
|
3399 |
1
| EmptyExpression e = new EmptyExpression(SourceInfo.NONE);
|
|
3400 |
1
| e.visit(testLLVisitor);
|
|
3401 |
1
| assertEquals("Should be 1 error", 1, errors.size());
|
|
3402 |
1
| assertEquals("Error message should be correct", "You appear to be missing an expression here",
|
|
3403 |
| errors.getLast().getFirst()); |
|
3404 |
| |
|
3405 |
| |
|
3406 |
1
| NoOpExpression noop =
|
|
3407 |
| new NoOpExpression(SourceInfo.NONE, new NullLiteral(SourceInfo.NONE), |
|
3408 |
| new NullLiteral(SourceInfo.NONE)); |
|
3409 |
1
| noop.visit(testLLVisitor);
|
|
3410 |
1
| assertEquals("Should be 2 errors", 2, errors.size());
|
|
3411 |
1
| assertEquals("Error message should be correct", "You are missing a binary operator here",
|
|
3412 |
| errors.getLast().getFirst()); |
|
3413 |
| } |
|
3414 |
| |
|
3415 |
1
| public void testIsConstructor() {
|
|
3416 |
1
| MethodData constr =
|
|
3417 |
| new MethodData("monkey", PUBLIC_MAV, new TypeParameter[0], _sd1, new VariableData[0], new String[0], _sd1, |
|
3418 |
| new NullLiteral(SourceInfo.NONE)); |
|
3419 |
1
| MethodData notRightOuter =
|
|
3420 |
| new MethodData("monkey", PUBLIC_MAV, new TypeParameter[0], _sd1, new VariableData[0], new String[0], _sd2, |
|
3421 |
| new NullLiteral(SourceInfo.NONE)); |
|
3422 |
1
| _sd2.setOuterData(_sd1);
|
|
3423 |
1
| _sd1.addInnerClass(_sd2);
|
|
3424 |
1
| MethodData notRightName =
|
|
3425 |
| new MethodData("chimp", PUBLIC_MAV, new TypeParameter[0], _sd1, new VariableData[0], new String[0], _sd1, |
|
3426 |
| new NullLiteral(SourceInfo.NONE)); |
|
3427 |
1
| MethodData notRightReturnType =
|
|
3428 |
| new MethodData("monkey", PUBLIC_MAV, new TypeParameter[0], _sd2, new VariableData[0], new String[0], _sd1, |
|
3429 |
| new NullLiteral(SourceInfo.NONE)); |
|
3430 |
| |
|
3431 |
| |
|
3432 |
1
| assertTrue(testLLVisitor.isConstructor(constr));
|
|
3433 |
| |
|
3434 |
| |
|
3435 |
1
| assertFalse(testLLVisitor.isConstructor(notRightOuter));
|
|
3436 |
| |
|
3437 |
| |
|
3438 |
1
| assertFalse(testLLVisitor.isConstructor(notRightName));
|
|
3439 |
| |
|
3440 |
| |
|
3441 |
1
| assertFalse(testLLVisitor.isConstructor(notRightReturnType));
|
|
3442 |
| |
|
3443 |
| |
|
3444 |
1
| assertFalse(testLLVisitor.isConstructor(_sd1));
|
|
3445 |
| } |
|
3446 |
| } |
|
3447 |
| } |