Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/Class/getEnclosingMethod/EnclosingMethodTests.java
41153 views
1
/*
2
* Copyright (c) 2004, 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 4962341
27
* @summary Check getEnclosingMethod method
28
* @author Joseph D. Darcy
29
*/
30
31
import java.lang.reflect.Method;
32
import java.lang.annotation.*;
33
34
public class EnclosingMethodTests {
35
static Class<?> anonymousClass;
36
37
static {
38
Cloneable c = new Cloneable() {}; // anonymous cloneable
39
anonymousClass = c.getClass();
40
}
41
42
EnclosingMethodTests() {}
43
44
@MethodDescriptor("java.lang.Class EnclosingMethodTests.getLocalClass(Object o)")
45
Class getLocalClass(Object o) {
46
class Local {};
47
Local l = new Local();
48
return l.getClass();
49
}
50
51
static int examine(Class enclosedClass, String methodSig) {
52
Method m = enclosedClass.getEnclosingMethod();
53
if (m == null && methodSig == null)
54
return 0;
55
56
if (m != null &&
57
m.getAnnotation(MethodDescriptor.class).value().equals(methodSig))
58
return 0; // everything is okay
59
else {
60
System.err.println("\nUnexpected method value; expected:\t" + methodSig +
61
"\ngot:\t" + m);
62
return 1;
63
}
64
}
65
66
@MethodDescriptor("public static void EnclosingMethodTests.main(java.lang.String[])")
67
public static void main(String argv[]) {
68
int failures = 0;
69
class StaticLocal {};
70
71
failures += examine(StaticLocal.class,
72
"public static void EnclosingMethodTests.main(java.lang.String[])");
73
74
failures += examine( (new EnclosingMethodTests()).getLocalClass(null),
75
"java.lang.Class EnclosingMethodTests.getLocalClass(Object o)");
76
77
failures += examine(EnclosingMethodTests.class, null);
78
79
failures += examine(anonymousClass, null);
80
81
if (failures > 0)
82
throw new RuntimeException("Test failed.");
83
}
84
}
85
86
@Retention(RetentionPolicy.RUNTIME)
87
@interface MethodDescriptor {
88
String value();
89
}
90
91