Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Properties/CheckOverrides.java
41149 views
1
/*
2
* Copyright (c) 2016, 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
import java.lang.reflect.Method;
25
import java.lang.reflect.Modifier;
26
import java.util.*;
27
import java.util.stream.Collectors;
28
import java.util.stream.Stream;
29
30
/*
31
* @test
32
* @bug 8029891
33
* @summary Test that the Properties class overrides all public+protected
34
* methods of all ancestor classes and interfaces
35
* @run main CheckOverrides
36
*/
37
public class CheckOverrides {
38
39
public static void main(String[] args) {
40
Set<MethodSignature> pMethodSignatures =
41
Stream.of(Properties.class.getDeclaredMethods())
42
.filter(CheckOverrides::isMethodOfInterest)
43
.map(MethodSignature::new)
44
.collect(Collectors.toSet());
45
46
Map<MethodSignature, Method> unoverriddenMethods = new HashMap<>();
47
for (Class<?> superclass = Properties.class.getSuperclass();
48
superclass != Object.class;
49
superclass = superclass.getSuperclass()) {
50
Stream.of(superclass.getDeclaredMethods())
51
.filter(CheckOverrides::isMethodOfInterest)
52
.forEach(m -> unoverriddenMethods.putIfAbsent(new MethodSignature(m), m));
53
}
54
unoverriddenMethods.keySet().removeAll(pMethodSignatures);
55
56
if (!unoverriddenMethods.isEmpty()) {
57
throw new RuntimeException(
58
"The following methods should be overridden by Properties class:\n" +
59
unoverriddenMethods.values().stream()
60
.map(Method::toString)
61
.collect(Collectors.joining("\n ", " ", "\n"))
62
);
63
}
64
}
65
66
static boolean isMethodOfInterest(Method method) {
67
int mods = method.getModifiers();
68
return !Modifier.isStatic(mods) &&
69
(Modifier.isPublic(mods) || Modifier.isProtected(mods));
70
}
71
72
static class MethodSignature {
73
final Class<?> returnType;
74
final String name;
75
final Class<?>[] parameterTypes;
76
77
MethodSignature(Method method) {
78
this(method.getReturnType(), method.getName(), method.getParameterTypes());
79
}
80
81
private MethodSignature(Class<?> returnType, String name, Class<?>[] parameterTypes) {
82
this.returnType = returnType;
83
this.name = name;
84
this.parameterTypes = parameterTypes;
85
}
86
87
@Override
88
public boolean equals(Object o) {
89
if (this == o) return true;
90
if (o == null || getClass() != o.getClass()) return false;
91
MethodSignature that = (MethodSignature) o;
92
if (!returnType.equals(that.returnType)) return false;
93
if (!name.equals(that.name)) return false;
94
return Arrays.equals(parameterTypes, that.parameterTypes);
95
}
96
97
@Override
98
public int hashCode() {
99
int result = returnType.hashCode();
100
result = 31 * result + name.hashCode();
101
result = 31 * result + Arrays.hashCode(parameterTypes);
102
return result;
103
}
104
}
105
}
106
107
108