1 /*******************************************************************************
2  * Copyright (c) 2013, 2016 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.HashMap;
18 import java.util.List;
19 
20 import junit.framework.Test;
21 
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.jdt.core.ICompilationUnit;
24 import org.eclipse.jdt.core.IJavaProject;
25 import org.eclipse.jdt.core.IPackageFragment;
26 import org.eclipse.jdt.core.IPackageFragmentRoot;
27 import org.eclipse.jdt.core.JavaCore;
28 import org.eclipse.jdt.core.dom.AST;
29 import org.eclipse.jdt.core.dom.ASTNode;
30 import org.eclipse.jdt.core.dom.ArrayCreation;
31 import org.eclipse.jdt.core.dom.ArrayType;
32 import org.eclipse.jdt.core.dom.Assignment;
33 import org.eclipse.jdt.core.dom.Block;
34 import org.eclipse.jdt.core.dom.CastExpression;
35 import org.eclipse.jdt.core.dom.CatchClause;
36 import org.eclipse.jdt.core.dom.ClassInstanceCreation;
37 import org.eclipse.jdt.core.dom.CompilationUnit;
38 import org.eclipse.jdt.core.dom.CreationReference;
39 import org.eclipse.jdt.core.dom.EnhancedForStatement;
40 import org.eclipse.jdt.core.dom.Expression;
41 import org.eclipse.jdt.core.dom.ExpressionStatement;
42 import org.eclipse.jdt.core.dom.FieldDeclaration;
43 import org.eclipse.jdt.core.dom.IAnnotationBinding;
44 import org.eclipse.jdt.core.dom.IBinding;
45 import org.eclipse.jdt.core.dom.IMethodBinding;
46 import org.eclipse.jdt.core.dom.ITypeBinding;
47 import org.eclipse.jdt.core.dom.IVariableBinding;
48 import org.eclipse.jdt.core.dom.IfStatement;
49 import org.eclipse.jdt.core.dom.InstanceofExpression;
50 import org.eclipse.jdt.core.dom.MarkerAnnotation;
51 import org.eclipse.jdt.core.dom.MethodDeclaration;
52 import org.eclipse.jdt.core.dom.MethodInvocation;
53 import org.eclipse.jdt.core.dom.ParameterizedType;
54 import org.eclipse.jdt.core.dom.ParenthesizedExpression;
55 import org.eclipse.jdt.core.dom.PrefixExpression;
56 import org.eclipse.jdt.core.dom.QualifiedName;
57 import org.eclipse.jdt.core.dom.QualifiedType;
58 import org.eclipse.jdt.core.dom.ReturnStatement;
59 import org.eclipse.jdt.core.dom.SimpleName;
60 import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
61 import org.eclipse.jdt.core.dom.ThisExpression;
62 import org.eclipse.jdt.core.dom.TryStatement;
63 import org.eclipse.jdt.core.dom.Type;
64 import org.eclipse.jdt.core.dom.TypeDeclaration;
65 import org.eclipse.jdt.core.dom.TypeMethodReference;
66 import org.eclipse.jdt.core.dom.TypeParameter;
67 import org.eclipse.jdt.core.dom.UnionType;
68 import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
69 import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
70 import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
71 import org.eclipse.jdt.core.dom.WildcardType;
72 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
73 
74 @SuppressWarnings({"rawtypes", "unchecked"})
75 public class TypeBindingTests308 extends ConverterTestSetup {
76 
77 	ICompilationUnit workingCopy;
78 
suite()79 	public static Test suite() {
80 		return buildModelTestSuite(TypeBindingTests308.class);
81 	}
82 	@Override
setUpSuite()83 	public void setUpSuite() throws Exception {
84 		super.setUpSuite();
85 		this.ast = AST.newAST(getAST8(), false);
86 	}
87 	/**
88 	 * @deprecated
89 	 */
getAST8()90 	protected int getAST8() {
91 		return AST.JLS8;
92 	}
TypeBindingTests308(String testName)93 	public TypeBindingTests308(String testName){
94 		super(testName);
95 	}
96 	static {
97 //		TESTS_NUMBERS = new int[] { };
98 //		TESTS_RANGE = new int[] { };
99 //		TESTS_NAMES = new String[] {"test027"};
100 	}
101 
verifyAnnotationOnType(Type type, String[] annots)102 	private void verifyAnnotationOnType(Type type, String[] annots) {
103 		verifyAnnotationsOnBinding(type.resolveBinding(), annots);
104 	}
105 
verifyAnnotationsOnBinding(ITypeBinding binding, String[] annots)106 	private void verifyAnnotationsOnBinding(ITypeBinding binding, String[] annots) {
107 		IAnnotationBinding[] annotations = binding.getTypeAnnotations();
108 		assertNotNull("Should not be null", annotations);
109 		int length = annots.length;
110 		assertEquals("Incorrect type use annotations", length, annotations.length);
111 		for (int i = 0; i < length; i++) {
112 			assertEquals("Incorrect annotation", annots[i], (annotations[i] == null) ? null : annotations[i].toString());
113 		}
114 	}
115 
verifyAnnotationsOnBinding(IVariableBinding binding, String[] annots)116 	private void verifyAnnotationsOnBinding(IVariableBinding binding, String[] annots) {
117 		IAnnotationBinding[] annotations = binding.getAnnotations();
118 		assertNotNull("Should not be null", annotations);
119 		int length = annots.length;
120 		assertEquals("Incorrect annotations", length, annotations.length);
121 		for (int i = 0; i < length; i++) {
122 			assertEquals("Incorrect annotation", annots[i], (annotations[i] == null) ? null : annotations[i].toString());
123 		}
124 	}
125 
test000()126 	public void test000() throws Exception {
127 		String contents =
128 					"public class X extends @Marker @SingleMember(0) @Normal(value = 0) Object {\n" +
129 					"}\n" +
130 					"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
131 					"@interface Marker {}\n" +
132 					"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
133 					"@interface SingleMember { int value() default 0;}\n" +
134 					"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
135 					"@interface Normal { int value() default 0;}\n";
136 
137 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
138 		ASTNode node = buildAST(contents, this.workingCopy);
139 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
140 		CompilationUnit compilationUnit = (CompilationUnit) node;
141 		assertProblemsSize(compilationUnit, 0);
142 		List types = compilationUnit.types();
143 		assertEquals("Incorrect no of types", 4, types.size());
144 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
145 		Type type = typeDecl.getSuperclassType();
146 		assertNotNull("Super class should not be null", type);
147 
148 		verifyAnnotationOnType(type, new String[]{"@Marker()", "@SingleMember(value = 0)", "@Normal(value = 0)"});
149 	}
test001()150 	public void test001() throws Exception {
151 		String contents =
152 				"public class X {\n" +
153 						"    @Marker int x;\n" +
154 						"}\n" +
155 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
156 						"@interface Marker {}\n";
157 
158 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
159 		ASTNode node = buildAST(contents, this.workingCopy);
160 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
161 		CompilationUnit compilationUnit = (CompilationUnit) node;
162 		assertProblemsSize(compilationUnit, 0);
163 		List types = compilationUnit.types();
164 		assertEquals("Incorrect no of types", 2, types.size());
165 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
166 		FieldDeclaration[] fields = typeDecl.getFields();
167 		assertEquals("Incorrect field", 1, fields.length);
168 		FieldDeclaration field = fields[0];
169 		verifyAnnotationOnType(field.getType(), new String[]{"@Marker()"});
170 	}
test002()171 	public void test002() throws Exception {
172 		String contents =
173 						"public class X {\n" +
174 						"    @Marker <@Marker2 T> int x() { return 10; };\n" +
175 						"}\n" +
176 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" +
177 						"@interface Marker2{}\n" +
178 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
179 						"@interface Marker {}\n";
180 
181 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
182 		ASTNode node = buildAST(contents, this.workingCopy);
183 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
184 		CompilationUnit compilationUnit = (CompilationUnit) node;
185 		assertProblemsSize(compilationUnit, 0);
186 		List types = compilationUnit.types();
187 		assertEquals("Incorrect no of types", 3, types.size());
188 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
189 		MethodDeclaration[] methods = typeDecl.getMethods();
190 		assertEquals("Incorrect method", 1, methods.length);
191 		MethodDeclaration method = methods[0];
192 		List params = method.typeParameters();
193 		TypeParameter param = (TypeParameter) params.get(0);
194 		ITypeBinding binding = param.resolveBinding();
195 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker2()"});
196 		verifyAnnotationOnType(method.getReturnType2(), new String[]{"@Marker()"});
197 	}
test003()198 	public void test003() throws Exception {
199 		String contents =
200 						"public class X {\n" +
201 						"    int x(@Marker int p) { return 10; };\n" +
202 						"}\n" +
203 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
204 						"@interface Marker {}\n";
205 
206 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
207 		ASTNode node = buildAST(contents, this.workingCopy);
208 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
209 		CompilationUnit compilationUnit = (CompilationUnit) node;
210 		assertProblemsSize(compilationUnit, 0);
211 		List types = compilationUnit.types();
212 		assertEquals("Incorrect no of types", 2, types.size());
213 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
214 		MethodDeclaration[] methods = typeDecl.getMethods();
215 		assertEquals("Incorrect method", 1, methods.length);
216 		MethodDeclaration method = methods[0];
217 		List params = method.parameters();
218 		SingleVariableDeclaration param = (SingleVariableDeclaration) params.get(0);
219 		ITypeBinding binding = param.resolveBinding().getType();
220 
221 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
222 		verifyAnnotationOnType(param.getType(), new String[]{"@Marker()"});
223 	}
test004()224 	public void test004() throws Exception {
225 		String contents =
226 				"public class X {\n" +
227 						"    int x(@Marker int ... p) { return 10; };\n" +
228 						"}\n" +
229 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
230 						"@interface Marker {}\n";
231 
232 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
233 		ASTNode node = buildAST(contents, this.workingCopy);
234 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
235 		CompilationUnit compilationUnit = (CompilationUnit) node;
236 		assertProblemsSize(compilationUnit, 0);
237 		List types = compilationUnit.types();
238 		assertEquals("Incorrect no of types", 2, types.size());
239 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
240 		MethodDeclaration[] methods = typeDecl.getMethods();
241 		assertEquals("Incorrect method", 1, methods.length);
242 		MethodDeclaration method = methods[0];
243 		List params = method.parameters();
244 		SingleVariableDeclaration param = (SingleVariableDeclaration) params.get(0);
245 		verifyAnnotationOnType(param.getType(), new String[]{"@Marker()"});
246 	}
247 
test005()248 	public void test005() throws Exception {
249 			String contents =
250 				"public class X {\n" +
251 						"    int x(@Marker int @Marker2 [] @Marker3 ... p) { return 10; };\n" +
252 						"}\n" +
253 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
254 						"@interface Marker {}\n" +
255 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
256 						"@interface Marker2 {}\n" +
257 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
258 						"@interface Marker3 {}\n";
259 
260 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
261 		ASTNode node = buildAST(contents, this.workingCopy);
262 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
263 		CompilationUnit compilationUnit = (CompilationUnit) node;
264 		assertProblemsSize(compilationUnit, 0);
265 		List types = compilationUnit.types();
266 		assertEquals("Incorrect no of types", 4, types.size());
267 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
268 		MethodDeclaration[] methods = typeDecl.getMethods();
269 		assertEquals("Incorrect method", 1, methods.length);
270 		MethodDeclaration method = methods[0];
271 		List params = method.parameters();
272 		SingleVariableDeclaration param = (SingleVariableDeclaration) params.get(0);
273 		ArrayType type = (ArrayType) param.getType();
274 		ITypeBinding binding = type.resolveBinding();
275 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker2()"});
276 		verifyAnnotationsOnBinding(param.resolveBinding().getType(), new String[]{"@Marker2()"});
277 		binding = binding.getComponentType();
278 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
279 	}
test006()280 	public void test006() throws Exception {
281 		String contents =
282 						"public class X {\n" +
283 						"    int x() {\n" +
284 						"        try {\n" +
285 						"        } catch (@Marker NullPointerException | @Marker2 ArrayIndexOutOfBoundsException e) {\n" +
286 						"        }\n" +
287 						"        return 10;\n" +
288 						"    }\n" +
289 						"}\n" +
290 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
291 						"@interface Marker {}\n" +
292 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
293 						"@interface Marker2 {}\n";
294 
295 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
296 		ASTNode node = buildAST(contents, this.workingCopy);
297 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
298 		CompilationUnit compilationUnit = (CompilationUnit) node;
299 		assertProblemsSize(compilationUnit, 0);
300 		List types = compilationUnit.types();
301 		assertEquals("Incorrect no of types", 3, types.size());
302 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
303 		MethodDeclaration[] methods = typeDecl.getMethods();
304 		assertEquals("Incorrect method", 1, methods.length);
305 		MethodDeclaration method = methods[0];
306 		List statements = method.getBody().statements();
307 		TryStatement trySt = (TryStatement) statements.get(0);
308 		CatchClause catchCl = (CatchClause) trySt.catchClauses().get(0);
309 		UnionType union = (UnionType) catchCl.getException().getType();
310 		types = union.types();
311 		assertEquals("Incorrect union types", 2, types.size());
312 		Type type = (Type) types.get(0);
313 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
314 
315 		type = (Type) types.get(1);
316 		verifyAnnotationOnType(type, new String[]{"@Marker2()"});
317 	}
test007()318 	public void test007() throws Exception {
319 		String contents =
320 				"package java.lang;\n" +
321 				"public class X {\n" +
322 				"    public void x() throws Exception {\n" +
323 				"        try (@Marker LocalStream p = null; final @Marker2 LocalStream q = null; @Marker3 final LocalStream r = null) {}\n" +
324 				"    }\n" +
325 				"}\n" +
326 				"class LocalStream implements AutoCloseable {\n" +
327 				"    public void close() throws Exception {}\n" +
328 				"}\n" +
329 				"interface AutoCloseable {}\n" +
330 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
331 				"@interface Marker {}\n" +
332 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
333 				"@interface Marker2 {}\n" +
334 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
335 				"@interface Marker3 {}\n";
336 
337 		this.workingCopy = getWorkingCopy("/Converter18/src/java/lang/X.java", true/*resolve*/);
338 		ASTNode node = buildAST(contents, this.workingCopy);
339 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
340 		CompilationUnit compilationUnit = (CompilationUnit) node;
341 		assertProblemsSize(compilationUnit, 0);
342 		List types = compilationUnit.types();
343 		assertEquals("Incorrect no of types", 6, types.size());
344 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
345 		MethodDeclaration[] methods = typeDecl.getMethods();
346 		assertEquals("Incorrect method", 1, methods.length);
347 		MethodDeclaration method = methods[0];
348 		List statements = method.getBody().statements();
349 		TryStatement trySt = (TryStatement) statements.get(0);
350 		List resources = trySt.resources();
351 		assertEquals("Incorrect no of resources", 3, resources.size());
352 		VariableDeclarationExpression resource = (VariableDeclarationExpression) resources.get(0);
353 		Type type = resource.getType();
354 		assertNotNull("Resource type should not be null", type);
355 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
356 
357 		resource = (VariableDeclarationExpression) resources.get(1);
358 		type = resource.getType();
359 		assertNotNull("Resource type should not be null", type);
360 		verifyAnnotationOnType(type, new String[]{"@Marker2()"});
361 
362 		resource = (VariableDeclarationExpression) resources.get(2);
363 		type = resource.getType();
364 		assertNotNull("Resource type should not be null", type);
365 		verifyAnnotationOnType(type, new String[]{"@Marker3()"});
366 	}
test008()367 	public void test008() throws Exception {
368 		String contents =
369 				"public class X {\n" +
370 						"    int x() {\n" +
371 						"        for (@Marker int i: new int[3]) {}\n" +
372 						"        for (final @Marker int i: new int[3]) {}\n" +
373 						"        for (@Marker final int i: new int[3]) {}\n" +
374 						"        return 10;\n" +
375 						"    }\n" +
376 						"}\n" +
377 						"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
378 						"@interface Marker {}\n";
379 
380 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
381 		ASTNode node = buildAST(contents, this.workingCopy);
382 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
383 		CompilationUnit compilationUnit = (CompilationUnit) node;
384 		assertProblemsSize(compilationUnit, 0);
385 		List types = compilationUnit.types();
386 		assertEquals("Incorrect no of types", 2, types.size());
387 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
388 		MethodDeclaration[] methods = typeDecl.getMethods();
389 		assertEquals("Incorrect method", 1, methods.length);
390 		MethodDeclaration method = methods[0];
391 		List statements = method.getBody().statements();
392 		EnhancedForStatement forStmt = (EnhancedForStatement) statements.get(0);
393 		SingleVariableDeclaration param = forStmt.getParameter();
394 		Type type = param.getType();
395 		assertNotNull("Resource type should not be null", type);
396 		ITypeBinding binding = param.resolveBinding().getType();
397 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
398 		binding = type.resolveBinding();
399 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
400 	}
test009()401 	public void test009() throws Exception {
402 		String contents =
403 				"interface I {\n" +
404 				"    Object copy(int [] ia);\n" +
405 				"}\n" +
406 				"public class X  {\n" +
407 				"    public static void main(String [] args) {\n" +
408 				"        I i = @Marker int @Marker2 []::clone;\n" +
409 				"    }\n" +
410 				"}\n" +
411 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
412 				"@interface Marker {}\n" +
413 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
414 				"@interface Marker2 {}\n";
415 
416 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
417 		ASTNode node = buildAST(contents, this.workingCopy);
418 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
419 		CompilationUnit compilationUnit = (CompilationUnit) node;
420 		assertProblemsSize(compilationUnit, 0);
421 		List types = compilationUnit.types();
422 		assertEquals("Incorrect no of types", 4, types.size());
423 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
424 		MethodDeclaration[] methods = typeDecl.getMethods();
425 		assertEquals("Incorrect method", 1, methods.length);
426 		MethodDeclaration method = methods[0];
427 		List statements = method.getBody().statements();
428 		VariableDeclarationStatement stmt = (VariableDeclarationStatement) statements.get(0);
429 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) stmt.fragments().get(0);
430 		TypeMethodReference lambda = (TypeMethodReference) fragment.getInitializer();
431 		ArrayType type = (ArrayType) lambda.getType();
432 
433 		verifyAnnotationOnType(type, new String[]{"@Marker2()"});
434 		ITypeBinding binding = type.resolveBinding();
435 		binding = binding.getComponentType();
436 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
437 	}
test010()438 	public void test010() throws Exception {
439 		String contents =
440 				"public class X  {\n" +
441 				"    public static void main(String [] args) {\n" +
442 				"        int i [] = new @Marker int @Marker2 [4];\n" +
443 				"        int j [] = new @Marker2 int @Marker [] { 10 };\n" +
444 				"    }\n" +
445 				"}\n" +
446 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
447 				"@interface Marker {}\n" +
448 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
449 				"@interface Marker2 {}\n";
450 
451 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
452 		ASTNode node = buildAST(contents, this.workingCopy);
453 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
454 		CompilationUnit compilationUnit = (CompilationUnit) node;
455 		assertProblemsSize(compilationUnit, 0);
456 		List types = compilationUnit.types();
457 		assertEquals("Incorrect no of types", 3, types.size());
458 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
459 		MethodDeclaration[] methods = typeDecl.getMethods();
460 		assertEquals("Incorrect method", 1, methods.length);
461 		MethodDeclaration method = methods[0];
462 		List statements = method.getBody().statements();
463 		VariableDeclarationStatement stmt = (VariableDeclarationStatement) statements.get(0);
464 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) stmt.fragments().get(0);
465 		ArrayCreation arrayCr = (ArrayCreation) fragment.getInitializer();
466 
467 		ArrayType type = arrayCr.getType();
468 		ITypeBinding binding = type.resolveBinding();
469 		verifyAnnotationOnType(type, new String[]{"@Marker2()"});
470 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker2()"});
471 		binding = binding.getComponentType();
472 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
473 
474 		stmt = (VariableDeclarationStatement) statements.get(1);
475 		fragment = (VariableDeclarationFragment) stmt.fragments().get(0);
476 		arrayCr = (ArrayCreation) fragment.getInitializer();
477 		type = arrayCr.getType();
478 
479 		binding = type.resolveBinding();
480 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
481 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
482 		binding = binding.getComponentType();
483 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker2()"});
484 	}
test011()485 	public void test011() throws Exception {
486 		String contents =
487 				"public class X  {\n" +
488 				"    public static void main(String [] args) {\n" +
489 				"        int i = (@Marker int) 0;\n" +
490 				"        int j [] = (@Marker int @Marker2 []) null;\n" +
491 				"    }\n" +
492 				"}\n" +
493 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
494 				"@interface Marker {}\n" +
495 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
496 				"@interface Marker2 {}\n";
497 
498 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
499 		ASTNode node = buildAST(contents, this.workingCopy);
500 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
501 		CompilationUnit compilationUnit = (CompilationUnit) node;
502 		assertProblemsSize(compilationUnit, 0);
503 		List types = compilationUnit.types();
504 		assertEquals("Incorrect no of types", 3, types.size());
505 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
506 		MethodDeclaration[] methods = typeDecl.getMethods();
507 		assertEquals("Incorrect method", 1, methods.length);
508 		MethodDeclaration method = methods[0];
509 		List statements = method.getBody().statements();
510 		VariableDeclarationStatement stmt = (VariableDeclarationStatement) statements.get(0);
511 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) stmt.fragments().get(0);
512 		CastExpression castExp = (CastExpression) fragment.getInitializer();
513 		Type type = castExp.getType();
514 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
515 
516 		stmt = (VariableDeclarationStatement) statements.get(1);
517 		fragment = (VariableDeclarationFragment) stmt.fragments().get(0);
518 		castExp = (CastExpression) fragment.getInitializer();
519 		ArrayType arrayType = (ArrayType) castExp.getType();
520 
521 		ITypeBinding binding = arrayType.resolveBinding();
522 		verifyAnnotationOnType(arrayType, new String[]{"@Marker2()"});
523 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker2()"});
524 		binding = binding.getComponentType();
525 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
526 	}
test012()527 	public void test012() throws Exception {
528 		String contents =
529 				"public class X  {\n" +
530 				"    public static void main(String args) {\n" +
531 				"        if (args instanceof @Marker String) {\n" +
532 				"        }\n" +
533 				"    }\n" +
534 				"}\n" +
535 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
536 				"@interface Marker {}\n";
537 
538 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
539 		ASTNode node = buildAST(contents, this.workingCopy);
540 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
541 		CompilationUnit compilationUnit = (CompilationUnit) node;
542 		assertProblemsSize(compilationUnit, 0);
543 		List types = compilationUnit.types();
544 		assertEquals("Incorrect no of types", 2, types.size());
545 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
546 		MethodDeclaration[] methods = typeDecl.getMethods();
547 		assertEquals("Incorrect method", 1, methods.length);
548 		MethodDeclaration method = methods[0];
549 		List statements = method.getBody().statements();
550 		IfStatement ifStmt = (IfStatement) statements.get(0);
551 		InstanceofExpression instanceOf = (InstanceofExpression) ifStmt.getExpression();
552 		Type type = instanceOf.getRightOperand();
553 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
554 	}
test013()555 	public void test013() throws Exception {
556 			String contents =
557 				"public class X extends Y<@Marker(10) Integer, String> {}\n" +
558 				"class Y<T, V> {}\n" +
559 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
560 				"@interface Marker {int value();}\n";
561 
562 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
563 		ASTNode node = buildAST(contents, this.workingCopy);
564 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
565 		CompilationUnit compilationUnit = (CompilationUnit) node;
566 		assertProblemsSize(compilationUnit, 0);
567 		List types = compilationUnit.types();
568 		assertEquals("Incorrect no of types", 3, types.size());
569 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
570 		ParameterizedType superClass = (ParameterizedType) typeDecl.getSuperclassType();
571 		List arguments = superClass.typeArguments();
572 		assertEquals("Incorrect no of type arguments", 2, arguments.size());
573 		Type type = (Type) arguments.get(0);
574 
575 		verifyAnnotationOnType(type, new String[]{"@Marker(value = 10)"});
576 	}
test014()577 	public void test014() throws Exception {
578 		String contents =
579 				"public class X<T extends Object & Comparable<? super @Marker String>> {}\n" +
580 				"class Y<T> {}\n" +
581 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
582 				"@interface Marker {}\n";
583 
584 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
585 		ASTNode node = buildAST(contents, this.workingCopy);
586 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
587 		CompilationUnit compilationUnit = (CompilationUnit) node;
588 		assertProblemsSize(compilationUnit, 0);
589 		List types = compilationUnit.types();
590 		assertEquals("Incorrect no of types", 3, types.size());
591 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
592 		List typeParams = typeDecl.typeParameters();
593 
594 		TypeParameter typeParam = (TypeParameter) typeParams.get(0);
595 		List bounds = typeParam.typeBounds();
596 		assertEquals("Incorrect no of type bounds", 2, bounds.size());
597 		ParameterizedType type = (ParameterizedType) bounds.get(1);
598 		typeParams = type.typeArguments();
599 		assertEquals("Incorrect type params", 1, typeParams.size());
600 		WildcardType wildcard = (WildcardType)typeParams.get(0);
601 		Type bound = wildcard.getBound();
602 		assertNotNull("Bound should not be null", bound);
603 		verifyAnnotationOnType(bound, new String[]{"@Marker()"});
604 	}
test015()605 	public void test015() throws Exception {
606 		String contents =
607 				"public class X {\n" +
608 				"	void foo(Map<@Marker ? super @Marker2 Object, @Marker3 ? extends @Marker4 String> m){}\n" +
609 				"   void goo(Map<@Marker4 ? extends @Marker3 Object, @Marker2 ? super @Marker String> m){}\n" +
610 				"}\n" +
611 				"class Map<K, V>{}\n" +
612 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
613 				"@interface Marker {}\n" +
614 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
615 				"@interface Marker2 {}\n" +
616 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
617 				"@interface Marker3 {}\n" +
618 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
619 				"@interface Marker4 {}\n";
620 
621 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
622 		ASTNode node = buildAST(contents, this.workingCopy);
623 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
624 		CompilationUnit compilationUnit = (CompilationUnit) node;
625 		assertProblemsSize(compilationUnit, 0);
626 		List types = compilationUnit.types();
627 		assertEquals("Incorrect no of types", 6, types.size());
628 
629 		MethodDeclaration[] methods = ((TypeDeclaration) types.get(0)).getMethods();
630 		assertEquals("Incorrect no of metods", 2, methods.length);
631 		MethodDeclaration method = methods[0];
632 		SingleVariableDeclaration arg = (SingleVariableDeclaration) method.parameters().get(0);
633 
634 
635 		List typeArgs = ((ParameterizedType) arg.getType()).typeArguments();
636 
637 		WildcardType wildcard = (WildcardType) typeArgs.get(0);
638 		verifyAnnotationOnType(wildcard, new String[]{"@Marker()"});
639 		Type type = wildcard.getBound();
640 		verifyAnnotationOnType(type, new String[]{"@Marker2()"});
641 
642 		wildcard = (WildcardType) typeArgs.get(1);
643 		verifyAnnotationOnType(wildcard, new String[]{"@Marker3()"});
644 		type = wildcard.getBound();
645 		verifyAnnotationOnType(type, new String[]{"@Marker4()"});
646 
647 		method = methods[1];
648 		arg = (SingleVariableDeclaration) method.parameters().get(0);
649 		typeArgs = ((ParameterizedType) arg.getType()).typeArguments();
650 
651 		wildcard = (WildcardType) typeArgs.get(0);
652 		verifyAnnotationOnType(wildcard, new String[]{"@Marker4()"});
653 		type = wildcard.getBound();
654 		verifyAnnotationOnType(type, new String[]{"@Marker3()"});
655 
656 		wildcard = (WildcardType) typeArgs.get(1);
657 		verifyAnnotationOnType(wildcard, new String[]{"@Marker2()"});
658 		type = wildcard.getBound();
659 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
660 	}
test016()661 	public void test016() throws Exception {
662 		String contents =
663 				"public class X<E> {\n" +
664 				"  class Y {\n" +
665 				"    E e;\n" +
666 				"    E getOtherElement(Object other) {\n" +
667 				"      if (!(other instanceof @Marker X<?>.Y)) {};\n" +
668 				"      return null;\n" +
669 				"    }\n" +
670 				"  }\n" +
671 				"}\n" +
672 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
673 				"@interface Marker {}\n";
674 
675 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
676 		ASTNode node = buildAST(contents, this.workingCopy);
677 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
678 		CompilationUnit compilationUnit = (CompilationUnit) node;
679 		assertProblemsSize(compilationUnit, 0);
680 		List types = compilationUnit.types();
681 		assertEquals("Incorrect no of types", 2, types.size());
682 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
683 		typeDecl = typeDecl.getTypes()[0];
684 		MethodDeclaration method = typeDecl.getMethods()[0];
685 		IfStatement ifStmt = (IfStatement) method.getBody().statements().get(0);
686 		PrefixExpression prefix = (PrefixExpression ) ifStmt.getExpression();
687 		ParenthesizedExpression operand = (ParenthesizedExpression) prefix.getOperand();
688 		InstanceofExpression expression = (InstanceofExpression) operand.getExpression();
689 		QualifiedType type = (QualifiedType) expression.getRightOperand();
690 		verifyAnnotationOnType(type, new String[]{});
691 		verifyAnnotationOnType(type.getQualifier(), new String[]{"@Marker()"});
692 	}
test017()693 	public void test017() throws Exception {
694 		String contents =
695 				"public class X<P, C> {\n" +
696 				"  public X() {\n" +
697 				"    if (!(this instanceof @Marker X)) {}\n" +
698 				"  }\n" +
699 				"}\n" +
700 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
701 				"@interface Marker {}\n";
702 
703 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
704 		ASTNode node = buildAST(contents, this.workingCopy);
705 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
706 		CompilationUnit compilationUnit = (CompilationUnit) node;
707 		assertProblemsSize(compilationUnit, 0);
708 		List types = compilationUnit.types();
709 		assertEquals("Incorrect no of types", 2, types.size());
710 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
711 		MethodDeclaration method = typeDecl.getMethods()[0];
712 		IfStatement ifStmt = (IfStatement) method.getBody().statements().get(0);
713 		PrefixExpression prefix = (PrefixExpression ) ifStmt.getExpression();
714 		ParenthesizedExpression operand = (ParenthesizedExpression) prefix.getOperand();
715 		InstanceofExpression expression = (InstanceofExpression) operand.getExpression();
716 		verifyAnnotationOnType(expression.getRightOperand(), new String[]{"@Marker()"});
717 	}
test018()718 	public void test018() throws Exception {
719 		String contents =
720 				"interface I {\n" +
721 				"    void foo(Y<String>.Z z, int x);\n" +
722 				"}\n" +
723 				"public class X  {\n" +
724 				"    public static void main(String [] args) {\n" +
725 				"        I i = Y<String>.@Marker Z::foo;\n" +
726 				"        i.foo(new Y<String>().new Z(), 10); \n" +
727 				"    }\n" +
728 				"}\n" +
729 				"class Y<T> {\n" +
730 				"    class Z {\n" +
731 				"        void foo(int x) {\n" +
732 				"        }\n" +
733 				"    }\n" +
734 				"}\n" +
735 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
736 				"@interface Marker {}\n";
737 
738 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
739 		ASTNode node = buildAST(contents, this.workingCopy);
740 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
741 		CompilationUnit compilationUnit = (CompilationUnit) node;
742 		assertProblemsSize(compilationUnit, 0);
743 		List types = compilationUnit.types();
744 		assertEquals("Incorrect no of types", 4, types.size());
745 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
746 		MethodDeclaration method = typeDecl.getMethods()[0];
747 		VariableDeclarationStatement statement = (VariableDeclarationStatement) method.getBody().statements().get(0);
748 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) statement.fragments().get(0);
749 		TypeMethodReference initializer = (TypeMethodReference) fragment.getInitializer();
750 		Type type = initializer.getType();
751 		assertTrue(type.isQualifiedType());
752 		QualifiedType qualifiedType = (QualifiedType) type;
753 		checkSourceRange(qualifiedType.getName(), "Z", contents);
754 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
755 		assertEquals("Should be a qualified type", ASTNode.QUALIFIED_TYPE, type.getNodeType());
756 		verifyAnnotationOnType(((QualifiedType) type).getQualifier() , new String[]{});
757 	}
test019()758 	public void test019() throws Exception {
759 		String contents =
760 				"public class X  {\n" +
761 				"    public static void main(String [] args) {\n" +
762 				"        X [] x = new @Marker X @Marker2 [5];\n" +
763 				"        X [] x2 = new @Marker2 X @Marker [] { null };\n" +
764 				"    }\n" +
765 				"}\n" +
766 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
767 				"@interface Marker {}\n" +
768 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
769 				"@interface Marker2 {}\n";
770 
771 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
772 		ASTNode node = buildAST(contents, this.workingCopy);
773 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
774 		CompilationUnit compilationUnit = (CompilationUnit) node;
775 		assertProblemsSize(compilationUnit, 0);
776 		List types = compilationUnit.types();
777 		assertEquals("Incorrect no of types", 3, types.size());
778 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
779 		MethodDeclaration method = typeDecl.getMethods()[0];
780 		List statements = method.getBody().statements();
781 		assertEquals("Incorrect no of statements", 2, statements.size());
782 		VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(0);
783 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) statement.fragments().get(0);
784 		ArrayCreation initializer = (ArrayCreation) fragment.getInitializer();
785 		ArrayType arrayType = initializer.getType();
786 		ITypeBinding binding = arrayType.resolveBinding();
787 
788 		verifyAnnotationOnType(arrayType, new String[]{"@Marker2()"});
789 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker2()"});
790 
791 		binding = binding.getComponentType();
792 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
793 
794 		statement = (VariableDeclarationStatement) statements.get(1);
795 		fragment = (VariableDeclarationFragment) statement.fragments().get(0);
796 		initializer = (ArrayCreation) fragment.getInitializer();
797 		arrayType = initializer.getType();
798 		binding = arrayType.resolveBinding();
799 		verifyAnnotationOnType(arrayType, new String[]{"@Marker()"});
800 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker()"});
801 
802 		binding = binding.getComponentType();
803 		verifyAnnotationsOnBinding(binding, new String[]{"@Marker2()"});
804 	}
test020()805 	public void test020() throws Exception {
806 		String contents =
807 				"public class X  {\n" +
808 				"    public static void main(String [] args) {\n" +
809 				"        Map.Entry<String, String> [] e = (Map.@Marker Entry<String, String> []) null;\n" +
810 				"    }\n" +
811 				"}\n" +
812 				"class Map<K, V> {\n" +
813 				"	interface Entry<K, V> {}\n" +
814 				"}\n" +
815 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
816 				"@interface Marker {}\n";
817 
818 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
819 		ASTNode node = buildAST(contents, this.workingCopy);
820 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
821 		CompilationUnit compilationUnit = (CompilationUnit) node;
822 		assertProblemsSize(compilationUnit, 0);
823 		List types = compilationUnit.types();
824 		assertEquals("Incorrect no of types", 3, types.size());
825 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
826 		MethodDeclaration method = typeDecl.getMethods()[0];
827 		List statements = method.getBody().statements();
828 		assertEquals("Incorrect no of statements", 1, statements.size());
829 		VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(0);
830 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) statement.fragments().get(0);
831 		CastExpression castExp = (CastExpression) fragment.getInitializer();
832 		ArrayType arrayType = (ArrayType) castExp.getType();
833 		verifyAnnotationOnType(arrayType, new String[]{});
834 		ParameterizedType type = (ParameterizedType) arrayType.getElementType();
835 		verifyAnnotationOnType(type.getType(), new String[]{"@Marker()"});
836 	}
test021()837 	public void test021() throws Exception {
838 		String contents =
839 				"import java.io.Serializable;\n" +
840 				"import java.util.List;\n" +
841 				"public class X<T extends Comparable<T> & Serializable> {\n" +
842 				"	void foo(List<? extends @Marker @Marker2 Comparable<T>> p) {} \n" +
843 				"}\n" +
844 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
845 				"@interface Marker {}\n" +
846 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
847 				"@interface Marker2 {}\n";
848 
849 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
850 		ASTNode node = buildAST(contents, this.workingCopy);
851 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
852 		CompilationUnit compilationUnit = (CompilationUnit) node;
853 		assertProblemsSize(compilationUnit, 0);
854 		List types = compilationUnit.types();
855 		assertEquals("Incorrect no of types", 3, types.size());
856 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
857 		MethodDeclaration method = typeDecl.getMethods()[0];
858 		SingleVariableDeclaration param = (SingleVariableDeclaration) method.parameters().get(0);
859 		Type type = param.getType();
860 		assertEquals("Should be a parameterized type", ASTNode.PARAMETERIZED_TYPE, type.getNodeType());
861 		List typeArgs = ((ParameterizedType) type).typeArguments();
862 		assertEquals("Incorrect type args", 1, typeArgs.size());
863 		WildcardType wildcard = (WildcardType) typeArgs.get(0);
864 		ParameterizedType bound = (ParameterizedType) wildcard.getBound();
865 		verifyAnnotationOnType(bound, new String[]{"@Marker()", "@Marker2()"});
866 	}
test022()867 	public void test022() throws Exception {
868 		String contents =
869 				"public class X {\n" +
870 				"    X x = new @Marker X();\n" +
871 				"    X y = new <String> @Marker X();\n" +
872 				"	<T> X(){}\n" +
873 				"}\n" +
874 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
875 				"@interface Marker {}\n";
876 
877 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
878 		ASTNode node = buildAST(contents, this.workingCopy);
879 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
880 		CompilationUnit compilationUnit = (CompilationUnit) node;
881 		assertProblemsSize(compilationUnit, 0);
882 		List types = compilationUnit.types();
883 		assertEquals("Incorrect no of types", 2, types.size());
884 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
885 		FieldDeclaration[] fields = typeDecl.getFields();
886 		assertEquals("Incorrect no of fields", 2, fields.length);
887 		FieldDeclaration field = fields[0];
888 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0);
889 		ClassInstanceCreation creation = (ClassInstanceCreation) fragment.getInitializer();
890 		verifyAnnotationOnType(creation.getType(), new String[]{"@Marker()"});
891 
892 		field = fields[1];
893 		fragment = (VariableDeclarationFragment) field.fragments().get(0);
894 		creation = (ClassInstanceCreation) fragment.getInitializer();
895 		verifyAnnotationOnType(creation.getType(), new String[]{"@Marker()"});
896 	}
test023()897 	public void test023() throws Exception {
898 		String contents =
899 				"public class X {\n" +
900 				"    class Y {\n" +
901 				"	    <T> Y(){}\n" +
902 				"    }\n" +
903 				"    Y y1 = new @Marker X().new @Marker2 Y();\n" +
904 				"    Y y2 = new @Marker2 X().new <String> @Marker Y();\n" +
905 				"}\n" +
906 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
907 				"@interface Marker {}\n" +
908 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
909 				"@interface Marker2 {}\n";
910 
911 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
912 		ASTNode node = buildAST(contents, this.workingCopy);
913 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
914 		CompilationUnit compilationUnit = (CompilationUnit) node;
915 		assertProblemsSize(compilationUnit, 0);
916 		List types = compilationUnit.types();
917 		assertEquals("Incorrect no of types", 3, types.size());
918 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
919 		FieldDeclaration[] fields = typeDecl.getFields();
920 		assertEquals("Incorrect no of fields", 2, fields.length);
921 		FieldDeclaration field = fields[0];
922 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0);
923 		ClassInstanceCreation creation = (ClassInstanceCreation) fragment.getInitializer();
924 		verifyAnnotationOnType(creation.getType(), new String[]{"@Marker2()"});
925 		creation = (ClassInstanceCreation) creation.getExpression();
926 		verifyAnnotationOnType(creation.getType(), new String[]{"@Marker()"});
927 
928 		field = fields[1];
929 		fragment = (VariableDeclarationFragment) field.fragments().get(0);
930 		creation = (ClassInstanceCreation) fragment.getInitializer();
931 		verifyAnnotationOnType(creation.getType(), new String[]{"@Marker()"});
932 		creation = (ClassInstanceCreation) creation.getExpression();
933 		verifyAnnotationOnType(creation.getType(), new String[]{"@Marker2()"});
934 	}
test024()935 	public void test024() throws Exception {
936 		String contents =
937 				"public class X {\n" +
938 				"    void foo() throws @Marker NullPointerException, @Marker2 ArrayIndexOutOfBoundsException {}\n" +
939 				"}\n" +
940 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
941 				"@interface Marker {}\n" +
942 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
943 				"@interface Marker2 {}\n";
944 
945 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
946 		ASTNode node = buildAST(contents, this.workingCopy);
947 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
948 		CompilationUnit compilationUnit = (CompilationUnit) node;
949 		assertProblemsSize(compilationUnit, 0);
950 		List types = compilationUnit.types();
951 		assertEquals("Incorrect no of types", 3, types.size());
952 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
953 		MethodDeclaration method = typeDecl.getMethods()[0];
954 		List thrownTypes = method.thrownExceptionTypes();
955 		assertEquals("Incorrect no of thrown exceptions", 2, thrownTypes.size());
956 		Type type = (Type) thrownTypes.get(0);
957 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
958 		type = (Type) thrownTypes.get(1);
959 		verifyAnnotationOnType(type, new String[]{"@Marker2()"});
960 	}
test025()961 	public void test025() throws Exception {
962 		String contents =
963 				"interface I {}\n" +
964 				"interface J {}\n" +
965 				"interface K extends @Marker I, @Marker2 J {}\n" +
966 				"interface L {}\n" +
967 				"public class X implements @Marker2 K, @Marker L {\n" +
968 				"}\n" +
969 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
970 				"@interface Marker {}\n" +
971 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
972 				"@interface Marker2 {}\n";
973 
974 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
975 		ASTNode node = buildAST(contents, this.workingCopy);
976 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
977 		CompilationUnit compilationUnit = (CompilationUnit) node;
978 		assertProblemsSize(compilationUnit, 0);
979 		List types = compilationUnit.types();
980 		assertEquals("Incorrect no of types", 7, types.size());
981 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(2);
982 		List interfaces = typeDecl.superInterfaceTypes();
983 		assertEquals("Incorrect no of super interfaces", 2, interfaces.size());
984 		verifyAnnotationOnType((Type) interfaces.get(0), new String[]{"@Marker()"});
985 		verifyAnnotationOnType((Type) interfaces.get(1), new String[]{"@Marker2()"});
986 
987 		typeDecl = (TypeDeclaration) types.get(4);
988 		interfaces = typeDecl.superInterfaceTypes();
989 		assertEquals("Incorrect no of super interfaces", 2, interfaces.size());
990 		verifyAnnotationOnType((Type) interfaces.get(0), new String[]{"@Marker2()"});
991 		verifyAnnotationOnType((Type) interfaces.get(1), new String[]{"@Marker()"});
992 	}
test026()993 	public void test026() throws Exception {
994 		String contents =
995 				"interface I {\n" +
996 				"    void foo(int x);\n" +
997 				"}\n" +
998 				"public class X  {\n" +
999 				"    public static void main(String [] args) {\n" +
1000 				"        I i = A.Y.@Marker Z ::foo;\n" +
1001 				"        i.foo(10); \n" +
1002 				"    }\n" +
1003 				"}\n" +
1004 				"class A {\n" +
1005 				"  static class Y {\n" +
1006 				"    static class Z {\n" +
1007 				"        public static void foo(int x) {\n" +
1008 				"	        System.out.println(x);\n" +
1009 				"        }\n" +
1010 				"    }\n" +
1011 				"  }\n" +
1012 				"}\n" +
1013 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1014 				"@interface Marker {}\n";
1015 
1016 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1017 		ASTNode node = buildAST(contents, this.workingCopy);
1018 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1019 		CompilationUnit compilationUnit = (CompilationUnit) node;
1020 		assertProblemsSize(compilationUnit, 0);
1021 		List types = compilationUnit.types();
1022 		assertEquals("Incorrect no of types", 4, types.size());
1023 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
1024 		MethodDeclaration method = typeDecl.getMethods()[0];
1025 		List statements = method.getBody().statements();
1026 
1027 		VariableDeclarationStatement stmt = (VariableDeclarationStatement) statements.get(0);
1028 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) stmt.fragments().get(0);
1029 		TypeMethodReference lambda = (TypeMethodReference) fragment.getInitializer();
1030 		Type type = lambda.getType();
1031 
1032 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
1033 	}
test027()1034 	public void test027() throws Exception {
1035 		String contents =
1036 				"interface I {\n" +
1037 				"    Y foo(int x);\n" +
1038 				"}\n" +
1039 				"public class X  {\n" +
1040 				"    class Z extends Y {\n" +
1041 				"        public Z(int x) {\n" +
1042 				"            super(x);\n" +
1043 				"        }\n" +
1044 				"    }\n" +
1045 				"    public static void main(String [] args) {\n" +
1046 				"        I i = @Marker W<@Marker2 Integer>::<@Marker3 String> new;\n" +
1047 				"    }\n" +
1048 				"}\n" +
1049 				"class W<T> extends Y {\n" +
1050 				"    public <C> W(T x) {\n" +
1051 				"        super(0);\n" +
1052 				"    }\n" +
1053 				"}\n" +
1054 				"class Y {\n" +
1055 				"    public Y(int x) {\n" +
1056 				"    }\n" +
1057 				"}\n" +
1058 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1059 				"@interface Marker {}\n" +
1060 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1061 				"@interface Marker2 {}\n" +
1062 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1063 				"@interface Marker3 {}\n";
1064 
1065 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1066 		ASTNode node = buildAST(contents, this.workingCopy);
1067 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1068 		CompilationUnit compilationUnit = (CompilationUnit) node;
1069 		assertProblemsSize(compilationUnit, 0);
1070 		List types = compilationUnit.types();
1071 		assertEquals("Incorrect no of types", 7, types.size());
1072 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
1073 		MethodDeclaration method = typeDecl.getMethods()[0];
1074 		List statements = method.getBody().statements();
1075 		VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(0);
1076 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) statement.fragments().get(0);
1077 		CreationReference lambda = (CreationReference) fragment.getInitializer();
1078 		Type type = lambda.getType();
1079 		verifyAnnotationOnType(type, new String[]{"@Marker()"});
1080 		ParameterizedType paramType = (ParameterizedType) type;
1081 		verifyAnnotationOnType((Type) paramType.typeArguments().get(0), new String[]{"@Marker2()"});
1082 		List typeArgs = lambda.typeArguments();
1083 		verifyAnnotationOnType((Type) typeArgs.get(0), new String[]{"@Marker3()"});
1084 	}
1085 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=418096
test028()1086 	public void test028() throws Exception {
1087 		String contents =
1088 				"public class X {\n" +
1089 				"    @TypeUseAnnotation(\"a\") String @TypeUseAnnotation(\"a1\") [] @TypeUseAnnotation(\"a2\") [] _field2 @TypeUseAnnotation(\"a3\") [], _field3 @TypeUseAnnotation(\"a4\") [][] = null;\n" +
1090 				"}" +
1091 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1092 				"@interface TypeUseAnnotation {\n" +
1093 				"	String value() default \"\";\n" +
1094 				"}\n";
1095 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1096 		ASTNode node = buildAST(contents, this.workingCopy);
1097 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1098 		CompilationUnit compilationUnit = (CompilationUnit) node;
1099 		assertProblemsSize(compilationUnit, 0);
1100 		List types = compilationUnit.types();
1101 		assertEquals("Incorrect no of types", 2, types.size());
1102 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1103 		FieldDeclaration[] fields = typeDecl.getFields();
1104 		assertEquals("Incorrect no of fields", 1, fields.length);
1105 		FieldDeclaration field = fields[0];
1106 		List fragments = field.fragments();
1107 		assertEquals("Incorrect no of fragments", 2, fragments.size());
1108 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
1109 		ITypeBinding binding = fragment.resolveBinding().getType();
1110 		verifyAnnotationsOnBinding(binding, new String[]{"@TypeUseAnnotation(value = a3)"});
1111 		verifyAnnotationsOnBinding(binding = binding.getComponentType(), new String[]{"@TypeUseAnnotation(value = a1)"});
1112 		verifyAnnotationsOnBinding(binding = binding.getComponentType(), new String[]{"@TypeUseAnnotation(value = a2)"});
1113 		verifyAnnotationsOnBinding(binding = binding.getComponentType(), new String[]{"@TypeUseAnnotation(value = a)"});
1114 		fragment = (VariableDeclarationFragment) fragments.get(1);
1115 		binding = fragment.resolveBinding().getType();
1116 		verifyAnnotationsOnBinding(binding, new String[]{"@TypeUseAnnotation(value = a4)"});
1117 		verifyAnnotationsOnBinding(binding = binding.getComponentType(), new String[]{});
1118 		verifyAnnotationsOnBinding(binding = binding.getComponentType(), new String[]{"@TypeUseAnnotation(value = a1)"});
1119 		verifyAnnotationsOnBinding(binding = binding.getComponentType(), new String[]{"@TypeUseAnnotation(value = a2)"});
1120 		verifyAnnotationsOnBinding(binding = binding.getComponentType(), new String[]{"@TypeUseAnnotation(value = a)"});
1121 	}
1122 
testAnnotatedBinaryType()1123 	public void testAnnotatedBinaryType() throws CoreException, IOException {
1124 		String jarName = "TypeBindingTests308.jar";
1125 		String srcName = "TypeBindingTests308_src.zip";
1126 		IJavaProject javaProject = getJavaProject("Converter18");
1127 		try {
1128 			String[] pathAndContents = new String[] {
1129 				"Outer.java",
1130 				"public class Outer  {\n" +
1131 				"	class Middle {\n" +
1132 				"		class Inner {\n" +
1133 				"		}\n" +
1134 				"	}\n" +
1135 				"	public @Marker(\"Outer\") Outer.@Marker (\"Middle\") Middle.@Marker(\"Inner\") Inner omi;\n" +
1136 				"}\n" +
1137 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1138 				"@interface Marker {\n" +
1139 				"	String value() default \"GOK\";\n" +
1140 				"}\n"
1141 			};
1142 
1143 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1144 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1145 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1146 
1147 			String contents =
1148 					"public class X {\n" +
1149 					"    void foo(Outer o) {\n" +
1150 					"        o.omi = null;\n" +
1151 					"    }\n" +
1152 					"}";
1153 
1154 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1155 			ASTNode node = buildAST(contents, this.workingCopy);
1156 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1157 			CompilationUnit compilationUnit = (CompilationUnit) node;
1158 			assertProblemsSize(compilationUnit, 0);
1159 			List types = compilationUnit.types();
1160 			assertEquals("Incorrect no of types", 1, types.size());
1161 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1162 
1163 			MethodDeclaration[] methods = typeDecl.getMethods();
1164 			assertEquals("Incorrect no of methods", 1, methods.length);
1165 			MethodDeclaration method = methods[0];
1166 			Block body = method.getBody();
1167 			ExpressionStatement stmt = (ExpressionStatement) body.statements().get(0);
1168 			Assignment assignment = (Assignment) stmt.getExpression();
1169 			Expression left = assignment.getLeftHandSide();
1170 			ITypeBinding type = left.resolveTypeBinding();
1171 			assertEquals("Wrong type", "@Marker((String)\"Outer\") Outer.@Marker((String)\"Middle\") Middle.@Marker((String)\"Inner\") Inner", type.toString());
1172 		} finally {
1173 			removeLibrary(javaProject, jarName, srcName);
1174 		}
1175 	}
testAnnotatedBinaryType2()1176 	public void testAnnotatedBinaryType2() throws CoreException, IOException {
1177 		String jarName = "TypeBindingTests308.jar";
1178 		String srcName = "TypeBindingTests308_src.zip";
1179 		IJavaProject javaProject = getJavaProject("Converter18");
1180 		try {
1181 			String[] pathAndContents = new String[] {
1182 				"Outer.java",
1183 				"public class Outer  {\n" +
1184 				"	class Middle {\n" +
1185 				"		class Inner {\n" +
1186 				"		}\n" +
1187 				"	}\n" +
1188 				"	public @Marker(\"Outer\") Outer.@Marker (\"Middle\") Middle.@Marker(\"Inner\") Inner @Marker(\"Prefix []\") [] omi @Marker(\"Extended []\") [];\n" +
1189 				"}\n" +
1190 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1191 				"@interface Marker {\n" +
1192 				"	String value() default \"GOK\";\n" +
1193 				"}\n"
1194 			};
1195 
1196 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1197 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1198 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1199 
1200 			String contents =
1201 					"public class X {\n" +
1202 					"    void foo(Outer o) {\n" +
1203 					"        o.omi = null;\n" +
1204 					"    }\n" +
1205 					"}";
1206 
1207 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1208 			ASTNode node = buildAST(contents, this.workingCopy);
1209 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1210 			CompilationUnit compilationUnit = (CompilationUnit) node;
1211 			assertProblemsSize(compilationUnit, 0);
1212 			List types = compilationUnit.types();
1213 			assertEquals("Incorrect no of types", 1, types.size());
1214 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1215 
1216 			MethodDeclaration[] methods = typeDecl.getMethods();
1217 			assertEquals("Incorrect no of methods", 1, methods.length);
1218 			MethodDeclaration method = methods[0];
1219 			Block body = method.getBody();
1220 			ExpressionStatement stmt = (ExpressionStatement) body.statements().get(0);
1221 			Assignment assignment = (Assignment) stmt.getExpression();
1222 			Expression left = assignment.getLeftHandSide();
1223 			ITypeBinding type = left.resolveTypeBinding();
1224 			assertEquals("Wrong type", "@Marker((String)\"Outer\") Outer.@Marker((String)\"Middle\") Middle.@Marker((String)\"Inner\") Inner @Marker((String)\"Extended []\") [] @Marker((String)\"Prefix []\") []", type.toString());
1225 		} finally {
1226 			removeLibrary(javaProject, jarName, srcName);
1227 		}
1228 	}
testAnnotatedBinaryType3()1229 	public void testAnnotatedBinaryType3() throws CoreException, IOException {
1230 		String jarName = "TypeBindingTests308.jar";
1231 		String srcName = "TypeBindingTests308_src.zip";
1232 		final IJavaProject javaProject = getJavaProject("Converter18");
1233 		try {
1234 			String[] pathAndContents = new String[] {
1235 				"Outer.java",
1236 				"public class Outer<K>  {\n" +
1237 				"	class Inner<P> {\n" +
1238 				"	}\n" +
1239 				"	public @T(1) Outer<@T(2) String>.@T(3) Inner<@T(4) Integer> @T(5) [] omi @T(6) [];\n" +
1240 				"}\n" +
1241 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1242 				"@interface T {\n" +
1243 				"	int value();\n" +
1244 				"}\n"
1245 			};
1246 
1247 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1248 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1249 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1250 
1251 			String contents =
1252 					"public class X {\n" +
1253 					"    void foo(Outer<String> o) {\n" +
1254 					"        o.omi = null;\n" +
1255 					"    }\n" +
1256 					"}";
1257 
1258 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1259 			ASTNode node = buildAST(contents, this.workingCopy);
1260 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1261 			CompilationUnit compilationUnit = (CompilationUnit) node;
1262 			assertProblemsSize(compilationUnit, 0);
1263 			List types = compilationUnit.types();
1264 			assertEquals("Incorrect no of types", 1, types.size());
1265 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1266 
1267 			MethodDeclaration[] methods = typeDecl.getMethods();
1268 			assertEquals("Incorrect no of methods", 1, methods.length);
1269 			MethodDeclaration method = methods[0];
1270 			Block body = method.getBody();
1271 			ExpressionStatement stmt = (ExpressionStatement) body.statements().get(0);
1272 			Assignment assignment = (Assignment) stmt.getExpression();
1273 			Expression left = assignment.getLeftHandSide();
1274 			ITypeBinding type = left.resolveTypeBinding();
1275 			assertEquals("Wrong type", "@T((int)1) Outer<@T((int)2) String>.@T((int)3) Inner<@T((int)4) Integer> @T((int)6) [] @T((int)5) []", type.toString());
1276 		} finally {
1277 			removeLibrary(javaProject, jarName, srcName);
1278 		}
1279 	}
1280 
testAnnotatedBinaryType4()1281 	public void testAnnotatedBinaryType4() throws CoreException, IOException {
1282 		String jarName = "TypeBindingTests308.jar";
1283 		String srcName = "TypeBindingTests308_src.zip";
1284 		final IJavaProject javaProject = getJavaProject("Converter18");
1285 		try {
1286 			String[] pathAndContents = new String[] {
1287 				"Outer.java",
1288 				"public class Outer<K>  {\n" +
1289 				"	class Inner<P> {\n" +
1290 				"	}\n" +
1291 				"	@T(1) K @T(2) [] f @T(3) [];\n" +
1292 				"}\n" +
1293 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1294 				"@interface T {\n" +
1295 				"	int value();\n" +
1296 				"}\n"
1297 			};
1298 
1299 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1300 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1301 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1302 
1303 			String contents =
1304 					"public class X {\n" +
1305 					"    void foo(Outer<String> o) {\n" +
1306 					"        o.f = null;\n" +
1307 					"    }\n" +
1308 					"}";
1309 
1310 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1311 			ASTNode node = buildAST(contents, this.workingCopy);
1312 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1313 			CompilationUnit compilationUnit = (CompilationUnit) node;
1314 			assertProblemsSize(compilationUnit, 0);
1315 			List types = compilationUnit.types();
1316 			assertEquals("Incorrect no of types", 1, types.size());
1317 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1318 
1319 			MethodDeclaration[] methods = typeDecl.getMethods();
1320 			assertEquals("Incorrect no of methods", 1, methods.length);
1321 			MethodDeclaration method = methods[0];
1322 			Block body = method.getBody();
1323 			ExpressionStatement stmt = (ExpressionStatement) body.statements().get(0);
1324 			Assignment assignment = (Assignment) stmt.getExpression();
1325 			Expression left = assignment.getLeftHandSide();
1326 			ITypeBinding type = left.resolveTypeBinding();
1327 			assertEquals("Wrong type", "@T((int)1) String @T((int)3) [] @T((int)2) []", type.toString());
1328 		} finally {
1329 			removeLibrary(javaProject, jarName, srcName);
1330 		}
1331 	}
testAnnotatedBinaryType5()1332 	public void testAnnotatedBinaryType5() throws CoreException, IOException {
1333 		String jarName = "TypeBindingTests308.jar";
1334 		String srcName = "TypeBindingTests308_src.zip";
1335 		final IJavaProject javaProject = getJavaProject("Converter18");
1336 		try {
1337 			String[] pathAndContents = new String[] {
1338 				"Outer.java",
1339 				"public class Outer<K>  {\n" +
1340 				"	class Inner<P> {\n" +
1341 				"	}\n" +
1342 				"	@T(1) Outer<@T(2) ? extends @T(3) String>.@T(4) Inner<@T(5) ? super @T(6) Integer> @T(7) [] f @T(8) [];\n" +
1343 				"}\n" +
1344 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1345 				"@interface T {\n" +
1346 				"	int value();\n" +
1347 				"}\n"
1348 			};
1349 
1350 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1351 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1352 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1353 
1354 			String contents =
1355 					"public class X {\n" +
1356 					"    void foo(Outer<String> o) {\n" +
1357 					"        o.f = null;\n" +
1358 					"    }\n" +
1359 					"}";
1360 
1361 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1362 			ASTNode node = buildAST(contents, this.workingCopy);
1363 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1364 			CompilationUnit compilationUnit = (CompilationUnit) node;
1365 			assertProblemsSize(compilationUnit, 0);
1366 			List types = compilationUnit.types();
1367 			assertEquals("Incorrect no of types", 1, types.size());
1368 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1369 
1370 			MethodDeclaration[] methods = typeDecl.getMethods();
1371 			assertEquals("Incorrect no of methods", 1, methods.length);
1372 			MethodDeclaration method = methods[0];
1373 			Block body = method.getBody();
1374 			ExpressionStatement stmt = (ExpressionStatement) body.statements().get(0);
1375 			Assignment assignment = (Assignment) stmt.getExpression();
1376 			Expression left = assignment.getLeftHandSide();
1377 			ITypeBinding type = left.resolveTypeBinding();
1378 			assertEquals("Wrong type", "@T((int)1) Outer<@T((int)2) ? extends @T((int)3) String>.@T((int)4) Inner<@T((int)5) ? super @T((int)6) Integer> @T((int)8) [] @T((int)7) []", type.toString());
1379 		} finally {
1380 			removeLibrary(javaProject, jarName, srcName);
1381 		}
1382 	}
testAnnotatedBinaryType6()1383 	public void testAnnotatedBinaryType6() throws CoreException, IOException {
1384 		String jarName = "TypeBindingTests308.jar";
1385 		String srcName = "TypeBindingTests308_src.zip";
1386 		final IJavaProject javaProject = getJavaProject("Converter18");
1387 		try {
1388 			String[] pathAndContents = new String[] {
1389 				"Outer.java",
1390 				"public class Outer<K>  {\n" +
1391 				"	class Inner<P> {\n" +
1392 				"	}\n" +
1393 				"	@T(1) Outer.@T(2) Inner @T(3) [] f @T(4) [];\n" +
1394 				"}\n" +
1395 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1396 				"@interface T {\n" +
1397 				"	int value();\n" +
1398 				"}\n"
1399 			};
1400 
1401 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1402 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1403 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1404 
1405 			String contents =
1406 					"public class X {\n" +
1407 					"    void foo(Outer<String> o) {\n" +
1408 					"        o.f = null;\n" +
1409 					"    }\n" +
1410 					"}";
1411 
1412 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1413 			ASTNode node = buildAST(contents, this.workingCopy);
1414 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1415 			CompilationUnit compilationUnit = (CompilationUnit) node;
1416 			assertProblemsSize(compilationUnit, 0);
1417 			List types = compilationUnit.types();
1418 			assertEquals("Incorrect no of types", 1, types.size());
1419 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1420 
1421 			MethodDeclaration[] methods = typeDecl.getMethods();
1422 			assertEquals("Incorrect no of methods", 1, methods.length);
1423 			MethodDeclaration method = methods[0];
1424 			Block body = method.getBody();
1425 			ExpressionStatement stmt = (ExpressionStatement) body.statements().get(0);
1426 			Assignment assignment = (Assignment) stmt.getExpression();
1427 			Expression left = assignment.getLeftHandSide();
1428 			ITypeBinding type = left.resolveTypeBinding();
1429 			assertEquals("Wrong type", "@T((int)1) Outer#RAW.@T((int)2) Inner#RAW @T((int)4) [] @T((int)3) []", type.toString());
1430 		} finally {
1431 			removeLibrary(javaProject, jarName, srcName);
1432 		}
1433 	}
testIntersectionCastType()1434 	public void testIntersectionCastType() throws CoreException, IOException {
1435 		String contents =
1436 				"import java.lang.annotation.ElementType;\n" +
1437 						"import java.lang.annotation.Target;\n" +
1438 						"@Target(ElementType.TYPE_USE)\n" +
1439 						"@interface T1 {\n" +
1440 						"}\n" +
1441 						"@Target(ElementType.TYPE_USE)\n" +
1442 						"@interface T2 {\n" +
1443 						"}\n" +
1444 						"@Target(ElementType.TYPE_USE)\n" +
1445 						"@interface T3 {\n" +
1446 						"}\n" +
1447 						"public class X {\n" +
1448 						"	Object o = (@T1 Object & @T2 Runnable & java.io.@T3 Serializable) null;\n" +
1449 						"	Object p = (@T1 Object & @T2 Runnable & java.io.@T3 Serializable) null;\n" +
1450 						"}\n";
1451 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1452 		ASTNode node = buildAST(contents, this.workingCopy);
1453 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1454 		CompilationUnit compilationUnit = (CompilationUnit) node;
1455 		assertProblemsSize(compilationUnit, 0);
1456 		List types = compilationUnit.types();
1457 		assertEquals("Incorrect no of types", 4, types.size());
1458 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(3);
1459 		FieldDeclaration[] fields = typeDecl.getFields();
1460 		assertEquals("Incorrect no of fields", 2, fields.length);
1461 		FieldDeclaration field = fields[0];
1462 		List fragments = field.fragments();
1463 		assertEquals("Incorrect no of fragments", 1, fragments.size());
1464 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
1465 		CastExpression cast = (CastExpression) fragment.getInitializer();
1466 		Type castType = cast.getType();
1467 		ITypeBinding binding1 = castType.resolveBinding();
1468 		assertEquals("Wrong annotations", "@T1 Object & @T2 Runnable & @T3 Serializable", binding1.toString());
1469 
1470 		field = fields[1];
1471 		fragments = field.fragments();
1472 		assertEquals("Incorrect no of fragments", 1, fragments.size());
1473 		fragment = (VariableDeclarationFragment) fragments.get(0);
1474 		cast = (CastExpression) fragment.getInitializer();
1475 		castType = cast.getType();
1476 		ITypeBinding binding2 = castType.resolveBinding();
1477 		assertEquals("Wrong annotations", "@T1 Object & @T2 Runnable & @T3 Serializable", binding2.toString());
1478 		assertSame("Should be equal", binding1, binding2);
1479 	}
testMemberType()1480 	public void testMemberType() throws CoreException, IOException {
1481 		String jarName = "TypeBindingTests308.jar";
1482 		String srcName = "TypeBindingTests308_src.zip";
1483 		final IJavaProject javaProject = getJavaProject("Converter18");
1484 		try {
1485 			String[] pathAndContents = new String[] {
1486 				"Outer.java",
1487 				"public class Outer  {\n" +
1488 				"	class Inner {\n" +
1489 				"	}\n" +
1490 				"}\n"
1491 			};
1492 
1493 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1494 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1495 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1496 
1497 			String contents =
1498 					"public class X {\n" +
1499 					"    void foo(@T Outer o) {\n" +
1500 					"    }\n" +
1501 					"}\n" +
1502 					"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1503 					"@interface T {\n" +
1504 					"}\n";
1505 
1506 
1507 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1508 			ASTNode node = buildAST(contents, this.workingCopy);
1509 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1510 			CompilationUnit compilationUnit = (CompilationUnit) node;
1511 			assertProblemsSize(compilationUnit, 0);
1512 			List types = compilationUnit.types();
1513 			assertEquals("Incorrect no of types", 2, types.size());
1514 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1515 
1516 			MethodDeclaration[] methods = typeDecl.getMethods();
1517 			assertEquals("Incorrect no of methods", 1, methods.length);
1518 			MethodDeclaration method = methods[0];
1519 			List parameters = method.parameters();
1520 			SingleVariableDeclaration parameter = (SingleVariableDeclaration) parameters.get(0);
1521 			ITypeBinding binding = parameter.resolveBinding().getType();
1522 			assertEquals("@T Outer", binding.toString());
1523 			ITypeBinding [] memberTypes = binding.getDeclaredTypes();
1524 			assertEquals("Incorrect no of types", 1, memberTypes.length);
1525 			assertEquals("Incorrect no of types", "@T Outer.Inner", memberTypes[0].toString());
1526 			assertEquals("Incorrect no of types", "@T Outer", memberTypes[0].getDeclaringClass().toString());
1527 		} finally {
1528 			removeLibrary(javaProject, jarName, srcName);
1529 		}
1530 	}
testMemberType2()1531 	public void testMemberType2() throws CoreException, IOException {
1532 		String jarName = "TypeBindingTests308.jar";
1533 		String srcName = "TypeBindingTests308_src.zip";
1534 		final IJavaProject javaProject = getJavaProject("Converter18");
1535 		try {
1536 			String[] pathAndContents = new String[] {
1537 				"Outer.java",
1538 				"public class Outer  {\n" +
1539 				"    @T Outer f;\n"+
1540 				"}\n" +
1541 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1542 				"@interface T {\n" +
1543 				"}\n"
1544 			};
1545 
1546 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1547 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1548 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1549 
1550 			String contents =
1551 					"public class X {\n" +
1552 					"    void foo(Outer o) {\n" +
1553 					"		o.f = null;\n" +
1554 					"    }\n" +
1555 					"}\n";
1556 
1557 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1558 			ASTNode node = buildAST(contents, this.workingCopy);
1559 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1560 			CompilationUnit compilationUnit = (CompilationUnit) node;
1561 			assertProblemsSize(compilationUnit, 0);
1562 			List types = compilationUnit.types();
1563 			assertEquals("Incorrect no of types", 1, types.size());
1564 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1565 
1566 			MethodDeclaration[] methods = typeDecl.getMethods();
1567 			assertEquals("Incorrect no of methods", 1, methods.length);
1568 			MethodDeclaration method = methods[0];
1569 			Block body = method.getBody();
1570 			ExpressionStatement stmt = (ExpressionStatement) body.statements().get(0);
1571 			Assignment assignment = (Assignment) stmt.getExpression();
1572 			Expression left = assignment.getLeftHandSide();
1573 			ITypeBinding type = left.resolveTypeBinding();
1574 			assertEquals("Wrong type", "@T Outer", type.toString());
1575 			IVariableBinding[] declaredFields = type.getDeclaredFields();
1576 			assertEquals("Wrong type", 1, declaredFields.length);
1577 			assertEquals("Wrong type", "@T Outer", declaredFields[0].getType().toString());
1578 		} finally {
1579 			removeLibrary(javaProject, jarName, srcName);
1580 		}
1581 	}
testBinarySuperInterfaces()1582 	public void testBinarySuperInterfaces() throws CoreException, IOException {
1583 		String jarName = "TypeBindingTests308.jar";
1584 		String srcName = "TypeBindingTests308_src.zip";
1585 		final IJavaProject javaProject = getJavaProject("Converter18");
1586 		try {
1587 			String[] pathAndContents = new String[] {
1588 				"Y.java",
1589 				"import java.lang.annotation.ElementType;\n" +
1590 				"import java.lang.annotation.Target;\n" +
1591 				"@Target(ElementType.TYPE_USE)\n" +
1592 				"@interface T1 {\n" +
1593 				"}\n" +
1594 				"public abstract class Y implements Comparable<@T1 Y>{  \n" +
1595 				"}\n"
1596 			};
1597 
1598 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1599 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1600 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1601 
1602 			String contents =
1603 					"public class X {\n" +
1604 					"    void foo(Y y) {\n" +
1605 					"    }\n" +
1606 					"}\n";
1607 
1608 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1609 			ASTNode node = buildAST(contents, this.workingCopy);
1610 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1611 			CompilationUnit compilationUnit = (CompilationUnit) node;
1612 			assertProblemsSize(compilationUnit, 0);
1613 			List types = compilationUnit.types();
1614 			assertEquals("Incorrect no of types", 1, types.size());
1615 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1616 
1617 			MethodDeclaration[] methods = typeDecl.getMethods();
1618 			assertEquals("Incorrect no of methods", 1, methods.length);
1619 			MethodDeclaration method = methods[0];
1620 			List parameters = method.parameters();
1621 			SingleVariableDeclaration parameter = (SingleVariableDeclaration) parameters.get(0);
1622 			ITypeBinding binding = parameter.resolveBinding().getType();
1623 			ITypeBinding binding2 = binding.getInterfaces()[0].getTypeArguments()[0];
1624 			assertEquals("Wrong type", "@T1 Y", binding2.toString());
1625 			assertEquals("Wrong type", "Comparable<@T1 Y>", binding2.getInterfaces()[0].toString());
1626 		} finally {
1627 			removeLibrary(javaProject, jarName, srcName);
1628 		}
1629 	}
testMemberTypeSource()1630 	public void testMemberTypeSource() throws CoreException, IOException {
1631 		String contents =
1632 				"import java.lang.annotation.ElementType;\n" +
1633 				"import java.lang.annotation.Target;\n" +
1634 				"@Target(ElementType.TYPE_USE)\n" +
1635 				"@interface T {\n" +
1636 				"}\n" +
1637 				"public class X {\n" +
1638 				"    class Y {}\n" +
1639 				"    @T X.Y xy;\n" +
1640 				"}\n";
1641 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1642 		ASTNode node = buildAST(contents, this.workingCopy);
1643 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1644 		CompilationUnit compilationUnit = (CompilationUnit) node;
1645 		assertProblemsSize(compilationUnit, 0);
1646 		List types = compilationUnit.types();
1647 		assertEquals("Incorrect no of types", 2, types.size());
1648 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
1649 		FieldDeclaration[] fields = typeDecl.getFields();
1650 		assertEquals("Incorrect no of fields", 1, fields.length);
1651 		FieldDeclaration field = fields[0];
1652 		ITypeBinding binding = field.getType().resolveBinding();
1653 		assertEquals("Wrong Type", "@T X", (binding = binding.getDeclaringClass()).toString());
1654 		assertEquals("Wrong Type", "@T X.Y", (binding = binding.getDeclaredTypes()[0]).toString());
1655 	}
testAnnotatedTypeIdentity()1656 	public void testAnnotatedTypeIdentity() throws CoreException, IOException {
1657 		String contents =
1658 				"import java.lang.annotation.ElementType;\n" +
1659 				"import java.lang.annotation.Target;\n" +
1660 				"import java.util.List;\n" +
1661 				"@Target(ElementType.TYPE_USE)\n" +
1662 				"@interface T {\n" +
1663 				"}\n" +
1664 				"public class X {\n" +
1665 				"    @T List<@T String> ls = (@T List<@T String>) null;\n" +
1666 				"}\n";
1667 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1668 		ASTNode node = buildAST(contents, this.workingCopy);
1669 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1670 		CompilationUnit compilationUnit = (CompilationUnit) node;
1671 		assertProblemsSize(compilationUnit, 0);
1672 		List types = compilationUnit.types();
1673 		assertEquals("Incorrect no of types", 2, types.size());
1674 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
1675 		FieldDeclaration[] fields = typeDecl.getFields();
1676 		assertEquals("Incorrect no of fields", 1, fields.length);
1677 		FieldDeclaration field = fields[0];
1678 		ITypeBinding binding = field.getType().resolveBinding();
1679 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0);
1680 		CastExpression cast = (CastExpression) fragment.getInitializer();
1681 		ITypeBinding binding2 = cast.resolveTypeBinding();
1682 		assertEquals("Wrong Type", "@T List<@T String>", binding.toString());
1683 		assertSame("not Equal", binding, binding2);
1684 	}
testAnnotatedTypeIdentity2()1685 	public void testAnnotatedTypeIdentity2() throws CoreException, IOException {
1686 		String jarName = "TypeBindingTests308.jar";
1687 		String srcName = "TypeBindingTests308_src.zip";
1688 		final IJavaProject javaProject = getJavaProject("Converter18");
1689 		try {
1690 			String[] pathAndContents = new String[] {
1691 				"Outer.java",
1692 				"public class Outer  {\n" +
1693 				"	Outer @T [] f @T [];\n" +
1694 				"}\n" +
1695 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1696 				"@interface T {\n" +
1697 				"	int value() default 10;\n" +
1698 				"}\n"
1699 			};
1700 
1701 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1702 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1703 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1704 
1705 			String contents =
1706 					"public class X {\n" +
1707 					"	 Outer @T [] f @T [];\n" +
1708 					"    void foo(Outer o) {\n" +
1709 					"        o.f = this.f;\n" +
1710 					"    }\n" +
1711 					"}";
1712 
1713 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1714 			ASTNode node = buildAST(contents, this.workingCopy);
1715 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1716 			CompilationUnit compilationUnit = (CompilationUnit) node;
1717 			assertProblemsSize(compilationUnit, 0);
1718 			List types = compilationUnit.types();
1719 			assertEquals("Incorrect no of types", 1, types.size());
1720 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1721 
1722 			MethodDeclaration[] methods = typeDecl.getMethods();
1723 			assertEquals("Incorrect no of methods", 1, methods.length);
1724 			MethodDeclaration method = methods[0];
1725 			Block body = method.getBody();
1726 			ExpressionStatement stmt = (ExpressionStatement) body.statements().get(0);
1727 			Assignment assignment = (Assignment) stmt.getExpression();
1728 			Expression left = assignment.getLeftHandSide();
1729 			ITypeBinding type = left.resolveTypeBinding();
1730 			Expression right = assignment.getRightHandSide();
1731 			ITypeBinding type2 = right.resolveTypeBinding();
1732 			assertEquals("Wrong type", "Outer @T [] @T []", type.toString());
1733 			assertSame ("Should be same", type, type2);
1734 		} finally {
1735 			removeLibrary(javaProject, jarName, srcName);
1736 		}
1737 	}
testAnnotatedTypeIdentity3()1738 	public void testAnnotatedTypeIdentity3() throws CoreException, IOException {
1739 		String jarName = "TypeBindingTests308.jar";
1740 		String srcName = "TypeBindingTests308_src.zip";
1741 		final IJavaProject javaProject = getJavaProject("Converter18");
1742 		try {
1743 			String[] pathAndContents = new String[] {
1744 				"Outer.java",
1745 				"import java.util.List;\n" +
1746 				"public class Outer  {\n" +
1747 				"	@T List<@T String> ls;\n" +
1748 				"}\n" +
1749 				"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
1750 				"@interface T {\n" +
1751 				"	int value() default 10;\n" +
1752 				"}\n"
1753 			};
1754 
1755 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1756 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1757 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1758 
1759 			String contents =
1760 					"import java.util.List;\n" +
1761 					"public class X {\n" +
1762 					"	@T List<@T String> ls;\n" +
1763 					"    void foo(Outer o) {\n" +
1764 					"        o.ls = this.ls;\n" +
1765 					"    }\n" +
1766 					"}";
1767 
1768 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1769 			ASTNode node = buildAST(contents, this.workingCopy);
1770 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1771 			CompilationUnit compilationUnit = (CompilationUnit) node;
1772 			assertProblemsSize(compilationUnit, 0);
1773 			List types = compilationUnit.types();
1774 			assertEquals("Incorrect no of types", 1, types.size());
1775 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
1776 
1777 			MethodDeclaration[] methods = typeDecl.getMethods();
1778 			assertEquals("Incorrect no of methods", 1, methods.length);
1779 			MethodDeclaration method = methods[0];
1780 			Block body = method.getBody();
1781 			ExpressionStatement stmt = (ExpressionStatement) body.statements().get(0);
1782 			Assignment assignment = (Assignment) stmt.getExpression();
1783 			Expression left = assignment.getLeftHandSide();
1784 			ITypeBinding type = left.resolveTypeBinding();
1785 			Expression right = assignment.getRightHandSide();
1786 			ITypeBinding type2 = right.resolveTypeBinding();
1787 			assertEquals("Wrong type", "@T List<@T String>", type.toString());
1788 			assertSame ("Should be same", type, type2);
1789 		} finally {
1790 			removeLibrary(javaProject, jarName, srcName);
1791 		}
1792 	}
testHybridAnnotations()1793 	public void testHybridAnnotations() throws CoreException, IOException {
1794 		String contents =
1795 				"import java.lang.annotation.ElementType;\n" +
1796 				"import java.lang.annotation.Target;\n" +
1797 				"@interface A {\n" +
1798 				"}\n" +
1799 				"@Target(ElementType.TYPE_USE)\n" +
1800 				"@interface AUse {\n" +
1801 				"}\n" +
1802 				"@Target({ElementType.TYPE_USE, ElementType.PARAMETER})\n" +
1803 				"@interface AUseParameter {\n" +
1804 				"}\n" +
1805 				"@Target({ElementType.TYPE_USE, ElementType.LOCAL_VARIABLE})\n" +
1806 				"@interface AUseLocal {\n" +
1807 				"}\n" +
1808 				"@Target({ElementType.PARAMETER})\n" +
1809 				"@interface AParameter {\n" +
1810 				"}\n" +
1811 				"public class X {    \n" +
1812 				"	void foo(@A @AUse @AUseParameter @AUseLocal @AParameter X x) {\n" +
1813 				"	}\n" +
1814 				"}\n";
1815 
1816 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1817 		ASTNode node = buildAST(contents, this.workingCopy);
1818 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1819 		CompilationUnit compilationUnit = (CompilationUnit) node;
1820 		assertProblemsSize(compilationUnit, 0);
1821 		List types = compilationUnit.types();
1822 		assertEquals("Incorrect no of types", 6, types.size());
1823 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(5);
1824 		MethodDeclaration[] methods = typeDecl.getMethods();
1825 		assertEquals("Incorrect no of methods", 1, methods.length);
1826 		MethodDeclaration method = methods[0];
1827 		SingleVariableDeclaration parameter = (SingleVariableDeclaration) method.parameters().get(0);
1828 		IVariableBinding parameterBinding = parameter.resolveBinding();
1829 		verifyAnnotationsOnBinding(parameterBinding, new String [] { "@A()", "@AUseParameter()", "@AParameter()" });
1830 		ITypeBinding type = parameterBinding.getType();
1831 		verifyAnnotationsOnBinding(type, new String [] { "@AUse()", "@AUseParameter()", "@AUseLocal()" });
1832 	}
testGenericMethod()1833 	public void testGenericMethod() throws CoreException, IOException {
1834 		String contents =
1835 				"import java.lang.annotation.Annotation;\n" +
1836 				"import java.lang.annotation.ElementType;\n" +
1837 				"import java.lang.annotation.Target;\n" +
1838 				"@Target(ElementType.TYPE_USE)\n" +
1839 				"@interface T {\n" +
1840 				"}\n" +
1841 				"public class X { \n" +
1842 				"	<N extends Annotation> @T String f(N a) {\n" +
1843 				"		return null;\n" +
1844 				"	}\n" +
1845 				"}\n";
1846 
1847 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1848 		ASTNode node = buildAST(contents, this.workingCopy);
1849 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1850 		CompilationUnit compilationUnit = (CompilationUnit) node;
1851 		assertProblemsSize(compilationUnit, 0);
1852 		List types = compilationUnit.types();
1853 		assertEquals("Incorrect no of types", 2, types.size());
1854 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
1855 		MethodDeclaration[] methods = typeDecl.getMethods();
1856 		assertEquals("Incorrect no of methods", 1, methods.length);
1857 		MethodDeclaration method = methods[0];
1858 		Type returnType = method.getReturnType2();
1859 		ITypeBinding type = returnType.resolveBinding();
1860 		verifyAnnotationsOnBinding(type, new String [] { "@T()" });
1861 	}
testHybridAnnotations2()1862 	public void testHybridAnnotations2() throws CoreException, IOException {
1863 		String contents =
1864 				"import java.lang.annotation.Target;\n" +
1865 				"import java.lang.annotation.ElementType;\n" +
1866 				"@Target({ ElementType.TYPE_USE, ElementType.METHOD })\n" +
1867 				"@interface SillyAnnotation {  }\n" +
1868 				"public class X {\n" +
1869 				"    @SillyAnnotation\n" +
1870 				"    X(@SillyAnnotation int x) {\n" +
1871 				"    }\n" +
1872 				"    @SillyAnnotation\n" +
1873 				"    void foo(@SillyAnnotation int x) {\n" +
1874 				"    }\n" +
1875 				"    @SillyAnnotation\n" +
1876 				"    String goo(@SillyAnnotation int x) {\n" +
1877 				"	return null;\n" +
1878 				"    }\n" +
1879 				"    @SillyAnnotation\n" +
1880 				"    X field;\n" +
1881 				"}\n";
1882 
1883 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
1884 		ASTNode node = buildAST(contents, this.workingCopy);
1885 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
1886 		CompilationUnit compilationUnit = (CompilationUnit) node;
1887 		assertProblemsSize(compilationUnit, 0);
1888 		List types = compilationUnit.types();
1889 		assertEquals("Incorrect no of types", 2, types.size());
1890 
1891 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
1892 		MethodDeclaration[] methods = typeDecl.getMethods();
1893 		assertEquals("Incorrect no of methods", 3, methods.length);
1894 
1895 		MethodDeclaration method = methods[0];
1896 		List modifiers = method.modifiers();
1897 		int size = modifiers.size();
1898 		assertTrue("Should be just 1", size == 1);
1899 		MarkerAnnotation annotation = (MarkerAnnotation) modifiers.get(0);
1900 		assertEquals("Incorrect annotation", "@SillyAnnotation", annotation.toString());
1901 		SingleVariableDeclaration parameter = (SingleVariableDeclaration) method.parameters().get(0);
1902 	    IAnnotationBinding [] annotations = parameter.resolveBinding().getAnnotations();
1903 		assertTrue("should be 0", annotations == null || annotations.length == 0);
1904 		IAnnotationBinding [] typeAnnotations = parameter.getType().resolveBinding().getTypeAnnotations();
1905 		assertEquals("Incorrect annotation", "@SillyAnnotation()", typeAnnotations[0].toString());
1906 
1907 		method = methods[1];
1908 		modifiers = method.modifiers();
1909 		size = modifiers.size();
1910 		assertTrue("Should be just 1", size == 1);
1911 		annotation = (MarkerAnnotation) modifiers.get(0);
1912 		assertEquals("Incorrect annotation", "@SillyAnnotation", annotation.toString());
1913 		typeAnnotations = method.getReturnType2().resolveBinding().getTypeAnnotations();
1914 		assertTrue("Should be just 0", typeAnnotations.length == 0);
1915 		parameter = (SingleVariableDeclaration) method.parameters().get(0);
1916 	    annotations = parameter.resolveBinding().getAnnotations();
1917 		assertTrue("should be 0", annotations == null || annotations.length == 0);
1918 		typeAnnotations = parameter.getType().resolveBinding().getTypeAnnotations();
1919 		assertEquals("Incorrect annotation", "@SillyAnnotation()", typeAnnotations[0].toString());
1920 
1921 		method = methods[2];
1922 		modifiers = method.modifiers();
1923 		size = modifiers.size();
1924 		assertTrue("Should be just 1", size == 1);
1925 		annotation = (MarkerAnnotation) modifiers.get(0);
1926 		assertEquals("Incorrect annotation", "@SillyAnnotation", annotation.toString());
1927 		typeAnnotations = method.getReturnType2().resolveBinding().getTypeAnnotations();
1928 		assertTrue("Should be just 1", typeAnnotations.length == 1);
1929 		assertEquals("Incorrect annotation", "@SillyAnnotation()", typeAnnotations[0].toString());
1930 		parameter = (SingleVariableDeclaration) method.parameters().get(0);
1931 	    annotations = parameter.resolveBinding().getAnnotations();
1932 		assertTrue("should be 0", annotations == null || annotations.length == 0);
1933 		typeAnnotations = parameter.getType().resolveBinding().getTypeAnnotations();
1934 		assertEquals("Incorrect annotation", "@SillyAnnotation()", typeAnnotations[0].toString());
1935 
1936 		FieldDeclaration[] fields = typeDecl.getFields();
1937 		assertEquals("Incorrect no of fields", 1, fields.length);
1938 
1939 		FieldDeclaration field = fields[0];
1940 		modifiers = field.modifiers();
1941 		size = modifiers.size();
1942 		assertTrue("Should be just 1", size == 1);
1943 		annotation = (MarkerAnnotation) modifiers.get(0);
1944 		assertEquals("Incorrect annotation", "@SillyAnnotation", annotation.toString());
1945 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0);
1946 		annotations = fragment.resolveBinding().getAnnotations();
1947 		assertTrue("Incorrect annotation", annotations == null || annotations.length == 0);
1948 
1949 		typeAnnotations = field.getType().resolveBinding().getTypeAnnotations();
1950 		assertTrue("Should be just 1", typeAnnotations.length == 1);
1951 		assertEquals("Incorrect annotation", "@SillyAnnotation()", typeAnnotations[0].toString());
1952 	}
1953 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=419918, [1.8][compiler] Annotations are not restored from class files in a few situations.
testBinaryWithoutGenericSignature()1954 	public void testBinaryWithoutGenericSignature() throws CoreException, IOException {
1955 		String jarName = "TypeBindingTests308.jar";
1956 		String srcName = "TypeBindingTests308_src.zip";
1957 		final IJavaProject javaProject = getJavaProject("Converter18");
1958 		try {
1959 			String[] pathAndContents = new String[] {
1960 				"Superclass.java",
1961 				"import java.lang.annotation.ElementType;\n" +
1962 				"import java.lang.annotation.Target;\n" +
1963 				"@Target(ElementType.TYPE_USE)\n" +
1964 				"@interface T {\n" +
1965 				"	int value() default 0;\n" +
1966 				"}\n" +
1967 				"@T(1)\n" +
1968 				"public abstract class Superclass extends @T(2) Object implements @T(3) Runnable {\n" +
1969 				"	Object @T(4) [] field;\n" +
1970 				"	@T(5)\n" +
1971 				"	public String run(@T(6) Superclass this, Object @T(7) [] that) throws @T(8) NullPointerException {\n" +
1972 				"		return null;\n" +
1973 				"	}\n" +
1974 				"   @T(9)\n" +
1975 				"   Superclass () {}\n" +
1976 				"   @T(10)\n" +
1977 				"   class Inner {}\n" +
1978 				"}\n"
1979 			};
1980 
1981 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
1982 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
1983 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
1984 
1985 			String contents =
1986 					"@T(21)\n" +
1987 					"public abstract class X extends @T(22) Superclass implements @T(23) Runnable {\n" +
1988 					"	Object @T(24) [] field;\n" +
1989 					"	@T(25)\n" +
1990 					"	public String run(@T(26) X this, Object @T(27) [] that) throws @T(28) NullPointerException {\n" +
1991 					"		return null;\n" +
1992 					"	}\n" +
1993 					"   @T(29)\n" +
1994 					"   X() {\n" +
1995 		            "   }" +
1996 					"   @T(30)\n" +
1997 					"   class Inner {\n" +
1998 					"   }\n" +
1999 					"}\n";
2000 
2001 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
2002 			ASTNode node = buildAST(contents, this.workingCopy);
2003 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2004 			CompilationUnit compilationUnit = (CompilationUnit) node;
2005 			assertProblemsSize(compilationUnit, 0);
2006 			List types = compilationUnit.types();
2007 			assertEquals("Incorrect no of types", 1, types.size());
2008 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
2009 			ITypeBinding typeBinding = typeDecl.resolveBinding();
2010 			IAnnotationBinding[] annotations = typeBinding.getAnnotations();
2011 			assertTrue("Should be 1", annotations.length == 1);
2012 			assertEquals("Annotation mismatch", "@T(value = 21)", annotations[0].toString());
2013 			annotations = typeBinding.getSuperclass().getTypeAnnotations();
2014 			assertTrue("Should be 1", annotations.length == 1);
2015 			assertEquals("Annotation mismatch", "@T(value = 22)", annotations[0].toString());
2016 			annotations = typeBinding.getInterfaces()[0].getTypeAnnotations();
2017 			assertTrue("Should be 1", annotations.length == 1);
2018 			assertEquals("Annotation mismatch", "@T(value = 23)", annotations[0].toString());
2019 
2020 			annotations = typeDecl.getFields()[0].getType().resolveBinding().getTypeAnnotations();
2021 			assertTrue("Should be 1", annotations.length == 1);
2022 			assertEquals("Annotation mismatch", "@T(value = 24)", annotations[0].toString());
2023 
2024 			annotations = typeDecl.getMethods()[0].getReturnType2().resolveBinding().getTypeAnnotations();
2025 			assertTrue("Should be 1", annotations.length == 1);
2026 			assertEquals("Annotation mismatch", "@T(value = 25)", annotations[0].toString());
2027 
2028 			annotations = typeDecl.getMethods()[0].getReceiverType().resolveBinding().getTypeAnnotations();
2029 			assertTrue("Should be 1", annotations.length == 1);
2030 			assertEquals("Annotation mismatch", "@T(value = 26)", annotations[0].toString());
2031 
2032 			annotations = ((SingleVariableDeclaration) (typeDecl.getMethods()[0].parameters().get(0))).getType().resolveBinding().getTypeAnnotations();
2033 			assertTrue("Should be 1", annotations.length == 1);
2034 			assertEquals("Annotation mismatch", "@T(value = 27)", annotations[0].toString());
2035 
2036 			annotations = ((Type) typeDecl.getMethods()[0].thrownExceptionTypes().get(0)).resolveBinding().getTypeAnnotations();
2037 			assertTrue("Should be 1", annotations.length == 1);
2038 			assertEquals("Annotation mismatch", "@T(value = 28)", annotations[0].toString());
2039 
2040 			annotations = typeDecl.getMethods()[1].resolveBinding().getAnnotations();
2041 			assertTrue("Should be 0", annotations.length == 0);
2042 
2043 			annotations = typeDecl.getTypes()[0].resolveBinding().getAnnotations();
2044 			assertTrue("Should be 1", annotations.length == 1);
2045 			assertEquals("Annotation mismatch", "@T(value = 30)", annotations[0].toString());
2046 
2047 
2048 			// Check the same set of things for the binary type.
2049 			annotations = typeBinding.getSuperclass().getAnnotations();
2050 			assertTrue("Should be 1", annotations.length == 1);
2051 			assertEquals("Annotation mismatch", "@T(value = 1)", annotations[0].toString());
2052 
2053 			annotations = typeBinding.getSuperclass().getSuperclass().getTypeAnnotations();
2054 			assertTrue("Should be 1", annotations.length == 1);
2055 			assertEquals("Annotation mismatch", "@T(value = 2)", annotations[0].toString());
2056 
2057 			annotations = typeBinding.getSuperclass().getInterfaces()[0].getTypeAnnotations();
2058 			assertTrue("Should be 1", annotations.length == 1);
2059 			assertEquals("Annotation mismatch", "@T(value = 3)", annotations[0].toString());
2060 
2061 			annotations = typeBinding.getSuperclass().getDeclaredFields()[0].getType().getTypeAnnotations();
2062 			assertTrue("Should be 1", annotations.length == 1);
2063 			assertEquals("Annotation mismatch", "@T(value = 4)", annotations[0].toString());
2064 
2065 			// Skip past the constructor at [0]
2066 			annotations = typeBinding.getSuperclass().getDeclaredMethods()[1].getReturnType().getTypeAnnotations();
2067 			assertTrue("Should be 1", annotations.length == 1);
2068 			assertEquals("Annotation mismatch", "@T(value = 5)", annotations[0].toString());
2069 
2070 			annotations = typeBinding.getSuperclass().getDeclaredMethods()[1].getDeclaredReceiverType().getTypeAnnotations();
2071 			assertTrue("Should be 1", annotations.length == 1);
2072 			assertEquals("Annotation mismatch", "@T(value = 6)", annotations[0].toString());
2073 
2074 			annotations = typeBinding.getSuperclass().getDeclaredMethods()[1].getParameterTypes()[0].getTypeAnnotations();
2075 			assertTrue("Should be 1", annotations.length == 1);
2076 			assertEquals("Annotation mismatch", "@T(value = 7)", annotations[0].toString());
2077 
2078 			annotations = typeBinding.getSuperclass().getDeclaredMethods()[1].getExceptionTypes()[0].getTypeAnnotations();
2079 			assertTrue("Should be 1", annotations.length == 1);
2080 			assertEquals("Annotation mismatch", "@T(value = 8)", annotations[0].toString());
2081 
2082 			annotations = typeBinding.getSuperclass().getDeclaredMethods()[0].getAnnotations();
2083 			assertTrue("Should be 0", annotations.length == 0);
2084 
2085 			annotations = typeBinding.getSuperclass().getDeclaredTypes()[0].getAnnotations();
2086 			assertTrue("Should be 1", annotations.length == 1);
2087 			assertEquals("Annotation mismatch", "@T(value = 10)", annotations[0].toString());
2088 		} finally {
2089 			removeLibrary(javaProject, jarName, srcName);
2090 		}
2091 	}
2092 	// Variants where superclass in binary is an annotated inner/nested class
testBinaryWithoutGenericSignature_b()2093 	public void testBinaryWithoutGenericSignature_b() throws CoreException, IOException {
2094 		String jarName = "TypeBindingTests308.jar";
2095 		String srcName = "TypeBindingTests308_src.zip";
2096 		final IJavaProject javaProject = getJavaProject("Converter18");
2097 		try {
2098 			String[] pathAndContents = new String[] {
2099 				"Superclass.java",
2100 				"import java.lang.annotation.ElementType;\n" +
2101 				"import java.lang.annotation.Target;\n" +
2102 				"@Target(ElementType.TYPE_USE)\n" +
2103 				"@interface T {\n" +
2104 				"	int value() default 0;\n" +
2105 				"}\n" +
2106 				"@T(1)\n" +
2107 				"public abstract class Superclass extends @T(2) Object implements @T(3) Runnable {\n" +
2108 				"   @T(9)\n" +
2109 				"   Superclass () {}\n" +
2110 				"   @T(10)\n" +
2111 				"   class Inner {}\n" +
2112 				"   @T(11)\n" +
2113 				"   class SubInner extends @T(12) Inner {}\n" +
2114 				"   @T(13)\n" +
2115 				"   static class Nested {}\n" +
2116 				"   @T(14)\n" +
2117 				"   static class SubNested extends @T(15) Nested {}\n" +
2118 				"}\n"
2119 			};
2120 
2121 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
2122 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
2123 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
2124 
2125 			String contents =
2126 					"@T(21)\n" +
2127 					"public abstract class X extends @T(22) Superclass implements @T(23) Runnable {\n" +
2128 					"}\n";
2129 
2130 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
2131 			ASTNode node = buildAST(contents, this.workingCopy);
2132 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2133 			CompilationUnit compilationUnit = (CompilationUnit) node;
2134 			assertProblemsSize(compilationUnit, 0);
2135 			List types = compilationUnit.types();
2136 			assertEquals("Incorrect no of types", 1, types.size());
2137 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
2138 			ITypeBinding typeBinding = typeDecl.resolveBinding();
2139 			IAnnotationBinding[] annotations = typeBinding.getAnnotations();
2140 			assertTrue("Should be 1", annotations.length == 1);
2141 			assertEquals("Annotation mismatch", "@T(value = 21)", annotations[0].toString());
2142 
2143 			ITypeBinding superclass = typeBinding.getSuperclass();
2144 			ITypeBinding[] inners = superclass.getDeclaredTypes();
2145 			assertTrue("Should be 2", inners.length == 4);
2146 
2147 			ITypeBinding subInner = inners[2];
2148 			assertEquals("Type name mismatch", "SubInner", subInner.getName());
2149 			annotations = subInner.getAnnotations();
2150 			assertTrue("Should be 1", annotations.length == 1);
2151 			assertEquals("Annotation mismatch", "@T(value = 11)", annotations[0].toString());
2152 
2153 			annotations = subInner.getSuperclass().getTypeAnnotations();
2154 			assertTrue("Should be 1", annotations.length == 1);
2155 			assertEquals("Annotation mismatch", "@T(value = 12)", annotations[0].toString());
2156 
2157 			ITypeBinding subNested = inners[3];
2158 			annotations = subNested.getAnnotations();
2159 			assertTrue("Should be 1", annotations.length == 1);
2160 			assertEquals("Annotation mismatch", "@T(value = 14)", annotations[0].toString());
2161 
2162 			annotations = subNested.getSuperclass().getTypeAnnotations();
2163 			assertTrue("Should be 1", annotations.length == 1);
2164 			assertEquals("Annotation mismatch", "@T(value = 15)", annotations[0].toString());
2165 		} finally {
2166 			removeLibrary(javaProject, jarName, srcName);
2167 		}
2168 	}
2169 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=419918, [1.8][compiler] Annotations are not restored from class files in a few situations.
testBinaryAnnotationType()2170 	public void testBinaryAnnotationType() throws CoreException, IOException {
2171 		String jarName = "TypeBindingTests308.jar";
2172 		String srcName = "TypeBindingTests308_src.zip";
2173 		final IJavaProject javaProject = getJavaProject("Converter18");
2174 		try {
2175 			String[] pathAndContents = new String[] {
2176 				"T.java",
2177 				"import java.lang.annotation.ElementType;\n" +
2178 				"import java.lang.annotation.Target;\n" +
2179 				"@Deprecated\n" +
2180 				"@Target(ElementType.TYPE_USE)\n" +
2181 				"@interface T {\n" +
2182 				"	int value() default 0;\n" +
2183 				"}\n"
2184 			};
2185 
2186 			HashMap libraryOptions = new HashMap(javaProject.getOptions(true));
2187 			libraryOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED);
2188 			addLibrary(javaProject, jarName, srcName, pathAndContents, JavaCore.VERSION_1_8, libraryOptions);
2189 
2190 			String contents =
2191 					"@T\n" +
2192 					"public class X {\n" +
2193 					"}\n";
2194 
2195 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
2196 			ASTNode node = buildAST(contents, this.workingCopy, false);
2197 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2198 			CompilationUnit compilationUnit = (CompilationUnit) node;
2199 			assertProblemsSize(compilationUnit, 1, "The type T is deprecated");
2200 			List types = compilationUnit.types();
2201 			assertEquals("Incorrect no of types", 1, types.size());
2202 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
2203 			ITypeBinding typeBinding = typeDecl.resolveBinding();
2204 			IAnnotationBinding[] annotations = typeBinding.getAnnotations()[0].getAnnotationType().getAnnotations();
2205 			assertTrue("Should be 2", annotations.length == 2);
2206 			assertEquals("Annotation mismatch", "@Target(value = {public static final java.lang.annotation.ElementType TYPE_USE})", annotations[0].toString());
2207 			assertEquals("Annotation mismatch", "@Deprecated()", annotations[1].toString());
2208 		} finally {
2209 			removeLibrary(javaProject, jarName, srcName);
2210 		}
2211 	}
2212 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=420320, [1.8] Bad AST recovery with type annotation and a syntax error in secondary type
testAnnotationRecovery()2213 	public void testAnnotationRecovery() throws CoreException, IOException {
2214 		String contents =
2215 				"import java.lang.annotation.ElementType;\n" +
2216 				"import java.lang.annotation.Target;\n" +
2217 				"import java.util.List;\n" +
2218 				"@Target(ElementType.TYPE_USE)\n" +
2219 				"@interface NonNull {\n" +
2220 				"}\n" +
2221 				"public class X {\n" +
2222 				"	List<@NonNull String> list2;\n" +
2223 				"}\n" +
2224 				"class Y {\n" +
2225 				"    void bar()\n" +
2226 				"    void foo() { }\n" +
2227 				"}\n";
2228 
2229 		String expected =
2230 				"import java.lang.annotation.ElementType;\n" +
2231 				"import java.lang.annotation.Target;\n" +
2232 				"import java.util.List;\n" +
2233 				"@Target(ElementType.TYPE_USE) @interface NonNull {}\n" +
2234 				"public class X {\n" +
2235 				"  List<@NonNull String> list2;\n" +
2236 				"}\n" +
2237 				"class Y {\n" +
2238 				"  void bar(){\n" +
2239 				"  }\n" +
2240 				"  void foo(){\n" +
2241 				"  }\n" +
2242 				"}\n";
2243 
2244 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
2245 		ASTNode node = buildAST(contents, this.workingCopy, false, true);
2246 		assertEquals("AST mismatch", expected, node.toString());
2247 	}
2248 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427337
testBug427337()2249 	public void testBug427337() throws CoreException, IOException {
2250 		String contents =
2251 				"public class X implements I {\n" +
2252 				"}\n";
2253 
2254 		createFile("/Converter18/src/NonNull.java",
2255 				"import java.lang.annotation.ElementType;\n" +
2256 				"import java.lang.annotation.Target;\n" +
2257 				"@Target(ElementType.TYPE_USE)\n" +
2258 				"@interface NonNull {}");
2259 		createFile("/Converter18/src/I.java",
2260 				"import java.util.List;\n" +
2261 				"interface I { \n" +
2262 				"	String bar2(@NonNull String s, @NonNull List<@NonNull String> l2);\n" +
2263 				"}");
2264 
2265 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
2266 		ASTNode node = buildAST(contents, this.workingCopy, false, true);
2267 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2268 		TypeDeclaration type = (TypeDeclaration) ((CompilationUnit) node).types().get(0);
2269 		ITypeBinding binding = type.resolveBinding();
2270 		ITypeBinding superInterface = binding.getInterfaces()[0];
2271 		IMethodBinding method = superInterface.getDeclaredMethods()[0];
2272 		binding = method.getParameterTypes()[0];
2273 		assertEquals("Incorrect type binding", "@NonNull String", binding.toString());
2274 		binding = method.getParameterTypes()[1];
2275 		assertEquals("Incorrect type binding", "@NonNull List<@NonNull String>", binding.toString());
2276 	}
2277 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426515
testBug426515()2278 	public void testBug426515() throws CoreException {
2279 		try {
2280 			String contents =
2281 					"public class X {\n" +
2282 					"	void foo() {\n" +
2283 					"		Outer.getInner();\n" +
2284 					"	}\n" +
2285 					"}\n";
2286 
2287 			createFile("/Converter18/src/A.java",
2288 					"import java.lang.annotation.ElementType;\n" +
2289 					"import java.lang.annotation.Target;\n" +
2290 					"@Target(ElementType.TYPE_USE)\n" +
2291 					"@interface A { int value() default 0; \n }");
2292 			createFile("/Converter18/src/Outer.java",
2293 					"class Outer<T> { \n" +
2294 					"	public class Inner<I> {}\n" +
2295 					"	public static @A(1) Outer<java.lang.@A(2) String>.@A(3) Inner<java.lang.@A(4) Object> getInner() { \n" +
2296 					"		return null;\n" +
2297 					"	}\n" +
2298 					"}");
2299 
2300 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
2301 			ASTNode node = buildAST(contents, this.workingCopy, false, true);
2302 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2303 			TypeDeclaration type = (TypeDeclaration) ((CompilationUnit) node).types().get(0);
2304 			MethodDeclaration method = type.getMethods()[0];
2305 			ExpressionStatement statement = (ExpressionStatement) method.getBody().statements().get(0);
2306 			MethodInvocation methodCal = (MethodInvocation) statement.getExpression();
2307 			ITypeBinding binding = methodCal.resolveTypeBinding();
2308 			assertEquals("Incorrect type binding", "@A((int)1) Outer<@A((int)2) String>.@A((int)3) Inner<@A((int)4) Object>", binding.toString());
2309 		} finally {
2310 			deleteFile("/Converter18/src/A.java");
2311 			deleteFile("/Converter18/src/Outer.java");
2312 		}
2313 	}
2314 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425599, [1.8][compiler] ISE when trying to compile qualified and annotated class instance creation
test425599()2315 	public void test425599() throws CoreException, IOException {
2316 		String contents =
2317 				"import java.lang.annotation.ElementType;\n" +
2318 				"import java.lang.annotation.Target;\n" +
2319 				"public class X {\n" +
2320 				"    Object ax = new @A(1) Outer().new @A(2) Middle<@A(3) String>();\n" +
2321 				"}\n" +
2322 				"@Target(ElementType.TYPE_USE) @interface A { int value(); }\n" +
2323 				"class Outer {\n" +
2324 				"    class Middle<E> {}\n" +
2325 				"}\n";
2326 
2327 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
2328 		ASTNode node = buildAST(contents, this.workingCopy);
2329 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2330 		CompilationUnit compilationUnit = (CompilationUnit) node;
2331 		assertProblemsSize(compilationUnit, 0);
2332 		List types = compilationUnit.types();
2333 		assertEquals("Incorrect no of types", 3, types.size());
2334 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
2335 		FieldDeclaration[] fields = typeDecl.getFields();
2336 		assertEquals("Incorrect no of methods", 1, fields.length);
2337 		FieldDeclaration field = fields[0];
2338 		assertEquals("Object ax=new @A(1) Outer().new @A(2) Middle<@A(3) String>();\n", field.toString());
2339 	}
2340 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425216, Bug 425216 - [1.8][dom ast] Binding for 'this' should have type annotations when receiver is annotated
test425216()2341 	public void test425216() throws CoreException, IOException {
2342 		String contents =
2343 				"import static java.lang.annotation.ElementType.TYPE_USE;\n" +
2344 				"import java.lang.annotation.Target;\n" +
2345 				"@Target(TYPE_USE)\n" +
2346 				"@interface NonNull {}\n" +
2347 				"public class X {\n" +
2348 				"   X foo(@NonNull X this) {\n" +
2349 				"	   return this;\n" +
2350 				"   }\n" +
2351 				"}\n";
2352 
2353 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true);
2354 		ASTNode node = buildAST(contents, this.workingCopy);
2355 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2356 		CompilationUnit compilationUnit = (CompilationUnit) node;
2357 		assertProblemsSize(compilationUnit, 0);
2358 		List types = compilationUnit.types();
2359 		assertEquals("Incorrect no of types", 2, types.size());
2360 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
2361 		MethodDeclaration[] methods = typeDecl.getMethods();
2362 		assertEquals("Incorrect no of methods", 1, methods.length);
2363 		MethodDeclaration method = methods[0];
2364 		ReturnStatement statement = (ReturnStatement) method.getBody().statements().get(0);
2365 		ThisExpression expression = (ThisExpression) statement.getExpression();
2366 		ITypeBinding type = expression.resolveTypeBinding();
2367 		assertEquals("@NonNull X", type.toString());
2368 	}
2369 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425216, Bug 425216 - [1.8][dom ast] Binding for 'this' should have type annotations when receiver is annotated
test425216a()2370 	public void test425216a() throws CoreException, IOException {
2371 		String contents =
2372 				"import java.lang.annotation.*;\n" +
2373 				"@Target(ElementType.TYPE_USE)\n" +
2374 				"@interface A {\n" +
2375 				"    int value() default 0;\n" +
2376 				"}\n" +
2377 				"public class Outer {\n" +
2378 				"    class Middle {\n" +
2379 				"    	class Inner {\n" +
2380 				"    		public @A(1) Inner(@A(2) Outer.@A(3) Middle Middle.this) {\n" +
2381 				"    			Outer r1 = Outer.this;\n" +
2382 				"    			Outer.Middle middle = Outer.Middle.this;\n" +
2383 				"    			Inner i = this;\n" +
2384 				"    		}\n" +
2385 				"    	}\n" +
2386 				"    }\n" +
2387 				"}\n";
2388 
2389 		this.workingCopy = getWorkingCopy("/Converter18/src/Outer.java", true);
2390 		ASTNode node = buildAST(contents, this.workingCopy);
2391 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2392 		CompilationUnit compilationUnit = (CompilationUnit) node;
2393 		assertProblemsSize(compilationUnit, 0);
2394 		List types = compilationUnit.types();
2395 		assertEquals("Incorrect no of types", 2, types.size());
2396 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
2397 		MethodDeclaration method= typeDecl.getTypes()[0].getTypes()[0].getMethods()[0];
2398 		ITypeBinding receiverType = method.getReceiverType().resolveBinding();
2399 		assertEquals("@A((int)2) Outer.@A((int)3) Middle", receiverType.toString());
2400 		ITypeBinding declaringClass = receiverType.getDeclaringClass();
2401 		assertEquals("@A((int)2) Outer", declaringClass.toString());
2402 		final List statements = method.getBody().statements();
2403 		VariableDeclarationStatement statement = ((VariableDeclarationStatement) statements.get(0));
2404 		VariableDeclarationFragment fragment = (VariableDeclarationFragment) statement.fragments().get(0);
2405 		ITypeBinding type = fragment.getInitializer().resolveTypeBinding();
2406 		assertEquals("@A((int)2) Outer", type.toString());
2407 		statement = ((VariableDeclarationStatement) statements.get(1));
2408 		fragment = (VariableDeclarationFragment) statement.fragments().get(0);
2409 		type = fragment.getInitializer().resolveTypeBinding();
2410 		assertEquals("@A((int)2) Outer.@A((int)3) Middle", type.toString());
2411 		assertEquals("@A((int)2) Outer", type.getDeclaringClass().toString());
2412 		statement = ((VariableDeclarationStatement) statements.get(2));
2413 		fragment = (VariableDeclarationFragment) statement.fragments().get(0);
2414 		type = fragment.getInitializer().resolveTypeBinding();
2415 		assertTrue(type.getTypeAnnotations().length == 0);
2416 		assertTrue(type.getName().equals("Inner"));
2417 	}
2418 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425216, Bug 425216 - [1.8][dom ast] Binding for 'this' should have type annotations when receiver is annotated
test425216b()2419 	public void test425216b() throws CoreException, IOException {
2420 		String contents =
2421 				"import java.lang.annotation.*;\n" +
2422 				"@Target(ElementType.TYPE_USE)\n" +
2423 				"@interface A {\n" +
2424 				"    int value() default 0;\n" +
2425 				"}\n" +
2426 				"public class Outer {\n" +
2427 				"    class Middle {\n" +
2428 				"    	class Inner {\n" +
2429 				"    		public @A(1) Inner(@A(2) Outer.@A(3) Middle Middle.this) {\n" +
2430 				"    		}\n" +
2431 				"    	}\n" +
2432 				"    }\n" +
2433 				"}\n";
2434 
2435 		this.workingCopy = getWorkingCopy("/Converter18/src/Outer.java", true);
2436 		ASTNode node = buildAST(contents, this.workingCopy);
2437 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2438 		CompilationUnit compilationUnit = (CompilationUnit) node;
2439 		assertProblemsSize(compilationUnit, 0);
2440 		List types = compilationUnit.types();
2441 		assertEquals("Incorrect no of types", 2, types.size());
2442 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
2443 		MethodDeclaration method= typeDecl.getTypes()[0].getTypes()[0].getMethods()[0];
2444 		SimpleName receiverQualifier = method.getReceiverQualifier();
2445 		ITypeBinding type = receiverQualifier.resolveTypeBinding();
2446 		assertEquals("@A((int)2) Outer.@A((int)3) Middle", type.toString());
2447 	}
2448 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427320
testBug427320()2449 	public void testBug427320() throws Exception {
2450 		try {
2451 			String contents =
2452 					"public class X {\n" +
2453 					"	@A @B @C X() {}\n" +
2454 					"	@A @B @C String foo() {\nreturn null;\n}\n" +
2455 					"}\n" +
2456 					"@java.lang.annotation.Target ({java.lang.annotation.ElementType.CONSTRUCTOR, "
2457 													+ "java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.TYPE_USE})\n" +
2458 					"@interface A {}\n" +
2459 					"@java.lang.annotation.Target ({java.lang.annotation.ElementType.CONSTRUCTOR, "
2460 													+ "java.lang.annotation.ElementType.METHOD})\n" +
2461 					"@interface B {}\n" +
2462 					"@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
2463 					"@interface C {}\n";
2464 
2465 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
2466 		ASTNode node = buildAST(contents, this.workingCopy, false);
2467 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2468 		CompilationUnit compilationUnit = (CompilationUnit) node;
2469 		assertProblemsSize(compilationUnit, 0);
2470 		List types = compilationUnit.types();
2471 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(0);
2472 		MethodDeclaration method = typeDecl.getMethods()[0];
2473 		assertTrue("Should be a constructor", method.isConstructor());
2474 		IMethodBinding methodBinding = method.resolveBinding();
2475 		IAnnotationBinding[] annots = methodBinding.getAnnotations();
2476 		assertEquals("Incorrect no of annotations", 2, annots.length);
2477 		assertEquals("Incorrect annotations attached","@A()", annots[0].toString());
2478 		assertEquals("Incorrect annotations attached","@B()", annots[1].toString());
2479 		ITypeBinding binding = methodBinding.getReturnType();
2480 		annots = binding.getTypeAnnotations();
2481 		assertEquals("Incorrect no of annotations", 0, annots.length);
2482 
2483 		method = typeDecl.getMethods()[1];
2484 		methodBinding = method.resolveBinding();
2485 		annots = methodBinding.getAnnotations();
2486 		assertEquals("Incorrect no of annotations", 2, annots.length);
2487 		assertEquals("Incorrect annotations attached","@A()", annots[0].toString());
2488 		assertEquals("Incorrect annotations attached","@B()", annots[1].toString());
2489 		binding = methodBinding.getReturnType();
2490 		annots = binding.getTypeAnnotations();
2491 		assertEquals("Incorrect no of annotations", 2, annots.length);
2492 		assertEquals("Incorrect annotations attached","@A @C String", binding.toString());
2493 		} finally {
2494 			deleteFile("/Converter18/src/X.java");
2495 		}
2496 	}
2497 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=431810
testBug431810()2498 	public void testBug431810() throws Exception {
2499 		try {
2500 			String contents =
2501 				"import java.lang.annotation.ElementType; \n" +
2502 				"import java.lang.annotation.Target; \n" +
2503 				"@interface A {}\n" +
2504 				"@Target(ElementType.TYPE_USE)\n" +
2505 				"@interface B {} \n" +
2506 				"class X {\n" +
2507 				"	@A \n" +
2508 				"	X() {}\n" +
2509 				"	@B \n" +
2510 				"	X(int x) {}\n" +
2511 				"}\n";
2512 
2513 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
2514 		ASTNode node = buildAST(contents, this.workingCopy, false);
2515 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2516 		CompilationUnit compilationUnit = (CompilationUnit) node;
2517 		assertProblemsSize(compilationUnit, 0);
2518 
2519 		List types = compilationUnit.types();
2520 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(2);
2521 
2522 		// X()
2523 		MethodDeclaration method = typeDecl.getMethods()[0];
2524 		assertTrue("Should be a constructor", method.isConstructor());
2525 		IMethodBinding methodBinding = method.resolveBinding();
2526 		IAnnotationBinding[] annots = methodBinding.getAnnotations();
2527 
2528 		assertEquals("Incorrect no of annotations", 1, annots.length);
2529 		assertEquals("Incorrect annotations attached","@A()", annots[0].toString());
2530 
2531 		// X(int)
2532 		method = typeDecl.getMethods()[1];
2533 		assertTrue("Should be a constructor", method.isConstructor());
2534 		methodBinding = method.resolveBinding();
2535 		annots = methodBinding.getAnnotations();
2536 
2537 		assertEquals("Incorrect no of annotations", 0, annots.length);
2538 		} finally {
2539 			deleteFile("/Converter18/src/X.java");
2540 		}
2541 	}
2542 
2543 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=431810
2544 	// Incorrect use of annotations on constructors
testBug431810a()2545 	public void testBug431810a() throws Exception {
2546 		try {
2547 			String contents =
2548 				"import java.lang.annotation.ElementType; \n" +
2549 				"import java.lang.annotation.Target; \n" +
2550 				"@Target({}) \n" +
2551 				"@interface A {} \n" +
2552 				"@Target(ElementType.TYPE)\n" +
2553 				"@interface B {} \n" +
2554 				"class X {\n" +
2555 				"	@A \n" +
2556 				"	X() {}\n" +
2557 				"	@B \n" +
2558 				"	X(int x) {}\n" +
2559 				"}\n";
2560 
2561 		this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
2562 		ASTNode node = buildAST(contents, this.workingCopy, false);
2563 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2564 		CompilationUnit compilationUnit = (CompilationUnit) node;
2565 
2566 		List types = compilationUnit.types();
2567 		TypeDeclaration typeDecl = (TypeDeclaration) types.get(2);
2568 
2569 		// X()
2570 		MethodDeclaration method = typeDecl.getMethods()[0];
2571 		assertTrue("Should be a constructor", method.isConstructor());
2572 		IMethodBinding methodBinding = method.resolveBinding();
2573 		IAnnotationBinding[] annots = methodBinding.getAnnotations();
2574 		assertEquals("Incorrect no of annotations", 0, annots.length);
2575 
2576 		// X(int)
2577 		method = typeDecl.getMethods()[1];
2578 		assertTrue("Should be a constructor", method.isConstructor());
2579 		methodBinding = method.resolveBinding();
2580 		annots = methodBinding.getAnnotations();
2581 		assertEquals("Incorrect no of annotations", 0, annots.length);
2582 		} finally {
2583 			deleteFile("/Converter18/src/X.java");
2584 		}
2585 	}
2586 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=487716
testBug487716()2587 	public void testBug487716() throws Exception {
2588 		try {
2589 			String contents =
2590 				"import java.lang.annotation.ElementType; \n" +
2591 				"import java.lang.annotation.Target; \n" +
2592 				"@Target({ElementType.TYPE_USE, ElementType.CONSTRUCTOR})\n" +
2593 				"@interface A {} \n" +
2594 				"class X {\n" +
2595 				"	@A X() {}\n" +
2596 				"	X _x_ = new X();\n" +
2597 				"}\n";
2598 
2599 			this.workingCopy = getWorkingCopy("/Converter18/src/X.java", true/*resolve*/);
2600 			ASTNode node = buildAST(contents, this.workingCopy, false);
2601 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2602 			CompilationUnit compilationUnit = (CompilationUnit) node;
2603 
2604 			List types = compilationUnit.types();
2605 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
2606 
2607 			// On the Allocation expression type - new X()
2608 			FieldDeclaration field = typeDecl.getFields()[0];
2609 			VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0);
2610 			ITypeBinding type = fragment.getInitializer().resolveTypeBinding();
2611 			IAnnotationBinding[] annots = type.getTypeAnnotations();
2612 			assertEquals("Incorrect no of annotations", 1, annots.length);
2613 
2614 			// On constructor declaration - X()
2615 			MethodDeclaration method = typeDecl.getMethods()[0];
2616 			assertTrue("Should be a constructor", method.isConstructor());
2617 			IMethodBinding methodBinding = method.resolveBinding();
2618 			annots = methodBinding.getAnnotations();
2619 			assertEquals("Incorrect no of annotations", 1, annots.length);
2620 		} finally {
2621 			deleteFile("/Converter18/src/X.java");
2622 		}
2623 	}
2624 	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=487716
testBug487716a()2625 	public void testBug487716a() throws Exception {
2626 		try {
2627 			String contents =
2628 				"package p;\n" +
2629 				"import java.lang.annotation.ElementType; \n" +
2630 				"import java.lang.annotation.Target; \n" +
2631 				"@Target({ElementType.TYPE_USE})\n" +
2632 				"@interface A {} \n" +
2633 				"class X {\n" +
2634 				"	@A X() {}\n" +
2635 				"   class Y {\n" +
2636 				"		@A Y() {}\n" +
2637 				"		Y _y_ = new X().new Y();\n" +
2638 				"	}\n" +
2639 				"}\n";
2640 
2641 			this.workingCopy = getWorkingCopy("/Converter18/src/p/X.java", true/*resolve*/);
2642 			ASTNode node = buildAST(contents, this.workingCopy, false);
2643 			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2644 			CompilationUnit compilationUnit = (CompilationUnit) node;
2645 
2646 			List types = compilationUnit.types();
2647 			TypeDeclaration typeDecl = (TypeDeclaration) types.get(1);
2648 
2649 			assertEquals(1, typeDecl.getTypes().length);
2650 			typeDecl = typeDecl.getTypes()[0];
2651 
2652 			// On the Qualified Allocation expression type - new X().new Y()
2653 			FieldDeclaration field = typeDecl.getFields()[0];
2654 			VariableDeclarationFragment fragment = (VariableDeclarationFragment) field.fragments().get(0);
2655 			ITypeBinding type = fragment.getInitializer().resolveTypeBinding();
2656 			IAnnotationBinding[] annots = type.getTypeAnnotations();
2657 			assertEquals("Incorrect no of annotations", 1, annots.length);
2658 
2659 			// On constructor declaration - Y()
2660 			MethodDeclaration method = typeDecl.getMethods()[0];
2661 			assertTrue("Should be a constructor", method.isConstructor());
2662 			IMethodBinding methodBinding = method.resolveBinding();
2663 			annots = methodBinding.getAnnotations();
2664 			assertEquals("Incorrect no of annotations", 0, annots.length);
2665 		} finally {
2666 			deleteFile("/Converter18/src/X.java");
2667 		}
2668 	}
testBug460491_comment30()2669 	public void testBug460491_comment30() throws CoreException {
2670 		// placed in this suite because we need type annotations enabled
2671 		IPackageFragmentRoot srcRoot = this.currentProject.getPackageFragmentRoots()[0];
2672 		assertFalse(srcRoot.isReadOnly());
2673 		createFolder(srcRoot.getPath().append("test"));
2674 		IPackageFragment testPackage = srcRoot.getPackageFragment("test");
2675 
2676 		testPackage.createCompilationUnit("Generic.java",
2677 				"package test;\n" +
2678 				"\n" +
2679 				"public class Generic<T> {\n" +
2680 				"	public static class NestedStatic {\n" +
2681 				"		public static final String X = \"x\";\n" +
2682 				"	}\n" +
2683 				"}\n",
2684 				true,
2685 				null);
2686 		String contents =
2687 				"package test;\n" +
2688 				"\n" +
2689 				"public class Usage {\n" +
2690 				"	String f() {\n" +
2691 				"		return Generic.NestedStatic.X;\n" +
2692 				"	}\n" +
2693 				"}\n";
2694 		ICompilationUnit cu = testPackage.createCompilationUnit("Usage.java", contents, true, null);
2695 		ASTNode node = buildAST(contents, cu, false);
2696 		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
2697 		CompilationUnit compilationUnit = (CompilationUnit) node;
2698 
2699 		List types = compilationUnit.types();
2700 		assertEquals(1, types.size());
2701 		List methods = ((TypeDeclaration) types.get(0)).bodyDeclarations();
2702 		assertEquals(1, methods.size());
2703 		List statements = ((MethodDeclaration) methods.get(0)).getBody().statements();
2704 		assertEquals(1, statements.size());
2705 
2706 		Expression expression = ((ReturnStatement) statements.get(0)).getExpression();
2707 		IBinding binding = ((QualifiedName) expression).getQualifier().resolveBinding();
2708 		assertNotNull(binding);
2709 	}
2710 }
2711