Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/annotation/repeatingAnnotations/OrderUnitTest.java
41153 views
1
/*
2
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8004912
27
* @summary Unit test for order of annotations returned by get[Declared]AnnotationsByType.
28
*
29
* @run main OrderUnitTest
30
*/
31
32
import java.lang.annotation.*;
33
import java.lang.reflect.*;
34
35
public class OrderUnitTest {
36
37
public static void main(String[] args) {
38
testOrder(Case1.class);
39
testOrder(Case2.class);
40
}
41
42
private static void testOrder(AnnotatedElement e) {
43
Annotation[] decl = e.getDeclaredAnnotations();
44
Foo[] declByType = e.getDeclaredAnnotationsByType(Foo.class);
45
46
if (decl[0] instanceof Foo != declByType[0].isDirect() ||
47
decl[1] instanceof Foo != declByType[1].isDirect()) {
48
throw new RuntimeException("Order of directly / indirectly present " +
49
"annotations from getDeclaredAnnotationsByType does not " +
50
"match order from getDeclaredAnnotations.");
51
}
52
}
53
}
54
55
@Retention(RetentionPolicy.RUNTIME)
56
@interface FooContainer {
57
Foo[] value();
58
}
59
60
@Retention(RetentionPolicy.RUNTIME)
61
@Repeatable(FooContainer.class)
62
@interface Foo {
63
boolean isDirect();
64
}
65
66
67
@Foo(isDirect = true) @FooContainer({@Foo(isDirect = false)})
68
class Case1 {
69
}
70
71
72
@FooContainer({@Foo(isDirect = false)}) @Foo(isDirect = true)
73
class Case2 {
74
}
75
76