Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 409236 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java (+82 lines)
Lines 13-18 Link Here
13
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
14
 *        Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
14
 *        Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
15
 *                          Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
15
 *                          Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
16
 *                          Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator
16
 *******************************************************************************/
17
 *******************************************************************************/
17
package org.eclipse.jdt.core.tests.compiler.regression;
18
package org.eclipse.jdt.core.tests.compiler.regression;
18
19
Lines 3060-3065 public class TypeAnnotationTest extends AbstractRegressionTest { Link Here
3060
		checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
3061
		checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
3061
	}
3062
	}
3062
	
3063
	
3064
	public void test070a_codeblocks_castWithIntersectionCast() throws Exception {
3065
		this.runConformTest(
3066
			new String[] {
3067
				"X.java",
3068
			"import java.io.*;\n" +
3069
				"public class X {\n" + 
3070
				"   public void foo(Object o) {\n" +
3071
				"	  I i = (@B(1) I & J) o;\n" +
3072
				"	  J j = (I & @B(2) J) o;\n" +
3073
			    "   }\n" +
3074
				"}\n" +
3075
				"interface I {}\n" +
3076
				"interface J {}\n",
3077
				
3078
				"B.java",
3079
				"import java.lang.annotation.*;\n" + 
3080
				"@Target(ElementType.TYPE_USE)\n" + 
3081
				"@Retention(RetentionPolicy.RUNTIME)\n" + 
3082
				"@interface B {\n" + 
3083
				"	int value() default 1;\n" + 
3084
				"}\n",
3085
		},
3086
		"");
3087
		String expectedOutput =
3088
			"    RuntimeVisibleTypeAnnotations: \n" + 
3089
			"      #27 @B(\n" + 
3090
			"        #28 value=(int) 1 (constant type)\n" + 
3091
			"        target type = 0x47 CAST\n" + 
3092
			"        offset = 1\n" + 
3093
			"        type argument index = 0\n" + 
3094
			"      )\n" + 
3095
			"      #27 @B(\n" + 
3096
			"        #28 value=(int) 2 (constant type)\n" + 
3097
			"        target type = 0x47 CAST\n" + 
3098
			"        offset = 9\n" + 
3099
			"        type argument index = 1\n" + 
3100
			"      )\n";
3101
		checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
3102
	}
3103
	
3104
	public void test070b_codeblocks_castWithIntersectionCast() throws Exception {
3105
		this.runConformTest(
3106
			new String[] {
3107
				"X.java",
3108
			"import java.io.*;\n" +
3109
				"public class X {\n" + 
3110
				"   public void foo(Object o) {\n" +
3111
				"     System.out.println(123);\n" +
3112
				"	  I<String> i = (I<@B(1) String> & @B(2) J<String>) o;\n" +
3113
			    "   }\n" +
3114
				"}\n" +
3115
				"interface I<T> {}\n" +
3116
				"interface J<T> {}\n",
3117
				
3118
				"B.java",
3119
				"import java.lang.annotation.*;\n" + 
3120
				"@Target(ElementType.TYPE_USE)\n" + 
3121
				"@Retention(RetentionPolicy.RUNTIME)\n" + 
3122
				"@interface B {\n" + 
3123
				"	int value() default 1;\n" + 
3124
				"}\n",
3125
		},
3126
		"");
3127
		String expectedOutput =
3128
			"    RuntimeVisibleTypeAnnotations: \n" + 
3129
			"      #39 @B(\n" + 
3130
			"        #40 value=(int) 1 (constant type)\n" + 
3131
			"        target type = 0x47 CAST\n" + 
3132
			"        offset = 9\n" + 
3133
			"        type argument index = 0\n" + 
3134
			"        location = [TYPE_ARGUMENT(0)]\n" + 
3135
			"      )\n" + 
3136
			"      #39 @B(\n" + 
3137
			"        #40 value=(int) 2 (constant type)\n" + 
3138
			"        target type = 0x47 CAST\n" + 
3139
			"        offset = 9\n" + 
3140
			"        type argument index = 1\n" + 
3141
			"      )\n";
3142
		checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
3143
	}
3144
	
