diff options
author | Stephan Herrmann | 2013-08-26 20:43:24 +0000 |
---|---|---|
committer | Stephan Herrmann | 2013-08-26 21:09:50 +0000 |
commit | 365e7f87646ce6e1751b8c49284326393484178c (patch) | |
tree | f8dc1e75e592288b30c14a6c7a625ad1b82249bc | |
parent | 4ff288f9c14eba5c9780f50be4522a4e3396a5cb (diff) | |
download | eclipse.jdt.core-365e7f87646ce6e1751b8c49284326393484178c.tar.gz eclipse.jdt.core-365e7f87646ce6e1751b8c49284326393484178c.tar.xz eclipse.jdt.core-365e7f87646ce6e1751b8c49284326393484178c.zip |
Bug 415850 - [1.8] Ensure RunJDTCoreTests can cope with null annotations
enabled
2 files changed, 39 insertions, 10 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java index dcb7175df7..6d4d46f8fc 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java @@ -1742,4 +1742,26 @@ public class NullTypeAnnotationTest extends AbstractNullAnnotationTest { "----------\n"); } + // don't let type annotations on array dimensions spoil type compatibility + // case without any error + public void testBug415850_06() { + runConformTestWithLibs( + new String[]{ + "X.java", + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int @Marker [][][] i = new @Marker int @Marker [2] @Marker [bar()] @Marker [];\n" + + " }\n" + + " public int bar() {\n" + + " return 2;\n" + + " }\n" + + "}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + }, + getCompilerOptions(), + ""); + } + }
\ No newline at end of file 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 3f708698ea..65eec856d5 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 * bug 392384 - [1.8][compiler][null] Restore nullness info from type annotations in class files * Bug 415043 - [1.8][null] Follow-up re null type annotations after bug 392099 + * Bug 415850 - [1.8] Ensure RunJDTCoreTests can cope with null annotations enabled * 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 @@ -570,13 +571,16 @@ protected void resolveAnnotations(Scope scope) { for (int j=0; j<len; j++) { Binding recipient = currentAnnotations[j].recipient; if (recipient instanceof Annotation.TypeUseBinding) { - if (isArrayReference) { - if (tagBitsPerDimension == null) - tagBitsPerDimension = new long[dimensions+1]; // each dimension plus leaf component type at last position - // @NonNull Foo [][][] means the leaf component type is @NonNull: - tagBitsPerDimension[dimensions] = ((Annotation.TypeUseBinding)recipient).tagBits & TagBits.AnnotationNullMASK; - } else { - tagBits |= ((Annotation.TypeUseBinding)recipient).tagBits & TagBits.AnnotationNullMASK; + long nullTagBits = ((Annotation.TypeUseBinding)recipient).tagBits & TagBits.AnnotationNullMASK; + if (nullTagBits != 0) { + if (isArrayReference) { + if (tagBitsPerDimension == null) + tagBitsPerDimension = new long[dimensions+1]; // each dimension plus leaf component type at last position + // @NonNull Foo [][][] means the leaf component type is @NonNull: + tagBitsPerDimension[dimensions] = nullTagBits; + } else { + tagBits |= nullTagBits; + } } } } @@ -595,9 +599,12 @@ protected void resolveAnnotations(Scope scope) { for (int j=0; j<len; j++) { Binding recipient = dimensionAnnotations[j].recipient; if (recipient instanceof Annotation.TypeUseBinding) { - if (tagBitsPerDimension == null) - tagBitsPerDimension = new long[dimensions+1]; - tagBitsPerDimension[i] = ((Annotation.TypeUseBinding)recipient).tagBits & TagBits.AnnotationNullMASK; + long nullTagBits = ((Annotation.TypeUseBinding)recipient).tagBits & TagBits.AnnotationNullMASK; + if (nullTagBits != 0) { + if (tagBitsPerDimension == null) + tagBitsPerDimension = new long[dimensions+1]; + tagBitsPerDimension[i] = nullTagBits; + } } } } |