Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/reflect/Constructor/TestParameterAnnotations.java
38828 views
1
/*
2
* Copyright (c) 2005, 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 6332964
27
* @summary Verify getParameterAnnotations doesn't throw spurious errors
28
* @author Joseph D. Darcy
29
*/
30
31
import java.lang.reflect.*;
32
import java.lang.annotation.*;
33
import static java.lang.annotation.RetentionPolicy.*;
34
import java.util.Arrays;
35
36
public class TestParameterAnnotations {
37
class Inner {
38
public Inner(@Marker Object o) {}
39
}
40
41
static class StaticNested {
42
public StaticNested(@Marker Object o) {}
43
}
44
45
static int visitCtorParameterAnnotations(Class clazz) {
46
int errors = 0;
47
for(Constructor<?> ctor : clazz.getDeclaredConstructors()) {
48
try {
49
System.out.printf("%nNormal: %s%nGeneric: %s%n",
50
ctor.toString(),
51
ctor.toGenericString());
52
Annotation[][] annotationArray = ctor.getParameterAnnotations();
53
System.out.println("\tParameter Annotations: " +
54
Arrays.deepToString(annotationArray));
55
} catch (AnnotationFormatError afe) {
56
System.err.println("\tWhoops, got an AnnotationFormatError on " +
57
ctor.toGenericString());
58
errors++;
59
}
60
}
61
return errors;
62
}
63
64
public static void main(String... argv) {
65
int errors = 0;
66
class LocalClass {
67
LocalClass(@Marker int i){}
68
}
69
70
Object anonymous = new Object() {public String toString(){return "Anonymous";}};
71
72
errors +=
73
visitCtorParameterAnnotations(Inner.class);
74
errors +=
75
visitCtorParameterAnnotations(StaticNested.class);
76
errors +=
77
visitCtorParameterAnnotations(CustomColors.class);
78
errors +=
79
visitCtorParameterAnnotations(TestParameterAnnotations.class);
80
errors +=
81
visitCtorParameterAnnotations(LocalClass.class);
82
errors +=
83
visitCtorParameterAnnotations(anonymous.getClass());
84
85
if (errors > 0)
86
throw new RuntimeException(errors +
87
" failures calling Constructor.getParameterAnnotations");
88
}
89
}
90
91
enum CustomColors {
92
FUCHSIA(5),
93
MULBERRY(6.0d);
94
CustomColors(@Marker int arg) {}
95
CustomColors(double arg) {}
96
}
97
98
@Retention(RUNTIME)
99
@interface Marker {}
100
101