Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 232296 Details for
Bug 409236
[1.8][compiler] Type annotations on intersection cast types dropped by code generator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix for this issue
0001-Bug409236-annotations-on-intersection-casts.patch (text/plain), 12.03 KB, created by
Andrew Clement
on 2013-06-12 11:13:15 EDT
(
hide
)
Description:
Fix for this issue
Filename:
MIME Type:
Creator:
Andrew Clement
Created:
2013-06-12 11:13:15 EDT
Size:
12.03 KB
patch
obsolete
>From 2cfaffb6536794f9b912a61368537f67d78849b7 Mon Sep 17 00:00:00 2001 >From: Andy Clement <andrew.clement@gmail.com> >Date: Wed, 12 Jun 2013 08:08:55 -0700 >Subject: [PATCH] Bug409236 - annotations on intersection casts > >--- > .../compiler/regression/TypeAnnotationTest.java | 82 ++++++++++++++++++++++ > .../eclipse/jdt/internal/compiler/ClassFile.java | 4 +- > .../ast/IntersectionCastTypeReference.java | 8 +++ > .../jdt/internal/compiler/ast/TypeReference.java | 22 +++--- > .../jdt/internal/core/util/ExtendedAnnotation.java | 6 +- > 5 files changed, 111 insertions(+), 11 deletions(-) > >diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java >index ccb9fde..07e365f 100644 >--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java >+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java >@@ -13,6 +13,7 @@ > * IBM Corporation - initial API and implementation > * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for > * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) >+ * Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator > *******************************************************************************/ > package org.eclipse.jdt.core.tests.compiler.regression; > >@@ -3060,6 +3061,87 @@ public class TypeAnnotationTest extends AbstractRegressionTest { > checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); > } > >+ public void test070a_codeblocks_castWithIntersectionCast() throws Exception { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "import java.io.*;\n" + >+ "public class X {\n" + >+ " public void foo(Object o) {\n" + >+ " I i = (@B(1) I & J) o;\n" + >+ " J j = (I & @B(2) J) o;\n" + >+ " }\n" + >+ "}\n" + >+ "interface I {}\n" + >+ "interface J {}\n", >+ >+ "B.java", >+ "import java.lang.annotation.*;\n" + >+ "@Target(ElementType.TYPE_USE)\n" + >+ "@Retention(RetentionPolicy.RUNTIME)\n" + >+ "@interface B {\n" + >+ " int value() default 1;\n" + >+ "}\n", >+ }, >+ ""); >+ String expectedOutput = >+ " RuntimeVisibleTypeAnnotations: \n" + >+ " #27 @B(\n" + >+ " #28 value=(int) 1 (constant type)\n" + >+ " target type = 0x47 CAST\n" + >+ " offset = 1\n" + >+ " type argument index = 0\n" + >+ " )\n" + >+ " #27 @B(\n" + >+ " #28 value=(int) 2 (constant type)\n" + >+ " target type = 0x47 CAST\n" + >+ " offset = 9\n" + >+ " type argument index = 1\n" + >+ " )\n"; >+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); >+ } >+ >+ public void test070b_codeblocks_castWithIntersectionCast() throws Exception { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "import java.io.*;\n" + >+ "public class X {\n" + >+ " public void foo(Object o) {\n" + >+ " System.out.println(123);\n" + >+ " I<String> i = (I<@B(1) String> & @B(2) J<String>) o;\n" + >+ " }\n" + >+ "}\n" + >+ "interface I<T> {}\n" + >+ "interface J<T> {}\n", >+ >+ "B.java", >+ "import java.lang.annotation.*;\n" + >+ "@Target(ElementType.TYPE_USE)\n" + >+ "@Retention(RetentionPolicy.RUNTIME)\n" + >+ "@interface B {\n" + >+ " int value() default 1;\n" + >+ "}\n", >+ }, >+ ""); >+ String expectedOutput = >+ " RuntimeVisibleTypeAnnotations: \n" + >+ " #39 @B(\n" + >+ " #40 value=(int) 1 (constant type)\n" + >+ " target type = 0x47 CAST\n" + >+ " offset = 9\n" + >+ " type argument index = 0\n" + >+ " location = [TYPE_ARGUMENT(0)]\n" + >+ " )\n" + >+ " #39 @B(\n" + >+ " #40 value=(int) 2 (constant type)\n" + >+ " target type = 0x47 CAST\n" + >+ " offset = 9\n" + >+ " type argument index = 1\n" + >+ " )\n"; >+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); >+ } >+ > public void test071_codeblocks_constructorInvocationTypeArgument() throws Exception { > this.runConformTest( > new String[] { >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java >index b3547fb..a7d3b61 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java >@@ -15,6 +15,7 @@ > * Bug 405066 - [1.8][compiler][codegen] Implement code generation infrastructure for JSR335 > * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for > * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) >+ * Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler; > >@@ -2190,8 +2191,7 @@ public class ClassFile implements TypeConstants, TypeIds { > // bytecode offset > this.contents[this.contentsOffset++] = (byte) (annotationContext.info >> 8); > this.contents[this.contentsOffset++] = (byte) annotationContext.info; >- // type_argument_index not set for cast >- this.contents[this.contentsOffset++] = (byte)0; >+ this.contents[this.contentsOffset++] = (byte) annotationContext.info2; > break; > > case AnnotationTargetTypeConstants.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT : >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java >index f4020cb..27da469 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java >@@ -11,6 +11,8 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for >+ * Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.ast; > >@@ -30,6 +32,12 @@ public class IntersectionCastTypeReference extends TypeReference { > this.sourceStart = typeReferences[0].sourceStart; > int length = typeReferences.length; > this.sourceEnd = typeReferences[length - 1].sourceEnd; >+ for (int i = 0, max = typeReferences.length; i < max; i++) { >+ if ((typeReferences[i].bits & ASTNode.HasTypeAnnotations) != 0) { >+ this.bits |= ASTNode.HasTypeAnnotations; >+ break; >+ } >+ } > } > > public TypeReference copyDims(int dim) { >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java >index 615cfa5..a56b1cb 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java >@@ -16,6 +16,7 @@ > * bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types > * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for > * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) >+ * Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.ast; > >@@ -51,8 +52,8 @@ static class AnnotationCollector extends ASTVisitor { > TypeReference typeReference; > int targetType; > Annotation[] primaryAnnotations; >- int info = -1; >- int info2 = -1; >+ int info = 0; >+ int info2 = 0; > LocalVariableBinding localVariable; > Annotation[][] annotationsOnDimensions; > int dimensions; >@@ -183,12 +184,6 @@ static class AnnotationCollector extends ASTVisitor { > case AnnotationTargetTypeConstants.NEW : > case AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE : > case AnnotationTargetTypeConstants.METHOD_REFERENCE : >- case AnnotationTargetTypeConstants.CAST: >- annotationContext.info = this.info; >- break; >- case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER_BOUND : >- case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER_BOUND : >- annotationContext.info2 = this.info2; > annotationContext.info = this.info; > break; > case AnnotationTargetTypeConstants.LOCAL_VARIABLE : >@@ -199,6 +194,9 @@ static class AnnotationCollector extends ASTVisitor { > case AnnotationTargetTypeConstants.METHOD_INVOCATION_TYPE_ARGUMENT : > case AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT : > case AnnotationTargetTypeConstants.METHOD_REFERENCE_TYPE_ARGUMENT : >+ case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER_BOUND : >+ case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER_BOUND : >+ case AnnotationTargetTypeConstants.CAST: > annotationContext.info2 = this.info2; > annotationContext.info = this.info; > break; >@@ -225,6 +223,14 @@ static class AnnotationCollector extends ASTVisitor { > this.currentWildcard = wildcard; > return true; > } >+ public boolean visit(IntersectionCastTypeReference intersectionCastTypeReference, BlockScope scope) { >+ int length = intersectionCastTypeReference.typeReferences == null ? 0 : intersectionCastTypeReference.typeReferences.length; >+ for (int i = 0; i < length; i++) { >+ this.info2 = i; >+ intersectionCastTypeReference.typeReferences[i].traverse(this, scope); >+ } >+ return false; // iteration was done here, do not repeat in the caller >+ } > public boolean visit(Argument argument, BlockScope scope) { > if ((argument.bits & ASTNode.IsUnionType) == 0) { > return true; >diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/ExtendedAnnotation.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/ExtendedAnnotation.java >index 902b329..634a1dc 100644 >--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/ExtendedAnnotation.java >+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/ExtendedAnnotation.java >@@ -13,6 +13,7 @@ > * IBM Corporation - initial API and implementation > * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for > * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) >+ * Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator > *******************************************************************************/ > package org.eclipse.jdt.internal.core.util; > >@@ -209,7 +210,10 @@ public class ExtendedAnnotation extends ClassFileStruct implements IExtendedAnno > > case IExtendedAnnotationConstants.CAST : > this.offset = u2At(classFileBytes, this.readOffset, localOffset); >- this.readOffset += 3; // skipping the 3rd byte which will be 0 for CAST >+ this.readOffset += 2; >+ // read type_argument_index >+ this.annotationTypeIndex = u1At(classFileBytes, this.readOffset, localOffset); >+ this.readOffset++; > break; > > case IExtendedAnnotationConstants.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT : >-- >1.7.11.2 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 409236
:
232296
|
233340