3063
	public void test071_codeblocks_constructorInvocationTypeArgument() throws Exception {
3145
	public void test071_codeblocks_constructorInvocationTypeArgument() throws Exception {
3064
		this.runConformTest(
3146
		this.runConformTest(
3065
			new String[] {
3147
			new String[] {
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java (-2 / +2 lines)
Lines 15-20 Link Here
15
 *							Bug 405066 - [1.8][compiler][codegen] Implement code generation infrastructure for JSR335             
15
 *							Bug 405066 - [1.8][compiler][codegen] Implement code generation infrastructure for JSR335             
16
 *        Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
16
 *        Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
17
 *                          Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
17
 *                          Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
18
 *                          Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator
18
 *******************************************************************************/
19
 *******************************************************************************/
19
package org.eclipse.jdt.internal.compiler;
20
package org.eclipse.jdt.internal.compiler;
20
21
Lines 2190-2197 public class ClassFile implements TypeConstants, TypeIds { Link Here
2190
				// bytecode offset
2191
				// bytecode offset
2191
				this.contents[this.contentsOffset++] = (byte) (annotationContext.info >> 8);
2192
				this.contents[this.contentsOffset++] = (byte) (annotationContext.info >> 8);
2192
				this.contents[this.contentsOffset++] = (byte) annotationContext.info;
2193
				this.contents[this.contentsOffset++] = (byte) annotationContext.info;
2193
				// type_argument_index not set for cast
2194
				this.contents[this.contentsOffset++] = (byte) annotationContext.info2;
2194
				this.contents[this.contentsOffset++] = (byte)0;
2195
				break;
2195
				break;
2196
				
2196
				
2197
			case AnnotationTargetTypeConstants.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT :
2197
			case AnnotationTargetTypeConstants.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT :
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java (+8 lines)
Lines 11-16 Link Here
11
 * 
11
 * 
12
 * Contributors:
12
 * Contributors:
13
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
14
 *        Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
15
 *                          Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator
14
 *******************************************************************************/
16
 *******************************************************************************/
15
package org.eclipse.jdt.internal.compiler.ast;
17
package org.eclipse.jdt.internal.compiler.ast;
16
18
Lines 30-35 public class IntersectionCastTypeReference extends TypeReference { Link Here
30
		this.sourceStart = typeReferences[0].sourceStart;
32
		this.sourceStart = typeReferences[0].sourceStart;
31
		int length = typeReferences.length;
33
		int length = typeReferences.length;
32
		this.sourceEnd = typeReferences[length - 1].sourceEnd;
34
		this.sourceEnd = typeReferences[length - 1].sourceEnd;
35
		for (int i = 0, max = typeReferences.length; i < max; i++) {
36
			if ((typeReferences[i].bits & ASTNode.HasTypeAnnotations) != 0) {
37
				this.bits |= ASTNode.HasTypeAnnotations;
38
				break;
39
			}
40
		}
33
	}
41
	}
34
42
35
	public TypeReference copyDims(int dim) {
43
	public TypeReference copyDims(int dim) {
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java (-8 / +14 lines)
Lines 16-21 Link Here
16
 *								bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types
16
 *								bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types
17
 *        Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
17
 *        Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
18
 *                          Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
18
 *                          Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
19
 *                          Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator
19
 *******************************************************************************/
20
 *******************************************************************************/
20
package org.eclipse.jdt.internal.compiler.ast;
21
package org.eclipse.jdt.internal.compiler.ast;
21
22
Lines 51-58 static class AnnotationCollector extends ASTVisitor { Link Here
51
	TypeReference typeReference;
52
	TypeReference typeReference;
52
	int targetType;
53
	int targetType;
53
	Annotation[] primaryAnnotations;
54
	Annotation[] primaryAnnotations;
54
	int info = -1;
55
	int info = 0;
55
	int info2 = -1;
56
	int info2 = 0;
56
	LocalVariableBinding localVariable;
57
	LocalVariableBinding localVariable;
57
	Annotation[][] annotationsOnDimensions;
58
	Annotation[][] annotationsOnDimensions;
58
	int dimensions;
59
	int dimensions;
Lines 183-194 static class AnnotationCollector extends ASTVisitor { Link Here
183
				case AnnotationTargetTypeConstants.NEW :
184
				case AnnotationTargetTypeConstants.NEW :
184
				case AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE :
185
				case AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE :
185
				case AnnotationTargetTypeConstants.METHOD_REFERENCE :
186
				case AnnotationTargetTypeConstants.METHOD_REFERENCE :
186
				case AnnotationTargetTypeConstants.CAST:
187
					annotationContext.info = this.info;
188
					break;
189
				case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER_BOUND :
190
				case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER_BOUND :
191
					annotationContext.info2 = this.info2;
192
					annotationContext.info = this.info;
187
					annotationContext.info = this.info;
193
					break;
188
					break;
194
				case AnnotationTargetTypeConstants.LOCAL_VARIABLE :
189
				case AnnotationTargetTypeConstants.LOCAL_VARIABLE :
Lines 199-204 static class AnnotationCollector extends ASTVisitor { Link Here
199
				case AnnotationTargetTypeConstants.METHOD_INVOCATION_TYPE_ARGUMENT :
194
				case AnnotationTargetTypeConstants.METHOD_INVOCATION_TYPE_ARGUMENT :
200
				case AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT :
195
				case AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT :
201
				case AnnotationTargetTypeConstants.METHOD_REFERENCE_TYPE_ARGUMENT :
196
				case AnnotationTargetTypeConstants.METHOD_REFERENCE_TYPE_ARGUMENT :
197
				case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER_BOUND :
198
				case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER_BOUND :
199
				case AnnotationTargetTypeConstants.CAST:
202
					annotationContext.info2 = this.info2;
200
					annotationContext.info2 = this.info2;
203
					annotationContext.info = this.info;
201
					annotationContext.info = this.info;
204
					break;
202
					break;
Lines 225-230 static class AnnotationCollector extends ASTVisitor { Link Here
225
		this.currentWildcard = wildcard;
223
		this.currentWildcard = wildcard;
226
		return true;
224
		return true;
227
	}
225
	}
226
	public boolean visit(IntersectionCastTypeReference intersectionCastTypeReference, BlockScope scope) {
227
		int length = intersectionCastTypeReference.typeReferences == null ? 0 : intersectionCastTypeReference.typeReferences.length;
228
		for (int i = 0; i < length; i++) {
229
			this.info2 = i;
230
			intersectionCastTypeReference.typeReferences[i].traverse(this, scope);
231
		}
232
		return false; // iteration was done here, do not repeat in the caller
233
	}
228
	public boolean visit(Argument argument, BlockScope scope) {
234
	public boolean visit(Argument argument, BlockScope scope) {
229
		if ((argument.bits & ASTNode.IsUnionType) == 0) {
235
		if ((argument.bits & ASTNode.IsUnionType) == 0) {
230
			return true;
236
			return true;
(-)a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/ExtendedAnnotation.java (-2 / +5 lines)
Lines 13-18 Link Here
13
 *     IBM Corporation - initial API and implementation
13
 *     IBM Corporation - initial API and implementation
14
 *        Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
14
 *        Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
15
 *                          Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
15
 *                          Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
16
 *                          Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator
16
 *******************************************************************************/
17
 *******************************************************************************/
17
package org.eclipse.jdt.internal.core.util;
18
package org.eclipse.jdt.internal.core.util;
18
19
Lines 209-215 public class ExtendedAnnotation extends ClassFileStruct implements IExtendedAnno Link Here
209
210
210
			case IExtendedAnnotationConstants.CAST :
211
			case IExtendedAnnotationConstants.CAST :
211
				this.offset = u2At(classFileBytes, this.readOffset, localOffset);
212
				this.offset = u2At(classFileBytes, this.readOffset, localOffset);
212
				this.readOffset += 3; // skipping the 3rd byte which will be 0 for CAST
213
				this.readOffset += 2; 
214
				// read type_argument_index
215
				this.annotationTypeIndex = u1At(classFileBytes, this.readOffset, localOffset);
216
				this.readOffset++;
213
				break;
217
				break;
214
218
215
			case IExtendedAnnotationConstants.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT :
219
			case IExtendedAnnotationConstants.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT :
216
- 

Return to bug 409236