# HG changeset patch # User jjg # Date 1351892157 25200 # Node ID 5652321f1ae4657265936eb1c1515f704752f381 # Parent eefd0e6642a8bf26e424aed8976df017bd7cdd77 7169362: JDK8: Write compiler tests for repeating annotations for JDK8 Reviewed-by: darcy, jjg Contributed-by: sonali.goel@oracle.com diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/BaseAnnoAsContainerAnno.java --- /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 {} + diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/BaseAnnoAsContainerAnno.out --- /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 diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/CyclicAnnotation.java --- /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 {} diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/CyclicAnnotation.out --- /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 diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/DefaultCasePresent.java --- /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 {} + diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/DocumentedContainerAnno.java --- /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 {} diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/DocumentedContainerAnno.out --- /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 diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/InheritedContainerAnno.java --- /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 {} + diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/InheritedContainerAnno.out --- /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 diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MissingContainer.java --- /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 {} diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MissingContainer.out --- /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 diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase1.java --- /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 {} + diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase1.out --- /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 diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase2.java --- /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 {} + diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MissingDefaultCase2.out --- /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 diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MissingValueMethod.java --- /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 {} + diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MissingValueMethod.out --- /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 diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MultiLevelRepeatableAnno.java --- /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 {} + diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/MultipleAnnoMixedOrder.java --- /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 {} + diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/NoRepeatableAnno.java --- /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 {} diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/NoRepeatableAnno.out --- /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 diff -r eefd0e6642a8 -r 5652321f1ae4 langtools/test/tools/javac/annotations/repeatingAnnotations/WrongReturnTypeForValue.java --- /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 {} diff -r eefd0e6642a8 -r 5652321f1ae4 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/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