提交 4a6e4445 编写于 作者: J jjg

7169362: JDK8: Write compiler tests for repeating annotations for JDK8

Reviewed-by: darcy, jjg
Contributed-by: sonali.goel@oracle.com
上级 0d937ac0
/**
* @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 {}
BaseAnnoAsContainerAnno.java:15:11: compiler.err.cyclic.annotation.element
1 error
/**
* @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 {}
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
/*
* 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 {}
/**
* @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 {}
DocumentedContainerAnno.java:14:1: compiler.err.invalid.containedby.annotation.not.documented: FooContainer, Foo
1 error
/**
* @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 {}
InheritedContainerAnno.java:14:1: compiler.err.invalid.containedby.annotation.not.inherited: FooContainer, Foo
1 error
/**
* @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 {}
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
/**
* @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 {}
MissingDefaultCase1.java:12:1: compiler.err.invalid.containedby.annotation.elem.nondefault: FooContainer, other()
1 error
/**
* @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 {}
MissingDefaultCase2.java:12:1: compiler.err.invalid.containedby.annotation.elem.nondefault: FooContainer, other()
1 error
/**
* @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 {}
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
/*
* 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 {}
/*
* 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 {}
/**
* @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 {}
NoRepeatableAnno.java:11:1: compiler.err.duplicate.annotation.missing.container: Foo
NoRepeatableAnno.java:11:6: compiler.err.duplicate.annotation.missing.container: Foo
2 errors
/**
* @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 {}
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册