7169362: JDK8: Write compiler tests for repeating annotations for JDK8
authorjjg
Fri, 02 Nov 2012 14:35:57 -0700
changeset 14371 5652321f1ae4
parent 14370 eefd0e6642a8
child 14372 323bf6f14277
child 14440 c929e663eff3
7169362: JDK8: Write compiler tests for repeating annotations for JDK8 Reviewed-by: darcy, jjg Contributed-by: sonali.goel@oracle.com
langtools/test/tools/javac/annotations/repeatingAnnotations/BaseAnnoAsContainerAnno.java
langtools/test/tools/javac/annotations/repeatingAnnotations/BaseAnnoAsContainerAnno.out
langtools/test/tools/javac/annotations/repeatingAnnotations/CyclicAnnotation.java
langtools/test/tools/javac/annotations/repeatingAnnotations/CyclicAnnotation.out
langtools/test/tools/javac/annotations/repeatingAnnotations/DefaultCasePresent.java
langtools/test/tools/javac/annotations/repeatingAnnotations/DocumentedContainerAnno.java
langtools/test/tools/javac/annotations/repeatingAnnotations/DocumentedContainerAnno.out
langtools/test/tools/javac/annotations/repeatingAnnotations/InheritedContainerAnno.java
langtools/test/tools/javac/annotations/repeatingAnnotations/InheritedContainerAnno.out
langtools/test/tools/javac/annotations/repeatingAnnotations/MissingContainer.java
langtools/test/tools/javac/annotations/repeatingAnnotations/MissingContainer.out
langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase1.java
langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase1.out
langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase2.java
langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase2.out
langtools/test/tools/javac/annotations/repeatingAnnotations/MissingValueMethod.java
langtools/test/tools/javac/annotations/repeatingAnnotations/MissingValueMethod.out
langtools/test/tools/javac/annotations/repeatingAnnotations/MultiLevelRepeatableAnno.java
langtools/test/tools/javac/annotations/repeatingAnnotations/MultipleAnnoMixedOrder.java
langtools/test/tools/javac/annotations/repeatingAnnotations/NoRepeatableAnno.java
langtools/test/tools/javac/annotations/repeatingAnnotations/NoRepeatableAnno.out
langtools/test/tools/javac/annotations/repeatingAnnotations/WrongReturnTypeForValue.java
langtools/test/tools/javac/annotations/repeatingAnnotations/WrongReturnTypeForValue.out
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/BaseAnnoAsContainerAnno.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,20 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author  sogoel
+ * @summary Base annotation specify itself as ContainerAnnotation
+ * @compile/fail/ref=BaseAnnoAsContainerAnno.out -XDrawDiagnostics BaseAnnoAsContainerAnno.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy(Foo.class)
+@ContainerFor(Foo.class)
+@interface Foo {
+    Foo[] value() default {};
+}
+
+@Foo() @Foo()
+public class BaseAnnoAsContainerAnno {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/BaseAnnoAsContainerAnno.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,2 @@
+BaseAnnoAsContainerAnno.java:15:11: compiler.err.cyclic.annotation.element
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/CyclicAnnotation.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,26 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author  sogoel
+ * @summary Cyclic annotation not allowed
+ * @compile/fail/ref=CyclicAnnotation.out -XDrawDiagnostics CyclicAnnotation.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy(Foo.class)
+@ContainerFor(Baz.class)
+@interface Baz {
+    Foo[] value() default {};
+}
+
+@ContainedBy(Baz.class)
+@ContainerFor(Foo.class)
+@interface Foo{
+    Baz[] value() default {};
+}
+
+@Foo(value = {@Baz,@Baz})
+@Baz(value = {@Foo,@Foo})
+public class CyclicAnnotation {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/CyclicAnnotation.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,6 @@
+CyclicAnnotation.java:12:1: compiler.err.invalid.container.wrong.containerfor: Foo, Baz
+CyclicAnnotation.java:13:1: compiler.err.invalid.container.wrong.containedby: Foo, Baz
+CyclicAnnotation.java:15:11: compiler.err.cyclic.annotation.element
+CyclicAnnotation.java:18:1: compiler.err.invalid.container.wrong.containerfor: Baz, Foo
+CyclicAnnotation.java:19:1: compiler.err.invalid.container.wrong.containedby: Baz, Foo
+5 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/DefaultCasePresent.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug     7169362
+ * @author  sogoel
+ * @summary Default case for methods other than value() in ContainerAnno
+ * @compile DefaultCasePresent.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy(FooContainer.class)
+@interface Foo {}
+
+@ContainerFor(Foo.class)
+@interface FooContainer {
+    Foo[] value();
+    String other() default "other-method";
+}
+
+@Foo @Foo
+public class DefaultCasePresent {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/DocumentedContainerAnno.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,23 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author  sogoel
+ * @summary Base anno is Documented but Container anno is not
+ * @compile/fail/ref=DocumentedContainerAnno.out -XDrawDiagnostics DocumentedContainerAnno.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+import java.lang.annotation.Documented;
+
+@Documented
+@ContainedBy(FooContainer.class)
+@interface Foo {}
+
+@ContainerFor(Foo.class)
+@interface FooContainer{
+    Foo[] value();
+}
+
+@Foo @Foo
+public class DocumentedContainerAnno {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/DocumentedContainerAnno.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,2 @@
+DocumentedContainerAnno.java:14:1: compiler.err.invalid.containedby.annotation.not.documented: FooContainer, Foo
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InheritedContainerAnno.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,24 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author   sogoel
+ * @summary Base anno is Inherited but Container anno is not
+ * @compile/fail/ref=InheritedContainerAnno.out -XDrawDiagnostics InheritedContainerAnno.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+import java.lang.annotation.Inherited;
+
+@Inherited
+@ContainedBy(FooContainer.class)
+@interface Foo {}
+
+@ContainerFor(Foo.class)
+@interface FooContainer{
+    Foo[] value();
+}
+
+@Foo @Foo
+public class InheritedContainerAnno {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/InheritedContainerAnno.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,2 @@
+InheritedContainerAnno.java:14:1: compiler.err.invalid.containedby.annotation.not.inherited: FooContainer, Foo
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MissingContainer.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,21 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author  sogoel
+ * @summary ContainerAnnotation does not have FooContainer.class specified
+ * @compile/fail/ref=MissingContainer.out -XDrawDiagnostics MissingContainer.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy()
+@interface Foo {}
+
+@ContainerFor(Foo.class)
+@interface FooContainer {
+    Foo[] value();
+}
+
+@Foo @Foo
+public class MissingContainer {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MissingContainer.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,5 @@
+MissingContainer.java:20:1: compiler.err.invalid.containedby.annotation: Foo
+MissingContainer.java:20:6: compiler.err.invalid.containedby.annotation: Foo
+MissingContainer.java:12:1: compiler.err.annotation.missing.default.value: java.lang.annotation.ContainedBy, value
+MissingContainer.java:15:1: compiler.err.invalid.container.wrong.containedby: Foo, FooContainer
+4 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase1.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,23 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author  sogoel
+ * @summary Default case not specified for other methods in container annotation
+ * @compile/fail/ref=MissingDefaultCase1.out -XDrawDiagnostics MissingDefaultCase1.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy(FooContainer.class)
+@interface Foo {}
+
+@ContainerFor(Foo.class)
+@interface FooContainer {
+    Foo[] value();
+    String other();  // missing default clause
+}
+
+@Foo @Foo
+public class MissingDefaultCase1 {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase1.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,2 @@
+MissingDefaultCase1.java:12:1: compiler.err.invalid.containedby.annotation.elem.nondefault: FooContainer, other()
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase2.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,23 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author  sogoel
+ * @summary Missing default case for other method and return type is base annotation
+ * @compile/fail/ref=MissingDefaultCase2.out -XDrawDiagnostics MissingDefaultCase2.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy(FooContainer.class)
+@interface Foo {}
+
+@ContainerFor(Foo.class)
+@interface FooContainer {
+    Foo[] value();
+    Foo other();  // missing default clause and return type is an annotation
+}
+
+@Foo @Foo
+public class MissingDefaultCase2 {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase2.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,2 @@
+MissingDefaultCase2.java:12:1: compiler.err.invalid.containedby.annotation.elem.nondefault: FooContainer, other()
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MissingValueMethod.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,22 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author   sogoel
+ * @summary Missing value() method in ContainerAnnotation
+ * @compile/fail/ref=MissingValueMethod.out -XDrawDiagnostics MissingValueMethod.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy(FooContainer.class)
+@interface Foo {}
+
+@ContainerFor(Foo.class)
+@interface FooContainer{
+    Foo[] values();  // wrong method name
+}
+
+@Foo @Foo
+public class MissingValueMethod {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MissingValueMethod.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,4 @@
+MissingValueMethod.java:20:1: compiler.err.invalid.containedby.annotation.no.value: FooContainer
+MissingValueMethod.java:20:6: compiler.err.invalid.containedby.annotation.no.value: FooContainer
+MissingValueMethod.java:12:1: compiler.err.invalid.containedby.annotation.elem.nondefault: FooContainer, values()
+3 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MultiLevelRepeatableAnno.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug     7169362
+ * @author  sogoel
+ * @summary ContainerType can have its own container
+ * @compile MultiLevelRepeatableAnno.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy(FooContainer.class)
+@interface Foo {}
+
+@ContainedBy(FooContainerContainer.class)
+@ContainerFor(Foo.class)
+@interface FooContainer {
+    Foo[] value();
+}
+
+@ContainerFor(FooContainer.class)
+@interface FooContainerContainer {
+  FooContainer[] value();
+}
+
+@Foo @Foo
+public class MultiLevelRepeatableAnno  {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/MultipleAnnoMixedOrder.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug     7169362
+ * @author  sogoel
+ * @summary Repeatable annotations in random order
+ * @compile MultipleAnnoMixedOrder.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy(FooContainer.class)
+@interface Foo {
+    int getNumbers();
+}
+
+@ContainerFor(Foo.class)
+@interface FooContainer {
+  Foo[] value();
+}
+
+@ContainedBy(BazContainer.class)
+@interface Baz {
+    String getStr();
+}
+
+@ContainerFor(Baz.class)
+@interface BazContainer {
+  Baz[] value();
+}
+
+@Foo(getNumbers=1)
+@Baz(getStr="hello")
+@Foo(getNumbers=2)
+@Baz(getStr="world")
+public class MultipleAnnoMixedOrder  {}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/NoRepeatableAnno.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,12 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author  sogoel
+ * @summary Foo is not a repeatable annotation but used as one.
+ * @compile/fail/ref=NoRepeatableAnno.out -XDrawDiagnostics NoRepeatableAnno.java
+ */
+
+@interface Foo {}
+
+@Foo @Foo
+public class NoRepeatableAnno {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/NoRepeatableAnno.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,3 @@
+NoRepeatableAnno.java:11:1: compiler.err.duplicate.annotation.missing.container: Foo
+NoRepeatableAnno.java:11:6: compiler.err.duplicate.annotation.missing.container: Foo
+2 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/WrongReturnTypeForValue.java	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,23 @@
+/**
+ * @test    /nodynamiccopyright/
+ * @bug     7169362
+ * @author  sogoel
+ * @summary Wrong return type for value() in ContainerAnnotation
+ * @compile/fail/ref=WrongReturnTypeForValue.out -XDrawDiagnostics WrongReturnTypeForValue.java
+ */
+
+import java.lang.annotation.ContainedBy;
+import java.lang.annotation.ContainerFor;
+
+@ContainedBy(FooContainer.class)
+@interface Foo {
+    int getNumbers();
+}
+
+@ContainerFor(Foo.class)
+@interface FooContainer{
+    Foo value();     // wrong return type
+}
+
+@Foo @Foo
+public class WrongReturnTypeForValue {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/annotations/repeatingAnnotations/WrongReturnTypeForValue.out	Fri Nov 02 14:35:57 2012 -0700
@@ -0,0 +1,3 @@
+WrongReturnTypeForValue.java:22:1: compiler.err.invalid.containedby.annotation.value.return: FooContainer, Foo, Foo[]
+WrongReturnTypeForValue.java:22:6: compiler.err.invalid.containedby.annotation.value.return: FooContainer, Foo, Foo[]
+2 errors