View | Details | Raw Unified | Return to bug 353474 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java (-2 / +99 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann - Contribution for Bug 342671 - ClassCastException: org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.ArrayBinding
10
 *     Stephan Herrmann - Contributions for 
11
 *     							Bug 342671 - ClassCastException: org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding cannot be cast to org.eclipse.jdt.internal.compiler.lookup.ArrayBinding
12
 *     							Bug 353474 - type converters should include more annotations
11
 *******************************************************************************/
13
 *******************************************************************************/
12
package org.eclipse.jdt.core.tests.dom;
14
package org.eclipse.jdt.core.tests.dom;
13
15
Lines 50-56 Link Here
50
	static {
52
	static {
51
//		TESTS_NUMBERS = new int[] { 353 };
53
//		TESTS_NUMBERS = new int[] { 353 };
52
//		TESTS_RANGE = new int[] { 325, -1 };
54
//		TESTS_RANGE = new int[] { 325, -1 };
53
//		TESTS_NAMES = new String[] {"test0204"};
55
//		TESTS_NAMES = new String[] {"testBug353474"};
54
	}
56
	}
55
	public static Test suite() {
57
	public static Test suite() {
56
		return buildModelTestSuite(ASTConverter15Test.class);
58
		return buildModelTestSuite(ASTConverter15Test.class);
Lines 11348-11352 Link Here
11348
        rhsType = ((Assignment)((ExpressionStatement)((Statement) statements.get(1))).getExpression()).getRightHandSide().resolveTypeBinding();
11350
        rhsType = ((Assignment)((ExpressionStatement)((Statement) statements.get(1))).getExpression()).getRightHandSide().resolveTypeBinding();
11349
        assertFalse("Assignement compatible", rhsType.isAssignmentCompatible(assignmentType));
11351
        assertFalse("Assignement compatible", rhsType.isAssignmentCompatible(assignmentType));
11350
	}
11352
	}
11353
	// Bug 353474 - type converters should include more annotations
11354
	public void testBug353474() throws CoreException {
11355
		
11356
		this.createFolder("/Converter15/src/testBug353474/annot");
11357
		String contents =	
11358
			"package testBug353474.annot;\n" +
11359
			"import static java.lang.annotation.ElementType.*;\n" + 
11360
			"import java.lang.annotation.*;\n" + 
11361
			"@Retention(RetentionPolicy.CLASS)\n" + 
11362
			"@Target({METHOD,PARAMETER,LOCAL_VARIABLE})\n" + 
11363
			"public @interface Nullable {\n" + 
11364
			"}\n";
11365
		getWorkingCopy("/Converter15/src/testBug353474/annot/Nullable.java", contents, true/*resolve*/);
11366
11367
		this.createFolder("/Converter15/src/testBug353474/p1");
11368
		contents =	
11369
			"package testBug353474.p1;\n" +
11370
			"import testBug353474.annot.*;\n" +
11371
			"public class C1 {\n" +
11372
			"	 public @Nullable String foo(@Nullable Object arg) {\n" +
11373
			"		return \"\";\n" +
11374
			"	 }\n" +
11375
			"}\n";
11376
		getWorkingCopy("/Converter15/src/testBug353474/p1/C1.java", contents, true/*resolve*/);
11377
11378
		this.workingCopy = getWorkingCopy("/Converter15/src/testBug353474/p1/C2.java", true/*resolve*/);
11379
		contents =
11380
			"package testBug353474.p1;\n" +
11381
			"public class C2 {\n" +
11382
			"	 public String bar(C1 c1) {\n" +
11383
			"        return c1.foo(null);\n" +
11384
			"    }\n" +
11385
			"}\n";
11386
		ASTNode node = buildAST(
11387
				contents,
11388
				this.workingCopy,
11389
				true);
11390
		assertNotNull("No node", node);
11391
		assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
11392
		CompilationUnit compilationUnit = (CompilationUnit) node;
11393
		TypeDeclaration c2 = (TypeDeclaration) compilationUnit.types().get(0);
11394
		MethodDeclaration bar = (MethodDeclaration) c2.bodyDeclarations().get(0);
11395
		ReturnStatement returnStat = (ReturnStatement) bar.getBody().statements().get(0);
11396
		MethodInvocation fooCall = (MethodInvocation) returnStat.getExpression();
11397
		IMethodBinding resolvedFoo = fooCall.resolveMethodBinding();
11398
		IAnnotationBinding[] parameterAnnotations0 = resolvedFoo.getParameterAnnotations(0);
11399
		assertNotNull("Parameter annotation should not be null", parameterAnnotations0);
11400
		assertEquals("Should have exactly one annotation", 1, parameterAnnotations0.length);
11401
		assertEquals("Unexpected annotation name", "Nullable", parameterAnnotations0[0].getName());
11402
		
11403
		IAnnotationBinding[] returnAnnotations = resolvedFoo.getAnnotations();
11404
		assertNotNull("Return annotation should not be null", returnAnnotations);
11405
		assertEquals("Should have exactly one return annotation", 1, returnAnnotations.length);
11406
		assertEquals("Unexpected annotation name", "Nullable", returnAnnotations[0].getName());
11407
		deleteFolder("/Converter15/src/testBug353474");
11408
	}
11409
	// Bug 353474 - type converters should include more annotations
11410
	// secondary type comes from binary
11411
	public void testBug353474a() throws CoreException {
11412
		String jarLocation = getWorkspacePath()+"Converter15/bins/bug353474.jar";
11413
		IJavaProject jp = createJavaProject("Bug353464a", new String[]{"src"}, new String[]{"CONVERTER_JCL15_LIB", jarLocation}, "bin", "1.5");
11414
		try {
11415
			this.workingCopy = getWorkingCopy("/Bug353464a/src/testBug353474/p1/C2.java", true/*resolve*/);
11416
			String contents =
11417
				"package testBug353474.p1;\n" +
11418
				"public class C2 {\n" +
11419
				"	 public String bar(C1a c1) {\n" +
11420
				"        return c1.foo(null);\n" +
11421
				"    }\n" +
11422
				"}\n";
11423
			ASTNode node = buildAST(
11424
					contents,
11425
					this.workingCopy,
11426
					true);
11427
			assertNotNull("No node", node);
11428
			assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
11429
			CompilationUnit compilationUnit = (CompilationUnit) node;
11430
			TypeDeclaration c2 = (TypeDeclaration) compilationUnit.types().get(0);
11431
			MethodDeclaration bar = (MethodDeclaration) c2.bodyDeclarations().get(0);
11432
			ReturnStatement returnStat = (ReturnStatement) bar.getBody().statements().get(0);
11433
			MethodInvocation fooCall = (MethodInvocation) returnStat.getExpression();
11434
			IMethodBinding resolvedFoo = fooCall.resolveMethodBinding();
11435
			IAnnotationBinding[] parameterAnnotations0 = resolvedFoo.getParameterAnnotations(0);
11436
			assertNotNull("Parameter annotation should not be null", parameterAnnotations0);
11437
			assertEquals("Should have exactly one annotation", 1, parameterAnnotations0.length);
11438
			assertEquals("Unexpected annotation name", "Nullable", parameterAnnotations0[0].getName());
11439
			
11440
			IAnnotationBinding[] returnAnnotations = resolvedFoo.getAnnotations();
11441
			assertNotNull("Return annotation should not be null", returnAnnotations);
11442
			assertEquals("Should have exactly one return annotation", 1, returnAnnotations.length);
11443
			assertEquals("Unexpected annotation name", "Nullable", returnAnnotations[0].getName());
11444
		} finally {
11445
			deleteProject(jp);
11446
		}
11447
	}
11351
11448
11352
}
11449
}
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java (-2 / +11 lines)
Added Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Added Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - TypeConverters don't set enclosingType - https://bugs.eclipse.org/bugs/show_bug.cgi?id=320841
10
 *     Stephan Herrmann <stephan@cs.tu-berlin.de> - Contributions for
