1 /*******************************************************************************
2 * Copyright (c) 2000, 2017 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.jdt.core.tests.dom;
15
16 import java.io.IOException;
17 import java.util.List;
18 import java.util.Map;
19
20 import junit.framework.Test;
21
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.jdt.core.IClassFile;
24 import org.eclipse.jdt.core.ICompilationUnit;
25 import org.eclipse.jdt.core.IJavaElement;
26 import org.eclipse.jdt.core.IJavaProject;
27 import org.eclipse.jdt.core.IMethod;
28 import org.eclipse.jdt.core.IType;
29 import org.eclipse.jdt.core.JavaModelException;
30 import org.eclipse.jdt.core.WorkingCopyOwner;
31 import org.eclipse.jdt.core.dom.*;
32
33 @SuppressWarnings("rawtypes")
34 public class ASTConverterBugsTest extends ConverterTestSetup {
35
36 @Override
setUpSuite()37 public void setUpSuite() throws Exception {
38 // PROJECT_SETUP = true; // do not copy Converter* directories
39 super.setUpSuite();
40 // setUpJCLClasspathVariables("1.5");
41 waitUntilIndexesReady();
42 }
43
ASTConverterBugsTest(String name)44 public ASTConverterBugsTest(String name) {
45 super(name);
46 }
47
suite()48 public static Test suite() {
49 return buildModelTestSuite(ASTConverterBugsTest.class);
50 }
51
checkParameterAnnotations(String message, String expected, IMethodBinding methodBinding)52 protected void checkParameterAnnotations(String message, String expected, IMethodBinding methodBinding) {
53 ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
54 int size = parameterTypes == null ? 0 : parameterTypes.length;
55 StringBuffer buffer = new StringBuffer();
56 for (int i=0; i<size; i++) {
57 buffer.append("----- param ");
58 buffer.append(i+1);
59 buffer.append("-----\n");
60 IAnnotationBinding[] bindings= methodBinding.getParameterAnnotations(i);
61 int length = bindings.length;
62 for (int j=0; j<length; j++) {
63 buffer.append(bindings[j].getKey());
64 buffer.append('\n');
65 }
66 }
67 assertEquals(message, expected, buffer.toString());
68 }
69
70 @Override
runConversion(ICompilationUnit unit, boolean resolveBindings)71 public ASTNode runConversion(ICompilationUnit unit, boolean resolveBindings) {
72 return runConversion(this.testLevel, unit, resolveBindings);
73 }
74
75 @Override
runConversion(ICompilationUnit unit, int position, boolean resolveBindings)76 public ASTNode runConversion(ICompilationUnit unit, int position, boolean resolveBindings) {
77 return runConversion(this.testLevel, unit, position, resolveBindings);
78 }
79
80 @Override
runConversion(IClassFile classFile, int position, boolean resolveBindings)81 public ASTNode runConversion(IClassFile classFile, int position, boolean resolveBindings) {
82 return runConversion(this.testLevel, classFile, position, resolveBindings);
83 }
84
85 @Override
runConversion(char[] source, String unitName, IJavaProject project)86 public ASTNode runConversion(char[] source, String unitName, IJavaProject project) {
87 return runConversion(this.testLevel, source, unitName, project);
88 }
89
90 @Override
runConversion(char[] source, String unitName, IJavaProject project, boolean resolveBindings)91 public ASTNode runConversion(char[] source, String unitName, IJavaProject project, boolean resolveBindings) {
92 return runConversion(this.testLevel, source, unitName, project, resolveBindings);
93 }
94
95 @Override
runConversion(char[] source, String unitName, IJavaProject project, Map<String, String> options, boolean resolveBindings)96 public ASTNode runConversion(char[] source, String unitName, IJavaProject project, Map<String, String> options, boolean resolveBindings) {
97 return runConversion(this.testLevel, source, unitName, project, options, resolveBindings);
98 }
99 @Override
runConversion(char[] source, String unitName, IJavaProject project, Map<String, String> options)100 public ASTNode runConversion(char[] source, String unitName, IJavaProject project, Map<String, String> options) {
101 return runConversion(this.testLevel, source, unitName, project, options);
102 }
103
runConversion( ICompilationUnit unit, boolean resolveBindings, boolean statementsRecovery, boolean bindingsRecovery)104 public ASTNode runConversion(
105 ICompilationUnit unit,
106 boolean resolveBindings,
107 boolean statementsRecovery,
108 boolean bindingsRecovery) {
109 ASTParser parser = createASTParser();
110 parser.setSource(unit);
111 parser.setResolveBindings(resolveBindings);
112 parser.setStatementsRecovery(statementsRecovery);
113 parser.setBindingsRecovery(bindingsRecovery);
114 parser.setWorkingCopyOwner(this.wcOwner);
115 return parser.createAST(null);
116 }
117
118 @Override
resolveASTs(ICompilationUnit[] cus, String[] bindingKeys, ASTRequestor requestor, IJavaProject project, WorkingCopyOwner owner)119 protected void resolveASTs(ICompilationUnit[] cus, String[] bindingKeys, ASTRequestor requestor, IJavaProject project, WorkingCopyOwner owner) {
120 ASTParser parser = createASTParser();
121 parser.setResolveBindings(true);
122 parser.setProject(project);
123 parser.setWorkingCopyOwner(owner);
124 parser.createASTs(cus, bindingKeys, requestor, null);
125 }
126
127 /**
128 * @bug 186410: [dom] StackOverflowError due to endless superclass bindings hierarchy
129 * @test Ensures that the superclass of "java.lang.Object" class is null even when it's a recovered binding
130 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=186410"
131 */
testBug186410()132 public void testBug186410() throws CoreException, IOException {
133 try {
134 createJavaProject("P", new String[] { "" }, new String[0], "");
135 createFile("P/A.java",
136 "public class A {\n" +
137 " void method(){}\n" +
138 "}"
139 );
140 ICompilationUnit cuA = getCompilationUnit("P/A.java");
141 CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
142 AbstractTypeDeclaration typeA = (AbstractTypeDeclaration) unitA.types().get(0);
143 ITypeBinding objectType = typeA.resolveBinding().getSuperclass();
144 assertEquals("Unexpected superclass", "Object", objectType.getName());
145 ITypeBinding objectSuperclass = objectType.getSuperclass();
146 assertNull("java.lang.Object should not have any superclass", objectSuperclass);
147 } finally {
148 deleteProject("P");
149 }
150 }
151
testBug186410b()152 public void testBug186410b() throws CoreException, IOException {
153 try {
154 createJavaProject("P", new String[] { "" }, new String[0], "");
155 createFile("P/A.java",
156 "public class A {\n" +
157 " Object field;\n" +
158 "}"
159 );
160 ICompilationUnit cuA = getCompilationUnit("P/A.java");
161 CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
162 AbstractTypeDeclaration type = (AbstractTypeDeclaration) unitA.types().get(0);
163 FieldDeclaration field = (FieldDeclaration) type.bodyDeclarations().get(0);
164 Type fieldType = field.getType();
165 ITypeBinding typeBinding = fieldType.resolveBinding();
166 ITypeBinding objectType = typeBinding.createArrayType(2).getElementType();
167 assertEquals("Unexpected superclass", "Object", objectType.getName());
168 ITypeBinding objectSuperclass = objectType.getSuperclass();
169 assertNull("java.lang.Object should not have any superclass", objectSuperclass);
170 } finally {
171 deleteProject("P");
172 }
173 }
174
175 /**
176 * @bug 209150: [dom] Recovered type binding for "java.lang.Object" information are not complete
177 * @test Ensures that getPackage() and getQualifiedName() works properly for the "java.lang.Object" recovered binding
178 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=209150"
179 */
testBug209150a()180 public void testBug209150a() throws CoreException, IOException {
181 try {
182 createJavaProject("P", new String[] { "" }, new String[0], "");
183 createFile("P/A.java",
184 "public class A {\n" +
185 " void method(){}\n" +
186 "}"
187 );
188 ICompilationUnit cuA = getCompilationUnit("P/A.java");
189 CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
190 AbstractTypeDeclaration typeA = (AbstractTypeDeclaration) unitA.types().get(0);
191 ITypeBinding objectType = typeA.resolveBinding().getSuperclass();
192 assertTrue("'java.lang.Object' should be recovered!", objectType.isRecovered());
193 assertEquals("Unexpected package for recovered 'java.lang.Object'", "java.lang", objectType.getPackage().getName());
194 assertEquals("Unexpected qualified name for recovered 'java.lang.Object'",
195 "java.lang.Object",
196 objectType.getQualifiedName());
197 } finally {
198 deleteProject("P");
199 }
200 }
201
testBug209150b()202 public void testBug209150b() throws CoreException, IOException {
203 try {
204 createJavaProject("P", new String[] { "" }, new String[0], "");
205 createFile("P/A.java",
206 "public class A {\n" +
207 " Object field;\n" +
208 "}"
209 );
210 ICompilationUnit cuA = getCompilationUnit("P/A.java");
211 CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
212 AbstractTypeDeclaration type = (AbstractTypeDeclaration) unitA.types().get(0);
213 FieldDeclaration field = (FieldDeclaration) type.bodyDeclarations().get(0);
214 Type fieldType = field.getType();
215 ITypeBinding typeBinding = fieldType.resolveBinding();
216 ITypeBinding arrayType = typeBinding.createArrayType(2);
217 assertTrue("'java.lang.Object' should be recovered!", arrayType.isRecovered());
218 assertNull("Unexpected package for recovered 'array of java.lang.Object'", arrayType.getPackage());
219 assertEquals("Unexpected qualified name for recovered 'java.lang.Object'",
220 "java.lang.Object[][]",
221 arrayType.getQualifiedName());
222 } finally {
223 deleteProject("P");
224 }
225 }
226
testBug209150c()227 public void testBug209150c() throws CoreException, IOException {
228 try {
229 createJavaProject("P", new String[] { "" }, new String[0], "");
230 createFile("P/A.java",
231 "public class A {\n" +
232 " Object[] array;\n" +
233 "}"
234 );
235 ICompilationUnit cuA = getCompilationUnit("P/A.java");
236 CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
237 AbstractTypeDeclaration type = (AbstractTypeDeclaration) unitA.types().get(0);
238 FieldDeclaration field = (FieldDeclaration) type.bodyDeclarations().get(0);
239 Type fieldType = field.getType();
240 ITypeBinding arrayType = fieldType.resolveBinding();
241 assertTrue("'java.lang.Object' should be recovered!", arrayType.isRecovered());
242 assertNull("Unexpected package for recovered 'array of java.lang.Object'", arrayType.getPackage());
243 assertEquals("Unexpected qualified name for recovered 'java.lang.Object'",
244 "java.lang.Object[]",
245 arrayType.getQualifiedName());
246 } finally {
247 deleteProject("P");
248 }
249 }
250
251 /**
252 * @bug 212100: [dom] Can't create binding to inner class
253 * @test Verify that the binding is well created for an inner class
254 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=212100"
255 */
testBug212100a()256 public void testBug212100a() throws JavaModelException {
257 this.workingCopies = new ICompilationUnit[1];
258 this.workingCopies[0] = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
259 String contents =
260 "public class X {\n" +
261 " public class Y {\n" +
262 " void foo() {}\n" +
263 " }\n" +
264 "}";
265 this.workingCopies[0].getBuffer().setContents(contents);
266 this.workingCopies[0].save(null, true);
267 final IBinding[] bindings = new IBinding[4];
268 final String key = "Ljava/lang/Object;"; // this will make the test fail
269 // final String key = "LX;"; // this would make the test pass
270
271 resolveASTs(this.workingCopies,
272 new String[] { key },
273 new ASTRequestor() {
274 public void acceptBinding(String bindingKey, IBinding binding) {
275 if (key.equals(bindingKey)) {
276 bindings[0] = binding;
277 IBinding[] temp = createBindings(new String[] {"LX;", "LX$Y;", "[LX$Y;"});
278 for (int i = 0; i < temp.length; ++i) {
279 bindings[i + 1] = temp[i];
280 }
281 }
282 }
283 },
284 getJavaProject("Converter15"),
285 null);
286 assertNotNull("Binding for java.lang.Object should not be null", bindings[0]);
287 assertNotNull("Binding for X should not be null", bindings[1]);
288 assertNotNull("Binding for X.Y should not be null", bindings[2]);
289 assertNotNull("Binding for X.Y[] should not be null", bindings[3]);
290 }
testBug212100b()291 public void testBug212100b() throws JavaModelException {
292 this.workingCopies = new ICompilationUnit[2];
293 this.workingCopies[0] = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
294 String contents =
295 "public class X {\n" +
296 " public class Y {\n" +
297 " void foo() {}\n" +
298 " }\n" +
299 "}";
300 this.workingCopies[0].getBuffer().setContents(contents);
301 this.workingCopies[0].save(null, true);
302
303 this.workingCopies[1] = getWorkingCopy("/Converter15/src/Z.java", true/*resolve*/);
304 String contentsZ =
305 "public class Z {\n" +
306 " public class W {\n" +
307 " void bar() {}\n" +
308 " }\n" +
309 "}";
310 this.workingCopies[1].getBuffer().setContents(contentsZ);
311 this.workingCopies[1].save(null, true);
312
313 final String keyX = "LX;";
314 final String keyXY = "LX$Y;";
315 final String keyZ = "LZ;";
316 final String keyZW = "LZ$W;";
317
318 resolveASTs(this.workingCopies,
319 new String[] { keyX, keyZ },
320 new ASTRequestor() {
321 public void acceptBinding(String bindingKey, IBinding binding) {
322 IBinding[] bindings = createBindings(new String[] {
323 keyX, keyXY, keyZ, keyZW
324 });
325 assertNotNull("When accepting " + bindingKey + ", Binding for X should not be null", bindings[0]);
326 assertNotNull("When accepting " + bindingKey + ", Binding for X.Y should not be null", bindings[1]);
327 assertNotNull("When accepting " + bindingKey + ", Binding for Z should not be null", bindings[2]);
328 assertNotNull("When accepting " + bindingKey + ", Binding for Z.W should not be null", bindings[3]);
329 }
330 },
331 getJavaProject("Converter15"),
332 null);
333 }
334
335 /**
336 * @bug 212834: [dom] IMethodBinding.getParameterAnnotations does not return annotations
337 * @test Ensures that the method binding get the parameter annotations even on method invocation
338 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=212834"
339 */
testBug212834()340 public void testBug212834() throws CoreException, IOException {
341 this.workingCopies = new ICompilationUnit[3];
342 this.workingCopies[0] = getWorkingCopy("/Converter15/src/Baz.java",
343 "public @interface Baz {\n" +
344 "}\n"
345 );
346 this.workingCopies[1] = getWorkingCopy("/Converter15/src/C.java",
347 "public class C {\n" +
348 "public C(D d) {\n" +
349 " foo(5);\n" +
350 " d.bar(7);\n" +
351 "}\n" +
352 "@Baz\n" +
353 "public void foo(@Baz int x) { }\n" +
354 "\n" +
355 "}"
356 );
357 this.workingCopies[2] = getWorkingCopy("/Converter15/src/D.java",
358 "public class D {\n" +
359 "@Baz\n" +
360 "public void bar(@Baz int y) { }\n" +
361 "\n" +
362 "}"
363 );
364
365 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[1], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
366 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
367 MethodInvocation methodInvocation = (MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(1)).getExpression();
368 IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
369 assertBindingsEqual(methodInvocation+" has invalid parameter annotations!",
370 "@LBaz;",
371 methodBinding.getParameterAnnotations(0)
372 );
373 }
374
375 /**
376 * @bug 212857: [dom] AST has wrong source range after parameter with array-valued annotation
377 * @test Ensures that the method body has the right source range even when there's braces in its header
378 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=212857"
379 */
testBug212857()380 public void testBug212857() throws CoreException, IOException {
381 this.workingCopies = new ICompilationUnit[1];
382 String source = "package xy;\n" +
383 "public class C {\n" +
384 " void m(@SuppressWarnings({\"unused\", \"bla\"}) int arg) {\n" +
385 " int local;\n" +
386 " }\n" +
387 "}\n";
388 this.workingCopies[0] = getWorkingCopy("/Converter15/src/xy/C.java", source);
389 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
390 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
391 checkSourceRange(methodDeclaration.getBody(),
392 "{\n" +
393 " int local;\n" +
394 " }",
395 source
396 );
397 }
testBug212857a()398 public void testBug212857a() throws CoreException, IOException {
399 this.workingCopies = new ICompilationUnit[1];
400 String source = "package xy;\n" +
401 "public class C {\n" +
402 " @SuppressWarnings({\"unused\", \"bla\"}) void m() {\n" +
403 " int local;\n" +
404 " }\n" +
405 "}\n";
406 this.workingCopies[0] = getWorkingCopy("/Converter15/src/xy/C.java", source);
407 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
408 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
409 checkSourceRange(methodDeclaration.getBody(),
410 "{\n" +
411 " int local;\n" +
412 " }",
413 source
414 );
415 }
416 // tests with recovery
testBug212857b()417 public void testBug212857b() throws CoreException, IOException {
418 this.workingCopies = new ICompilationUnit[1];
419 String source = "package test;\n" +
420 "public class X {\n" +
421 " void m() \n" +
422 " if (arg == 0) {}\n" +
423 " }\n" +
424 "}\n";
425 this.workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
426 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
427 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
428 checkSourceRange(methodDeclaration.getBody(),
429 " \n" +
430 " if (arg == 0) {}\n" +
431 " }",
432 source
433 );
434 }
testBug212857c()435 public void testBug212857c() throws CoreException, IOException {
436 this.workingCopies = new ICompilationUnit[1];
437 String source = "package test;\n" +
438 "public class X {\n" +
439 " void m() \n" +
440 " }\n" +
441 "}\n";
442 this.workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
443 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
444 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
445 checkSourceRange(methodDeclaration.getBody(),
446 " \n" +
447 " }",
448 source
449 );
450 }
testBug212857d()451 public void testBug212857d() throws CoreException, IOException {
452 this.workingCopies = new ICompilationUnit[1];
453 String source = "package test;\n" +
454 "public class X {\n" +
455 " void m(String str) \n" +
456 " if (arg == 0) {}\n" +
457 " }\n" +
458 "}\n";
459 this.workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
460 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
461 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
462 checkSourceRange(methodDeclaration.getBody(),
463 " \n" +
464 " if (arg == 0) {}\n" +
465 " }",
466 source
467 );
468 }
testBug212857e()469 public void testBug212857e() throws CoreException, IOException {
470 this.workingCopies = new ICompilationUnit[1];
471 String source = "package test;\n" +
472 "public class X {\n" +
473 " void m(Object obj, int x) \n" +
474 " }\n" +
475 "}\n";
476 this.workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
477 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
478 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
479 checkSourceRange(methodDeclaration.getBody(),
480 " \n" +
481 " }",
482 source
483 );
484 }
485
486 /**
487 * @bug 213509: [dom] IMethodBinding.getParameterAnnotations returns annotations for wrong parameter
488 * @test Ensures that all parameter annotations of a the method binding are correctly returned
489 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=213509"
490 */
testBug213509()491 public void testBug213509() throws CoreException, IOException {
492 this.workingCopies = new ICompilationUnit[1];
493 this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
494 "public class Test {\n" +
495 " void m(@Foo @Bar @Annot String str, @Bar @Foo Object obj, @Annot int x) {}\n" +
496 "}\n" +
497 "@interface Foo {}\n" +
498 "@interface Bar {}\n" +
499 "@interface Annot {}\n"
500 );
501
502 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
503 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
504 checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
505 "----- param 1-----\n" +
506 "@LTest~Foo;\n" +
507 "@LTest~Bar;\n" +
508 "@LTest~Annot;\n" +
509 "----- param 2-----\n" +
510 "@LTest~Bar;\n" +
511 "@LTest~Foo;\n" +
512 "----- param 3-----\n" +
513 "@LTest~Annot;\n",
514 methodDeclaration.resolveBinding()
515 );
516 }
testBug213509_invocation()517 public void testBug213509_invocation() throws CoreException, IOException {
518 this.workingCopies = new ICompilationUnit[2];
519 this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
520 "public class Test {\n" +
521 " void m(@Foo @Bar @Annot String str, @Bar @Foo Object obj, @Annot int x) {}\n" +
522 "}\n" +
523 "@interface Foo {}\n" +
524 "@interface Bar {}\n" +
525 "@interface Annot {}\n"
526 );
527 this.workingCopies[1] = getWorkingCopy("/Converter15/src/X.java",
528 "public class X {\n" +
529 "public X(Test test) {\n" +
530 " test.m(\"\", null, 7);\n" +
531 "}\n" +
532 "}"
533 );
534
535 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[1], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
536 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
537 MethodInvocation methodInvocation = (MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(0)).getExpression();
538 checkParameterAnnotations(methodInvocation+" has invalid parameter annotations!",
539 "----- param 1-----\n" +
540 "@LTest~Foo;\n" +
541 "@LTest~Bar;\n" +
542 "@LTest~Annot;\n" +
543 "----- param 2-----\n" +
544 "@LTest~Bar;\n" +
545 "@LTest~Foo;\n" +
546 "----- param 3-----\n" +
547 "@LTest~Annot;\n",
548 methodInvocation.resolveMethodBinding()
549 );
550 }
551
552 /**
553 * @bug 214002: [dom] NPE in MethodBinding.getParameterAnnotations()
554 * @test Ensures that no NPE occurs when not all method parameters have annotations
555 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=214002"
556 */
testBug214002()557 public void testBug214002() throws CoreException, IOException {
558 this.workingCopies = new ICompilationUnit[1];
559 this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
560 "public class Test {\n" +
561 " void m(String str, @Bar @Foo Object obj, @Annot int x) {}\n" +
562 "}\n" +
563 "@interface Foo {}\n" +
564 "@interface Bar {}\n" +
565 "@interface Annot {}\n"
566 );
567
568 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
569 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
570 checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
571 "----- param 1-----\n" +
572 "----- param 2-----\n" +
573 "@LTest~Bar;\n" +
574 "@LTest~Foo;\n" +
575 "----- param 3-----\n" +
576 "@LTest~Annot;\n",
577 methodDeclaration.resolveBinding()
578 );
579 }
testBug214002b()580 public void testBug214002b() throws CoreException, IOException {
581 this.workingCopies = new ICompilationUnit[1];
582 this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
583 "public class Test {\n" +
584 " void m(@Annot String str, Object obj, @Bar @Foo int x) {}\n" +
585 "}\n" +
586 "@interface Foo {}\n" +
587 "@interface Bar {}\n" +
588 "@interface Annot {}\n"
589 );
590
591 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
592 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
593 checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
594 "----- param 1-----\n" +
595 "@LTest~Annot;\n" +
596 "----- param 2-----\n" +
597 "----- param 3-----\n" +
598 "@LTest~Bar;\n" +
599 "@LTest~Foo;\n",
600 methodDeclaration.resolveBinding()
601 );
602 }
603 /**
604 * @bug 212434: [dom] IllegalArgumentException during AST Creation
605 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=212434"
606 */
testBug212434a()607 public void testBug212434a() throws CoreException, IOException {
608 try {
609 createJavaProject("P", new String[] {""}, new String[0], "");
610 createFile("P/A.java",
611 "public class A {\n"+
612 "\n"+
613 " public void foo() {\n"+
614 " new Object() { \n"+
615 " public void bar() { \n"+
616 " if (true) {\n"+
617 " final\n"+
618 " }\n"+
619 " }\n"+
620 "\n"+
621 " }; \n"+
622 "\n"+
623 " if (false) {\n"+
624 " Object var = new Object() {\n"+
625 " void toto() {\n"+
626 " \n"+
627 " }\n"+
628 " };\n"+
629 " }\n"+
630 " }\n"+
631 "}"
632 );
633 ICompilationUnit cuA = getCompilationUnit("P/A.java");
634 try {
635 runConversion(getJLS3(), cuA, true, true, true);
636 } catch(IllegalArgumentException e) {
637 assertTrue("Unexpected IllegalArgumentException", false);
638 }
639 } finally {
640 deleteProject("P");
641 }
642 }
643 /**
644 * @bug 214647: [dom] NPE in MethodBinding.getParameterAnnotations(..)
645 * @test Ensures that no NPE occurs when parameters have no annotation
646 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=214647"
647 */
testBug214647()648 public void testBug214647() throws CoreException, IOException {
649 this.workingCopies = new ICompilationUnit[1];
650 this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
651 "public class Test {\n" +
652 " void m(String str) {}\n" +
653 "}\n"
654 );
655
656 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
657 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
658 checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
659 "----- param 1-----\n",
660 methodDeclaration.resolveBinding()
661 );
662 }
testBug214647b()663 public void testBug214647b() throws CoreException, IOException {
664 this.workingCopies = new ICompilationUnit[1];
665 this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
666 "public class Test {\n" +
667 " void m(String str, Object o, int x) {}\n" +
668 "}\n"
669 );
670
671 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
672 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
673 checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
674 "----- param 1-----\n" +
675 "----- param 2-----\n" +
676 "----- param 3-----\n",
677 methodDeclaration.resolveBinding()
678 );
679 }
680
681 /**
682 * @bug 215759: DOM AST regression tests should be improved
683 * @test these tests test the new DOM AST test framework
684 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=215759"
685 */
testBug215759a()686 public void testBug215759a() throws CoreException {
687 this.workingCopies = new ICompilationUnit[1];
688
689 this.workingCopies[0] = getWorkingCopy(
690 "/Converter/src/p/Y.java",
691 "package p;\n" +
692 "public class Y {\n" +
693 "}",
694 true/*resolve*/);
695
696 ASTResult result = this.buildMarkedAST(
697 "/Converter/src/p/X.java",
698 "package p;\n" +
699 "public class X extends Y {\n" +
700 " /**\n" +
701 " * blabla1\n" +
702 " * @param [*1*]string[*1*] blabla2\n" +
703 " */\n" +
704 " protected [*2*]String[*2*] foo(String string) {\n" +
705 " return [*3*](\"\" + string + \"\")[*3*] + (\"\");\n" +
706 " }\n" +
707 " /*comment*/[*4*]protected void bar() {}[*4*]\n" +
708 " #\n" +
709 "}");
710
711 assertASTResult(
712 "===== AST =====\n" +
713 "package p;\n" +
714 "public class X extends Y {\n" +
715 " /** \n" +
716 " * blabla1\n" +
717 " * @param [*1*]string[*1*] blabla2\n" +
718 " */\n" +
719 " protected [*2*]String[*2*] foo( String string){\n" +
720 " return [*3*](\"\" + string + \"\")[*3*] + (\"\");\n" +
721 " }\n" +
722 " [*4*]protected void bar(){\n" +
723 " }[*4*]\n" +
724 "}\n" +
725 "\n" +
726 "===== Details =====\n" +
727 "1:SIMPLE_NAME,[66,6],,,[VARIABLE,Lp/X;.foo(Ljava/lang/String;)Ljava/lang/String;#string#0#0,]\n" +
728 "2:SIMPLE_TYPE,[97,6],,,[TYPE,Ljava/lang/String;,]\n" +
729 "2:SIMPLE_NAME,[97,6],,,[TYPE,Ljava/lang/String;,]\n" +
730 "3:PARENTHESIZED_EXPRESSION,[134,18],,,[N/A]\n" +
731 "4:METHOD_DECLARATION,[176,23],,,[METHOD,Lp/X;.bar()V,]\n" +
732 "===== Problems =====\n" +
733 "1. ERROR in /Converter/src/p/X.java (at line 11)\n" +
734 " #\n" +
735 " ^\n" +
736 "Syntax error on token \"Invalid Character\", delete this token\n",
737 result);
738 }
739
testBug215759b()740 public void testBug215759b() throws CoreException {
741 this.workingCopies = new ICompilationUnit[1];
742
743 this.workingCopies[0] = getWorkingCopy(
744 "/Converter/src/p/Y.java",
745 "package p;\n" +
746 "public class Y {\n" +
747 "}",
748 true/*resolve*/);
749
750 ASTResult result = this.buildMarkedAST(
751 "/Converter/src/p/X.java",
752 "package p;\n" +
753 "public class X extends Y {\n" +
754 " /**\n" +
755 " * blabla1\n" +
756 " * @param [*1*]string[*1*] blabla2\n" +
757 " */\n" +
758 " protected [*2*]String[*2*] foo(String string) {\n" +
759 " return [*3*](\"\" + string + \"\")[*3*] + (\"\");\n" +
760 " }\n" +
761 " /*comment*/[*4*]protected void bar() {}[*4*]\n" +
762 " [*5*]/**@deprecated*/protected void bar2() {}[*5*]\n" +
763 "}");
764
765 assertASTResult(
766 "===== AST =====\n" +
767 "package p;\n" +
768 "public class X extends Y {\n" +
769 " /** \n" +
770 " * blabla1\n" +
771 " * @param [*1*]string[*1*] blabla2\n" +
772 " */\n" +
773 " protected [*2*]String[*2*] foo( String string){\n" +
774 " return [*3*](\"\" + string + \"\")[*3*] + (\"\");\n" +
775 " }\n" +
776 " [*4*]protected void bar(){\n" +
777 " }[*4*]\n" +
778 " [*5*]/** \n" +
779 " * @deprecated\n" +
780 " */\n" +
781 " protected void bar2(){\n" +
782 " }[*5*]\n" +
783 "}\n" +
784 "\n" +
785 "===== Details =====\n" +
786 "1:SIMPLE_NAME,[66,6],,,[VARIABLE,Lp/X;.foo(Ljava/lang/String;)Ljava/lang/String;#string#0#0,]\n" +
787 "2:SIMPLE_TYPE,[97,6],,,[TYPE,Ljava/lang/String;,]\n" +
788 "2:SIMPLE_NAME,[97,6],,,[TYPE,Ljava/lang/String;,]\n" +
789 "3:PARENTHESIZED_EXPRESSION,[134,18],,,[N/A]\n" +
790 "4:METHOD_DECLARATION,[176,23],[165,34],,[METHOD,Lp/X;.bar()V,]\n" +
791 "5:METHOD_DECLARATION,[201,40],,,[METHOD,Lp/X;.bar2()V,DEPRECATED]\n" +
792 "===== Problems =====\n" +
793 "No problem",
794 result);
795 }
796 /**
797 * @bug 218824: [DOM/AST] incorrect code leads to IllegalArgumentException during AST creation
798 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=218824"
799 */
testBug218824a()800 public void testBug218824a() throws JavaModelException {
801 ASTResult result = this.buildMarkedAST(
802 "/Converter15/src/a/X.java",
803 "package a;\n" +
804 "public class X {\n"+
805 " public void takeParam(int i) {\n"+
806 " // do something\n"+
807 " }\n"+
808 "\n"+
809 " void test() {\n"+
810 " char c = 'a';\n"+
811 " public void takeParam(int i) {\n"+
812 " // do something\n"+
813 " }\n"+
814 "\n"+
815 " void test() {\n"+
816 " char c = 'a';\n"+
817 " takeParam((int) c);\n"+
818 " }[*1*]takeParam([*1*](int) c);\n"+
819 " }\n"+
820 "}\n");
821
822 assertASTResult(
823 "===== AST =====\n" +
824 "package a;\n" +
825 "public class X {\n" +
826 " public void takeParam( int i){\n" +
827 " }\n" +
828 " void test(){\n" +
829 " char c=\'a\';\n" +
830 " public void takeParam;\n" +
831 " int i;\n" +
832 " new test(){\n" +
833 " char c=\'a\';\n" +
834 "{\n" +
835 " takeParam((int)c);\n" +
836 " }\n" +
837 " [*1*]void takeParam(){\n" +
838 " }[*1*]\n" +
839 " }\n" +
840 ";\n" +
841 " }\n" +
842 "}\n" +
843 "\n" +
844 "===== Details =====\n" +
845 "1:METHOD_DECLARATION,[447,10],,MALFORMED,[null]\n" +
846 "===== Problems =====\n" +
847 "1. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
848 " public void takeParam(int i) {\n" +
849 " ^^^^^^^^^\n" +
850 "void is an invalid type for the variable takeParam\n" +
851 "2. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
852 " public void takeParam(int i) {\n" +
853 " ^\n" +
854 "Syntax error on token \"(\", ; expected\n" +
855 "3. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
856 " public void takeParam(int i) {\n" +
857 " ^\n" +
858 "Syntax error on token \")\", ; expected\n" +
859 "4. ERROR in /Converter15/src/a/X.java (at line 13)\n" +
860 " void test() {\n" +
861 " ^^^^\n" +
862 "Syntax error on token \"void\", new expected\n" +
863 "5. ERROR in /Converter15/src/a/X.java (at line 13)\n" +
864 " void test() {\n" +
865 " ^^^^\n" +
866 "test cannot be resolved to a type\n" +
867 "6. ERROR in /Converter15/src/a/X.java (at line 14)\n" +
868 " char c = \'a\';\n" +
869 " ^\n" +
870 "Syntax error on token \";\", { expected after this token\n" +
871 "7. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
872 " }takeParam((int) c);\n" +
873 " ^\n" +
874 "Syntax error, insert \"}\" to complete ClassBody\n" +
875 "8. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
876 " }takeParam((int) c);\n" +
877 " ^\n" +
878 "Syntax error, insert \";\" to complete Statement\n" +
879 "9. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
880 " }takeParam((int) c);\n" +
881 " ^^^^^^^^^^\n" +
882 "Return type for the method is missing\n",
883 result);
884 }
885 /**
886 * @bug 215137: [AST]Some malformed MethodDeclaration, their Block is null, but they actually have Block
887 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=215137"
888 */
testBug215137a()889 public void testBug215137a() throws JavaModelException {
890 ASTResult result = this.buildMarkedAST(
891 "/Converter15/src/a/X.java",
892 "package a;\n" +
893 "public class X {\n"+
894 " public void foo() [*1*]{\n"+
895 " System.out.println(\"hello);\n"+
896 " }[*1*]\n"+
897 "}\n");
898
899 assertASTResult(
900 "===== AST =====\n" +
901 "package a;\n" +
902 "public class X {\n" +
903 " public void foo()[*1*]{\n" +
904 " }[*1*]\n" +
905 "}\n" +
906 "\n" +
907 "===== Details =====\n" +
908 "1:BLOCK,[54,55],,RECOVERED,[N/A]\n" +
909 "===== Problems =====\n" +
910 "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
911 " System.out.println(\"hello);\n" +
912 " ^^^^^^^^\n" +
913 "String literal is not properly closed by a double-quote\n",
914 result);
915 }
testBug215137b()916 public void testBug215137b() throws JavaModelException {
917 ASTResult result = this.buildMarkedAST(
918 "/Converter15/src/a/X.java",
919 "package a;\n" +
920 "public class X {\n"+
921 " public void foo() [*1*]{\n"+
922 " System.out.println('a);\n"+
923 " }[*1*]\n"+
924 "}\n");
925
926 assertASTResult(
927 "===== AST =====\n" +
928 "package a;\n" +
929 "public class X {\n" +
930 " public void foo()[*1*]{\n" +
931 " }[*1*]\n" +
932 "}\n" +
933 "\n" +
934 "===== Details =====\n" +
935 "1:BLOCK,[54,51],,RECOVERED,[N/A]\n" +
936 "===== Problems =====\n" +
937 "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
938 " System.out.println(\'a);\n" +
939 " ^^\n" +
940 "Invalid character constant\n",
941 result);
942 }
testBug215137c()943 public void testBug215137c() throws JavaModelException {
944 ASTResult result = this.buildMarkedAST(
945 "/Converter15/src/a/X.java",
946 "package a;\n" +
947 "public class X {\n"+
948 " public void foo() [*1*]{\n"+
949 " System.out.println(''a);\n"+
950 " }[*1*]\n"+
951 "}\n");
952
953 assertASTResult(
954 "===== AST =====\n" +
955 "package a;\n" +
956 "public class X {\n" +
957 " public void foo()[*1*]{\n" +
958 " }[*1*]\n" +
959 "}\n" +
960 "\n" +
961 "===== Details =====\n" +
962 "1:BLOCK,[54,52],,RECOVERED,[N/A]\n" +
963 "===== Problems =====\n" +
964 "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
965 " System.out.println(\'\'a);\n" +
966 " ^^\n" +
967 "Invalid character constant\n",
968 result);
969 }
testBug215137d()970 public void testBug215137d() throws JavaModelException {
971 ASTResult result = this.buildMarkedAST(
972 "/Converter15/src/a/X.java",
973 "package a;\n" +
974 "public class X {\n"+
975 " public void foo() [*1*]{\n"+
976 " 7eSystem.out.println();\n"+
977 " }[*1*]\n"+
978 "}\n");
979
980 assertASTResult(
981 "===== AST =====\n" +
982 "package a;\n" +
983 "public class X {\n" +
984 " public void foo()[*1*]{\n" +
985 " }[*1*]\n" +
986 "}\n" +
987 "\n" +
988 "===== Details =====\n" +
989 "1:BLOCK,[54,51],,RECOVERED,[N/A]\n" +
990 "===== Problems =====\n" +
991 "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
992 " 7eSystem.out.println();\n" +
993 " ^^^\n" +
994 "Invalid float literal number\n",
995 result);
996 }
997 /**
998 * @bug 223838: [dom] AnnotationBinding.isRecovered() always return false
999 * @test That the annotation binding is well flagged as recovered when the annotation is an unknown type
1000 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=223838"
1001 */
testBug223838()1002 public void testBug223838() throws JavaModelException {
1003 String contents =
1004 "package b223838;\n" +
1005 "@Deprecated\n" +
1006 "@Invalid\n" +
1007 "public class Test {\n" +
1008 "}\n";
1009 ICompilationUnit workingCopy = getWorkingCopy(
1010 "/Converter15/src/b223838/Test.java",
1011 contents,
1012 true/*resolve*/
1013 );
1014 ASTNode node = buildAST(contents, workingCopy, false, false, true);
1015 CompilationUnit unit = (CompilationUnit) node;
1016 List types = unit.types();
1017 TypeDeclaration type = (TypeDeclaration) types.get(0);
1018 ITypeBinding typeBinding = type.resolveBinding();
1019 IAnnotationBinding[] annotations = typeBinding.getAnnotations();
1020 assertTrue("Expected recovered annotation binding!", annotations[1].isRecovered());
1021 }
1022 /**
1023 * @bug 223838: [dom] AnnotationBinding.isRecovered() always return false
1024 * @test That the annotation binding is not reported when the recovery is off
1025 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=223838"
1026 */
testBug223838a()1027 public void testBug223838a() throws JavaModelException {
1028 String contents =
1029 "package b223838;\n" +
1030 "@Deprecated\n" +
1031 "@Invalid\n" +
1032 "public class Test {\n" +
1033 "}\n";
1034 ICompilationUnit workingCopy = getWorkingCopy(
1035 "/Converter15/src/b223838/Test.java",
1036 contents,
1037 true/*resolve*/
1038 );
1039 ASTNode node = buildAST(contents, workingCopy, false, false, false);
1040 CompilationUnit unit = (CompilationUnit) node;
1041 List types = unit.types();
1042 TypeDeclaration type = (TypeDeclaration) types.get(0);
1043 ITypeBinding typeBinding = type.resolveBinding();
1044 IAnnotationBinding[] annotations = typeBinding.getAnnotations();
1045 assertEquals("Got more than one annotation binding", 1, annotations.length);
1046 }
1047
1048 /**
1049 * @bug 226357: NPE in MethodBinding.getParameterAnnotations() if some, but not all parameters are annotated
1050 * @test Verify that NPE does no longer occur on the given test case
1051 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=226357"
1052 */
testBug226357()1053 public void testBug226357() throws CoreException, IOException {
1054 this.workingCopies = new ICompilationUnit[2];
1055 this.workingCopies[0] = getWorkingCopy("/Converter15/src/ParameterSubsetAnnotated.java",
1056 "public class ParameterSubsetAnnotated {\n" +
1057 " public @interface NonZero { }\n" +
1058 " public static int safeDiv(int a, @NonZero int b) {\n" +
1059 " return a / b;\n" +
1060 " }\n" +
1061 "}"
1062 );
1063 this.workingCopies[1] = getWorkingCopy("/Converter15/src/ParameterSubsetClient.java",
1064 "public class ParameterSubsetClient {\n" +
1065 "\n" +
1066 " public void client() {\n" +
1067 " ParameterSubsetAnnotated.safeDiv(5, 0);\n" +
1068 " }\n" +
1069 "\n" +
1070 "}\n"
1071 );
1072
1073 CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[1], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
1074 MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
1075 ExpressionStatement statement = (ExpressionStatement) methodDeclaration.getBody().statements().get(0);
1076 MethodInvocation methodInvocation = (MethodInvocation) statement.getExpression();
1077 checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
1078 "----- param 1-----\n" +
1079 "----- param 2-----\n" +
1080 "@LParameterSubsetAnnotated$NonZero;\n",
1081 methodInvocation.resolveMethodBinding()
1082 );
1083 }
1084
testBug274898a()1085 public void testBug274898a() throws JavaModelException {
1086 ASTResult result = this.buildMarkedAST(
1087 "/Converter15/src/a/X.java",
1088 "package a;\n" +
1089 "public class X {\n"+
1090 " public void foo() {\n"+
1091 " [*1*]Object o = new [*1*][*2*]new Object(){}[*2*]; \n"+
1092 " }\n"+
1093 "}\n");
1094
1095 assertASTResult(
1096 "===== AST =====\n" +
1097 "package a;\n" +
1098 "public class X {\n" +
1099 " public void foo(){\n" +
1100 " [*1*]Object o;[*1*]\n" +
1101 " [*2*]new Object(){\n" +
1102 " }\n" +
1103 ";[*2*]\n" +
1104 " }\n" +
1105 "}\n" +
1106 "\n" +
1107 "===== Details =====\n" +
1108 "1:VARIABLE_DECLARATION_STATEMENT,[72,15],,,[N/A]\n" +
1109 "2:EXPRESSION_STATEMENT,[87,14],,,[N/A]\n" +
1110 "2:CLASS_INSTANCE_CREATION,[87,14],,RECOVERED,[N/A]\n" +
1111 "===== Problems =====\n" +
1112 "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
1113 " Object o = new new Object(){}; \n" +
1114 " ^^^\n" +
1115 "Syntax error on token \"new\", delete this token\n",
1116 result);
1117 }
testBug274898b()1118 public void testBug274898b() throws JavaModelException {
1119 ASTResult result = this.buildMarkedAST(
1120 "/Converter15/src/a/X.java",
1121 "package a;\n" +
1122 "public class X {\n"+
1123 " public void foo() {\n"+
1124 " [*1*]Object o = new # [*1*][*2*]new Object(){}[*2*]; \n"+
1125 " }\n"+
1126 "}\n");
1127
1128 assertASTResult(
1129 "===== AST =====\n" +
1130 "package a;\n" +
1131 "public class X {\n" +
1132 " public void foo(){\n" +
1133 " [*1*]Object o;[*1*]\n" +
1134 " [*2*]new Object(){\n" +
1135 " }\n" +
1136 ";[*2*]\n" +
1137 " }\n" +
1138 "}\n" +
1139 "\n" +
1140 "===== Details =====\n" +
1141 "1:VARIABLE_DECLARATION_STATEMENT,[72,17],,,[N/A]\n" +
1142 "2:EXPRESSION_STATEMENT,[89,14],,,[N/A]\n" +
1143 "2:CLASS_INSTANCE_CREATION,[89,14],,,[N/A]\n" +
1144 "===== Problems =====\n" +
1145 "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
1146 " Object o = new # new Object(){}; \n" +
1147 " ^^^^^\n" +
1148 "Syntax error on tokens, delete these tokens\n",
1149 result);
1150 }
1151
testBug277204a()1152 public void testBug277204a() throws JavaModelException {
1153 ASTResult result = this.buildMarkedAST(
1154 "/Converter15/src/a/X.java",
1155 "package a;\n" +
1156 "public class X {\n" +
1157 " {\n" +
1158 " class Local {\n" +
1159 " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*] \n" +
1160 " }\n" +
1161 " }\n" +
1162 "}\n");
1163
1164 assertASTResult(
1165 "===== AST =====\n" +
1166 "package a;\n" +
1167 "public class X {\n" +
1168 "{\n" +
1169 "class Local {\n" +
1170 " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
1171 " }\n" +
1172 " }\n" +
1173 "}\n" +
1174 "\n" +
1175 "===== Details =====\n" +
1176 "1:FIELD_DECLARATION,[69,16],,,[N/A]\n" +
1177 "2:VARIABLE_DECLARATION_FRAGMENT,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
1178 "2:SIMPLE_NAME,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
1179 "3:VARIABLE_DECLARATION_FRAGMENT,[79,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
1180 "3:SIMPLE_NAME,[79,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
1181 "===== Problems =====\n" +
1182 "No problem",
1183 result);
1184 }
testBug277204b()1185 public void testBug277204b() throws JavaModelException {
1186 ASTResult result = this.buildMarkedAST(
1187 "/Converter15/src/a/X.java",
1188 "package a;\n" +
1189 "public class X {\n" +
1190 " {\n" +
1191 " class Local {\n" +
1192 " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*] \n" +
1193 " [*1*]}\n" +
1194 " }\n" +
1195 "}\n");
1196
1197 assertASTResult(
1198 "===== AST =====\n" +
1199 "package a;\n" +
1200 "public class X {\n" +
1201 "{\n" +
1202 "class Local {\n" +
1203 " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
1204 " }\n" +
1205 " }\n" +
1206 "}\n" +
1207 "\n" +
1208 "===== Details =====\n" +
1209 "1:FIELD_DECLARATION,[69,26],,MALFORMED,[N/A]\n" +
1210 "2:VARIABLE_DECLARATION_FRAGMENT,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
1211 "2:SIMPLE_NAME,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
1212 "3:VARIABLE_DECLARATION_FRAGMENT,[79,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
1213 "3:SIMPLE_NAME,[79,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
1214 "===== Problems =====\n" +
1215 "1. ERROR in /Converter15/src/a/X.java (at line 5)\n" +
1216 " Object x, Local \n" +
1217 " ^^^^^\n" +
1218 "Syntax error, insert \";\" to complete ClassBodyDeclarations\n",
1219 result);
1220 }
testBug277204c()1221 public void testBug277204c() throws JavaModelException {
1222 ASTResult result = this.buildMarkedAST(
1223 "/Converter15/src/a/X.java",
1224 "package a;\n" +
1225 "public class X {\n" +
1226 " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*] \n" +
1227 "}\n");
1228
1229 assertASTResult(
1230 "===== AST =====\n" +
1231 "package a;\n" +
1232 "public class X {\n" +
1233 " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
1234 "}\n" +
1235 "\n" +
1236 "===== Details =====\n" +
1237 "1:FIELD_DECLARATION,[32,16],,,[N/A]\n" +
1238 "2:VARIABLE_DECLARATION_FRAGMENT,[39,1],,,[VARIABLE,La/X;.x)Ljava/lang/Object;,]\n" +
1239 "2:SIMPLE_NAME,[39,1],,,[VARIABLE,La/X;.x)Ljava/lang/Object;,]\n" +
1240 "3:VARIABLE_DECLARATION_FRAGMENT,[42,5],,,[VARIABLE,La/X;.Local)Ljava/lang/Object;,]\n" +
1241 "3:SIMPLE_NAME,[42,5],,,[VARIABLE,La/X;.Local)Ljava/lang/Object;,]\n" +
1242 "===== Problems =====\n" +
1243 "No problem",
1244 result);
1245 }
testBug277204d()1246 public void testBug277204d() throws JavaModelException {
1247 ASTResult result = this.buildMarkedAST(
1248 "/Converter15/src/a/X.java",
1249 "package a;\n" +
1250 "public class X {\n" +
1251 " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*][*1*] \n" +
1252 "}\n");
1253
1254 assertASTResult(
1255 "===== AST =====\n" +
1256 "package a;\n" +
1257 "public class X {\n" +
1258 " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
1259 "}\n" +
1260 "\n" +
1261 "===== Details =====\n" +
1262 "1:FIELD_DECLARATION,[32,15],,MALFORMED|RECOVERED,[N/A]\n" +
1263 "2:VARIABLE_DECLARATION_FRAGMENT,[39,1],,,[VARIABLE,La/X;.x)Ljava/lang/Object;,]\n" +
1264 "2:SIMPLE_NAME,[39,1],,,[VARIABLE,La/X;.x)Ljava/lang/Object;,]\n" +
1265 "3:VARIABLE_DECLARATION_FRAGMENT,[42,5],,,[VARIABLE,La/X;.Local)Ljava/lang/Object;,]\n" +
1266 "3:SIMPLE_NAME,[42,5],,,[VARIABLE,La/X;.Local)Ljava/lang/Object;,]\n" +
1267 "===== Problems =====\n" +
1268 "1. ERROR in /Converter15/src/a/X.java (at line 3)\n" +
1269 " Object x, Local \n" +
1270 " ^^^^^\n" +
1271 "Syntax error, insert \";\" to complete ClassBodyDeclarations\n",
1272 result);
1273 }
testBug277204e()1274 public void testBug277204e() throws JavaModelException {
1275 ASTResult result = this.buildMarkedAST(
1276 "/Converter15/src/a/X.java",
1277 "package a;\n" +
1278 "public class X {\n" +
1279 " {\n" +
1280 " class Local {\n" +
1281 " [*1*]Object [*2*]x[*2*],\n" +
1282 " [*3*]Local[*3*] \n" +
1283 " [*1*]}\n" +
1284 " }\n" +
1285 "}\n");
1286
1287 assertASTResult(
1288 "===== AST =====\n" +
1289 "package a;\n" +
1290 "public class X {\n" +
1291 "{\n" +
1292 "class Local {\n" +
1293 " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
1294 " }\n" +
1295 " }\n" +
1296 "}\n" +
1297 "\n" +
1298 "===== Details =====\n" +
1299 "1:FIELD_DECLARATION,[69,42],,MALFORMED,[N/A]\n" +
1300 "2:VARIABLE_DECLARATION_FRAGMENT,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
1301 "2:SIMPLE_NAME,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
1302 "3:VARIABLE_DECLARATION_FRAGMENT,[95,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
1303 "3:SIMPLE_NAME,[95,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
1304 "===== Problems =====\n" +
1305 "1. ERROR in /Converter15/src/a/X.java (at line 6)\n" +
1306 " Local \n" +
1307 " ^^^^^\n" +
1308 "Syntax error, insert \";\" to complete ClassBodyDeclarations\n",
1309 result);
1310 }
1311
1312 // Verify that the binding for a constructor is a method binding
1313 @SuppressWarnings("deprecation")
testBug381503()1314 public void testBug381503() throws CoreException, IOException {
1315 try {
1316 IJavaProject javaProject = createJavaProject("P", new String[] { "src" }, new String[] { "CONVERTER_JCL_LIB" }, "bin");
1317 IType type = javaProject.findType("java.lang.IllegalMonitorStateException");
1318 IMethod javaElement = type.getMethod("IllegalMonitorStateException", new String[]{});
1319 ASTParser parser = ASTParser.newParser(AST.JLS8);
1320 parser.setResolveBindings(true);
1321 parser.setProject(javaProject);
1322 IBinding[] bindings = parser.createBindings(new IJavaElement[] { javaElement }, null);
1323 assertEquals("Wrong number of bindings", 1, bindings.length);
1324 assertTrue("Wrong binding kind: "+bindings[0].getClass().getName(), bindings[0] instanceof IMethodBinding);
1325 } finally {
1326 deleteProject("P");
1327 }
1328 }
1329 }
1330