Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/Class/getMethods/StarInheritance.java
41153 views
1
/*
2
* Copyright (c) 2002, 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 4654698
27
* @summary Verify that expected methods are returned for star inheritance.
28
*/
29
30
import java.lang.reflect.Method;
31
import java.util.Arrays;
32
import java.util.ArrayList;
33
34
// D.m
35
interface A1 extends B1, C1 {}
36
interface B1 extends D1 {}
37
interface C1 extends D1 {}
38
interface D1 { void m(); }
39
40
// A.m
41
interface A2 extends B2, C2 { void m(); }
42
interface B2 extends D2 {}
43
interface C2 extends D2 {}
44
interface D2 { void m(); }
45
46
// B.m, C.m
47
interface A3 extends B3, C3 {}
48
interface B3 extends D3 { void m(); }
49
interface C3 extends D3 { void m(); }
50
interface D3 { void m() ; }
51
52
// B.m
53
interface A4 extends B4, C4 {}
54
interface B4 extends D4 { void m(); }
55
interface C4 extends D4 {}
56
interface D4 { void m(); }
57
58
public class StarInheritance {
59
private static int n = 1;
60
61
private static void test(Method [] ma, ArrayList expect) {
62
System.out.println("Test " + n++);
63
64
if (expect.size() != ma.length) {
65
System.err.println(" found methods: " + Arrays.asList(ma));
66
System.err.println(" expected locations: " + expect);
67
throw new RuntimeException("found = " + ma.length
68
+"; expected = " + expect.size());
69
}
70
71
for (int i = 0; i < ma.length; i++) {
72
Method m = ma[i];
73
System.out.println(" " + m.toString());
74
int n;
75
if (m.getName().equals("m")
76
&& (n = expect.indexOf(m.getDeclaringClass())) != -1) {
77
expect.remove(n);
78
} else {
79
throw new RuntimeException("unable to locate method in class: "
80
+ m.getDeclaringClass());
81
}
82
}
83
}
84
85
public static void main(String [] args) {
86
Class [] l1 = {D1.class};
87
test(A1.class.getMethods(), new ArrayList(Arrays.asList(l1)));
88
89
Class [] l2 = {A2.class};
90
test(A2.class.getMethods(), new ArrayList(Arrays.asList(l2)));
91
92
Class [] l3 = {B3.class, C3.class};
93
test(A3.class.getMethods(), new ArrayList(Arrays.asList(l3)));
94
95
Class [] l4 = {B4.class};
96
test(A4.class.getMethods(), new ArrayList(Arrays.asList(l4)));
97
}
98
}
99
100