Skip to content

Commit af8ee20

Browse files
committed
Code cleanup
1 parent 03b28ee commit af8ee20

File tree

9 files changed

+256
-292
lines changed

9 files changed

+256
-292
lines changed

LICENSE-header.txt

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,2 @@
1-
Mapping Verifier
2-
Copyright (c) 2016-2020.
3-
4-
This library is free software; you can redistribute it and/or
5-
modify it under the terms of the GNU Lesser General Public
6-
License as published by the Free Software Foundation version 2.1
7-
of the License.
8-
9-
This library is distributed in the hope that it will be useful,
10-
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12-
Lesser General Public License for more details.
13-
14-
You should have received a copy of the GNU Lesser General Public
15-
License along with this library; if not, write to the Free Software
16-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1+
Copyright (c) Forge Development LLC
2+
SPDX-License-Identifier: LGPL-2.1-only

src/main/java/net/minecraftforge/mappingverifier/AccessLevels.java

+21-32
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
11
/*
2-
* Mapping Verifier
3-
* Copyright (c) 2016-2020.
4-
*
5-
* This library is free software; you can redistribute it and/or
6-
* modify it under the terms of the GNU Lesser General Public
7-
* License as published by the Free Software Foundation version 2.1
8-
* of the License.
9-
*
10-
* This library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
* Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public
16-
* License along with this library; if not, write to the Free Software
17-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
184
*/
195
package net.minecraftforge.mappingverifier;
206

217
import java.util.ArrayDeque;
228
import java.util.Deque;
239
import java.util.HashSet;
10+
import java.util.List;
2411
import java.util.Set;
2512
import java.util.function.Function;
13+
import java.util.stream.Collectors;
2614