11
 *     								Bug 320841 - TypeConverters don't set enclosingType
12
 *     								Bug 353474 - type converters should include more annotations
11
 *******************************************************************************/
13
 *******************************************************************************/
12
package org.eclipse.jdt.internal.compiler.parser;
14
package org.eclipse.jdt.internal.compiler.parser;
13
15
Added Link Here
28
import org.eclipse.jdt.core.IAnnotation;
30
import org.eclipse.jdt.core.IAnnotation;
29
import org.eclipse.jdt.core.IImportDeclaration;
31
import org.eclipse.jdt.core.IImportDeclaration;
30
import org.eclipse.jdt.core.IJavaElement;
32
import org.eclipse.jdt.core.IJavaElement;
33
import org.eclipse.jdt.core.ILocalVariable;
31
import org.eclipse.jdt.core.ISourceRange;
34
import org.eclipse.jdt.core.ISourceRange;
32
import org.eclipse.jdt.core.JavaModelException;
35
import org.eclipse.jdt.core.JavaModelException;
33
import org.eclipse.jdt.core.Signature;
36
import org.eclipse.jdt.core.Signature;
Added Link Here
373
		char[][] argumentNames = methodInfo.getArgumentNames();
376
		char[][] argumentNames = methodInfo.getArgumentNames();
374
		int argumentCount = argumentTypeSignatures == null ? 0 : argumentTypeSignatures.length;
377
		int argumentCount = argumentTypeSignatures == null ? 0 : argumentTypeSignatures.length;
375
		if (argumentCount > 0) {
378
		if (argumentCount > 0) {
379
			ILocalVariable[] parameters = methodHandle.getParameters();
376
			long position = ((long) start << 32) + end;
380
			long position = ((long) start << 32) + end;
377
			method.arguments = new Argument[argumentCount];
381
			method.arguments = new Argument[argumentCount];
378
			for (int i = 0; i < argumentCount; i++) {
382
			for (int i = 0; i < argumentCount; i++) {
Added Link Here
387
						typeReference,
391
						typeReference,
388
						ClassFileConstants.AccDefault);
392
						ClassFileConstants.AccDefault);
389
				// do not care whether was final or not
393
				// do not care whether was final or not
394
				// convert 1.5 specific constructs only if compliance is 1.5 or above
395
				if (this.has1_5Compliance) {
396
					/* convert annotations */
397
					method.arguments[i].annotations = convertAnnotations(parameters[i]);
398
				}
390
			}
399
			}
391
		}
400
		}
392
401

Return to bug 353474