2715
import org.objectweb.asm.Opcodes;
2816
import org.objectweb.asm.tree.AbstractInsnNode;
2917
import org.objectweb.asm.tree.ClassNode;
3018
import org.objectweb.asm.tree.FieldInsnNode;
3119
import org.objectweb.asm.tree.MethodInsnNode;
20+
import org.objectweb.asm.tree.MethodNode;
3221
import org.objectweb.asm.tree.TypeInsnNode;
3322
import net.minecraftforge.mappingverifier.InheratanceMap.Class;
3423
import net.minecraftforge.mappingverifier.InheratanceMap.Node;
@@ -43,26 +32,28 @@ protected AccessLevels(MappingVerifier verifier) {
4332
public boolean process() {
4433
InheratanceMap inh = verifier.getInheratance();
4534
IMappingFile map = verifier.getMappings();
46-
return inh.getRead()
47-
.sorted((o1, o2) -> o1.name.compareTo(o2.name))
48-
.map(cls -> {
35+
36+
boolean success = true;
37+
for (Class cls : inh.getOwned()) {
4938
Main.LOG.fine(" Processing: " + map.remapClass(cls.name));
5039
ClassNode node = inh.getNode(cls.name);
5140

5241
if (node == null) {
5342
error(" Missing node: " + cls.name);
54-
return false; //Does this ever happen?
43+
success = false;
44+
continue; //Does this ever happen?
5545
}
5646

5747
Set<String> warned = new HashSet<>();
5848

5949
String newCls = map.remapClass(cls.name);
6050
String pkg = packageName(newCls);
61-
boolean success = node.methods.stream().sequential()
62-
.sorted((o1, o2) -> o1.name.equals(o2.name) ? o1.desc.compareTo(o2.desc) : o1.name.compareTo(o2.name))
63-
.map(mt -> {
64-
boolean inner_success = true;
6551

52+
List<MethodNode> methods = node.methods.stream().sequential()
53+
.sorted((o1, o2) -> o1.name.equals(o2.name) ? o1.desc.compareTo(o2.desc) : o1.name.compareTo(o2.name))
54+
.collect(Collectors.toList());
55+
56+
for (MethodNode mt : methods) {
6657
for (AbstractInsnNode isn : mt.instructions.toArray()) {
6758
if (isn instanceof FieldInsnNode) {
6859
FieldInsnNode field = (FieldInsnNode)isn;
@@ -93,7 +84,7 @@ public boolean process() {
9384
boolean isPackage = pkg.equals(packageName(newOwner));
9485
boolean isSubclass = cls.getStack().contains(target.owner);
9586

96-
inner_success &= canAccess(newCls, newOwner + "/" + newField, target.access, isPackage, isSubclass, isSelf, warned);
87+
success &= canAccess(newCls, newOwner + "/" + newField, target.access, isPackage, isSubclass, isSelf, warned);
9788
} else if (isn instanceof MethodInsnNode) {
9889
MethodInsnNode method = (MethodInsnNode)isn;
9990

@@ -123,7 +114,7 @@ public boolean process() {
123114

124115
boolean isPackage = pkg.equals(packageName(newOwner));
125116
boolean isSubclass = cls.getStack().contains(target.owner);
126-
inner_success &= canAccess(newCls, newOwner + "/" + newMethod + newDesc, target.access, isPackage, isSubclass, isSelf, warned);
117+
success &= canAccess(newCls, newOwner + "/" + newMethod + newDesc, target.access, isPackage, isSubclass, isSelf, warned);
127118
} else if (isn instanceof TypeInsnNode) {
128119
String obfed = ((TypeInsnNode)isn).desc;
129120
boolean isSelf = obfed.equals(node.name);
@@ -138,15 +129,13 @@ public boolean process() {
138129
String newOwner = map.remapClass(obfed);
139130
boolean isPackage = pkg.equals(packageName(newOwner));
140131
boolean isSubclass = cls.getStack().contains(inh.getClass(obfed));
141-
inner_success &= canAccess(newCls, newOwner, owner.getAccess(), isPackage, isSubclass, isSelf, warned);
132+
success &= canAccess(newCls, newOwner, owner.getAccess(), isPackage, isSubclass, isSelf, warned);
142133
}
143134
}
135+
}
136+
}
144137

145-
return inner_success;
146-
}).reduce(true, (a,b) -> a && b);
147-
148-
return success;
149-
}).reduce(true, (a,b) -> a && b);
138+
return success;
150139
}
151140

152141
private String packageName(String clsName) {

src/main/java/net/minecraftforge/mappingverifier/IVerifier.java

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
/*
2-
* Mapping Verifier
3-
* Copyright (c) 2016-2020.
4-
*
5-
* This library is free software; you can redistribute it and/or
6-
* modify it under the terms of the GNU Lesser General Public
7-
* License as published by the Free Software Foundation version 2.1
8-
* of the License.
9-
*
10-
* This library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
* Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public
16-
* License along with this library; if not, write to the Free Software
17-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
184
*/
195
package net.minecraftforge.mappingverifier;
206

src/main/java/net/minecraftforge/mappingverifier/InheratanceMap.java

+65-25
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
/*
2-
* Mapping Verifier
3-
* Copyright (c) 2016-2020.
4-
*
5-
* This library is free software; you can redistribute it and/or
6-
* modify it under the terms of the GNU Lesser General Public
7-
* License as published by the Free Software Foundation version 2.1
8-
* of the License.
9-
*
10-
* This library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
* Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public
16-
* License along with this library; if not, write to the Free Software
17-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
184
*/
195
package net.minecraftforge.mappingverifier;
206

@@ -24,12 +10,15 @@
2410
import java.util.ArrayList;
2511
import java.util.Arrays;
2612
import java.util.Collection;
13+
import java.util.Collections;
2714
import java.util.HashMap;
2815
import java.util.HashSet;
2916
import java.util.List;
3017
import java.util.Map;
3118
import java.util.Queue;
3219
import java.util.Set;
20+
import java.util.TreeMap;
21+
import java.util.TreeSet;
3322
import java.util.function.Predicate;
3423
import java.util.stream.Collectors;
3524
import java.util.stream.Stream;
@@ -58,17 +47,23 @@ public class InheratanceMap {
5847
private Map<String, ClassNode> nodes = new HashMap<>();
5948
private Map<String, Set<Method>> bouncers = new HashMap<>();
6049
private Map<String, Set<Method>> toResolveBouncers = new HashMap<>();
50+
private Set<Class> owned = new TreeSet<>();
51+
private Set<Class> ownedView = Collections.unmodifiableSet(owned);
6152

62-
public void processClass(InputStream data) throws IOException {
53+
public void processClass(InputStream data, boolean owned) throws IOException {
6354
ClassNode node = new ClassNode();
6455
ClassReader reader = new ClassReader(data);
6556
reader.accept(node, 0);
6657

6758
Class cls = getClass(node.name);
6859
cls.parent = getClass(node.superName);
6960
cls.wasRead = true;
61+
cls.owned = owned;
7062
cls.access = node.access;
7163

64+
if (owned)
65+
this.owned.add(cls);
66+
7267
for (String intf : node.interfaces)
7368
cls.interfaces.add(getClass(intf));
7469

@@ -107,7 +102,7 @@ public void processClass(InputStream data) throws IOException {
107102
}
108103
}
109104
}
110-
105+
111106
for (Method m : bouncers.getOrDefault(cls.name, new HashSet<>())) {
112107
addBouncer(cls, m);
113108
}
@@ -125,7 +120,7 @@ private void addBouncer(Class cls, Method m) {
125120
return;
126121
}
127122
}
128-
123+
129124
if (parent != null) {
130125
bouncers.computeIfAbsent(parent.name, (name) -> new HashSet<>()).add(m);
131126
}
@@ -151,6 +146,10 @@ public Stream<Class> getRead() {
151146
return classes.values().stream().filter(e -> e.wasRead);
152147
}
153148

149+
public Collection<Class> getOwned() {
150+
return this.ownedView;
151+
}
152+
154153
public void resolve() {
155154
classes.values().stream().forEach(this::resolve);
156155
}
@@ -189,7 +188,7 @@ private void resolve(Class cls) {
189188
}
190189
}
191190
}
192-
191+
193192
for (Method bounce : toResolveBouncers.getOrDefault(mtd.getKey(), new HashSet<>())) {
194193
if (!mtd.overrides.isEmpty()) {
195194
bounce.overrides.addAll(mtd.overrides);
@@ -222,15 +221,19 @@ private void resolve(Class cls) {
222221
cls.resolved = true;
223222
}
224223

225-
public static class Class {
224+
public static class Class implements Comparable<Class> {
226225
private boolean resolved = false;
227226
private boolean wasRead = false;
227+
private boolean owned = false;
228228
private int access = 0;
229229
private Class parent;
230230
public final String name;
231-
public final Map<String, Field> fields = new HashMap<>();
232-
public final Map<String, Method> methods = new HashMap<>();
233-
public final List<Class> interfaces = new ArrayList<>();
231+
private final Map<String, Field> fields = new TreeMap<>();
232+
private final Map<String, Field> fieldsView = Collections.unmodifiableMap(fields);
233+
private final Map<String, Method> methods = new TreeMap<>();
234+
private final Map<String, Method> methodsView = Collections.unmodifiableMap(methods);
235+
private final List<Class> interfaces = new ArrayList<>();
236+
private final List<Class> interfacesView = Collections.unmodifiableList(interfaces);
234237
private List<Class> stack = null;
235238

236239
public Class(String name) {
@@ -241,6 +244,10 @@ public boolean wasRead() {
241244
return wasRead;
242245
}
243246

247+
public boolean isOwned() {
248+
return owned;
249+
}
250+
244251
public int getAccess() {
245252
return access;
246253
}
@@ -253,11 +260,28 @@ public Class getParent() {
253260
return parent;
254261
}
255262

263+
public Map<String, Field> getFields() {
264+
return this.fieldsView;
265+
}
266+
267+
public Map<String, Method> getMethods() {
268+
return this.methodsView;
269+
}
270+
271+
public Collection<Class> getInterfaces() {
272+
return this.interfacesView;
273+
}
274+
256275
@Override
257276
public String toString() {
258277
return this.name + " [" + fields.size() + ", " + methods.size() + "]";
259278
}
260279

280+
@Override
281+
public int hashCode() {
282+
return this.name.hashCode();
283+
}
284+
261285
public Field getField(String name) {
262286
return fields.get(name);
263287
}
@@ -291,9 +315,15 @@ public List<Class> getStack() {
291315
}
292316
return stack;
293317
}
318+
319+
@Override
320+
public int compareTo(Class o) {
321+
if (o == null) return -1;
322+
return this.name.compareTo(o.name);
323+
}
294324
}
295325

296-
public static class Node {
326+
public static class Node implements Comparable<Node> {
297327
public final Class owner;
298328
public final String name;
299329
public final String desc;
@@ -329,6 +359,16 @@ public int hashCode() {
329359
public String toString() {
330360
return Access.get(this.access).name() + " " + this.owner.name + "/" + this.name + this.desc;
331361
}
362+
363+
@Override
364+
public int compareTo(Node o) {
365+
if (o == null) return -1;
366+
int ret = this.owner.compareTo(o.owner);
367+
if (ret != 0) return ret;
368+
ret = this.name.compareTo(o.name);
369+
if (ret != 0) return ret;
370+
return this.desc.compareTo(o.desc);
371+
}
332372
}
333373

334374
public static class Field extends Node {

0 commit comments

Comments
 (0)