1
1
/*
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
18
4
*/
19
5
package net .minecraftforge .mappingverifier ;
20
6
24
10
import java .util .ArrayList ;
25
11
import java .util .Arrays ;
26
12
import java .util .Collection ;
13
+ import java .util .Collections ;
27
14
import java .util .HashMap ;
28
15
import java .util .HashSet ;
29
16
import java .util .List ;
30
17
import java .util .Map ;
31
18
import java .util .Queue ;
32
19
import java .util .Set ;
20
+ import java .util .TreeMap ;
21
+ import java .util .TreeSet ;
33
22
import java .util .function .Predicate ;
34
23
import java .util .stream .Collectors ;
35
24
import java .util .stream .Stream ;
@@ -58,17 +47,23 @@ public class InheratanceMap {
58
47
private Map <String , ClassNode > nodes = new HashMap <>();
59
48
private Map <String , Set <Method >> bouncers = new HashMap <>();
60
49
private Map <String , Set <Method >> toResolveBouncers = new HashMap <>();
50
+ private Set <Class > owned = new TreeSet <>();
51
+ private Set <Class > ownedView = Collections .unmodifiableSet (owned );
61
52
62
- public void processClass (InputStream data ) throws IOException {
53
+ public void processClass (InputStream data , boolean owned ) throws IOException {
63
54
ClassNode node = new ClassNode ();
64
55
ClassReader reader = new ClassReader (data );
65
56
reader .accept (node , 0 );
66
57
67
58
Class cls = getClass (node .name );
68
59
cls .parent = getClass (node .superName );
69
60
cls .wasRead = true ;
61
+ cls .owned = owned ;
70
62
cls .access = node .access ;
71
63
64
+ if (owned )
65
+ this .owned .add (cls );
66
+
72
67
for (String intf : node .interfaces )
73
68
cls .interfaces .add (getClass (intf ));
74
69
@@ -107,7 +102,7 @@ public void processClass(InputStream data) throws IOException {
107
102
}
108
103
}
109
104
}
110
-
105
+
111
106
for (Method m : bouncers .getOrDefault (cls .name , new HashSet <>())) {
112
107
addBouncer (cls , m );
113
108
}
@@ -125,7 +120,7 @@ private void addBouncer(Class cls, Method m) {
125
120
return ;
126
121
}
127
122
}
128
-
123
+
129
124
if (parent != null ) {
130
125
bouncers .computeIfAbsent (parent .name , (name ) -> new HashSet <>()).add (m );
131
126
}
@@ -151,6 +146,10 @@ public Stream<Class> getRead() {
151
146
return classes .values ().stream ().filter (e -> e .wasRead );
152
147
}
153
148
149
+ public Collection <Class > getOwned () {
150
+ return this .ownedView ;
151
+ }
152
+
154
153
public void resolve () {
155
154
classes .values ().stream ().forEach (this ::resolve );
156
155
}
@@ -189,7 +188,7 @@ private void resolve(Class cls) {
189
188
}
190
189
}
191
190
}
192
-
191
+
193
192
for (Method bounce : toResolveBouncers .getOrDefault (mtd .getKey (), new HashSet <>())) {
194
193
if (!mtd .overrides .isEmpty ()) {
195
194
bounce .overrides .addAll (mtd .overrides );
@@ -222,15 +221,19 @@ private void resolve(Class cls) {
222
221
cls .resolved = true ;
223
222
}
224
223
225
- public static class Class {
224
+ public static class Class implements Comparable < Class > {
226
225
private boolean resolved = false ;
227
226
private boolean wasRead = false ;
227
+ private boolean owned = false ;
228
228
private int access = 0 ;
229
229
private Class parent ;
230
230
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 );
234
237
private List <Class > stack = null ;
235
238
236
239
public Class (String name ) {
@@ -241,6 +244,10 @@ public boolean wasRead() {
241
244
return wasRead ;
242
245
}
243
246
247
+ public boolean isOwned () {
248
+ return owned ;
249
+ }
250
+
244
251
public int getAccess () {
245
252
return access ;
246
253
}
@@ -253,11 +260,28 @@ public Class getParent() {
253
260
return parent ;
254
261
}
255
262
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
+
256
275
@ Override
257
276
public String toString () {
258
277
return this .name + " [" + fields .size () + ", " + methods .size () + "]" ;
259
278
}
260
279
280
+ @ Override
281
+ public int hashCode () {
282
+ return this .name .hashCode ();
283
+ }
284
+
261
285
public Field getField (String name ) {
262
286
return fields .get (name );
263
287
}
@@ -291,9 +315,15 @@ public List<Class> getStack() {
291
315
}
292
316
return stack ;
293
317
}
318
+
319
+ @ Override
320
+ public int compareTo (Class o ) {
321
+ if (o == null ) return -1 ;
322
+ return this .name .compareTo (o .name );
323
+ }
294
324
}
295
325
296
- public static class Node {
326
+ public static class Node implements Comparable < Node > {
297
327
public final Class owner ;
298
328
public final String name ;
299
329
public final String desc ;
@@ -329,6 +359,16 @@ public int hashCode() {
329
359
public String toString () {
330
360
return Access .get (this .access ).name () + " " + this .owner .name + "/" + this .name + this .desc ;
331
361
}
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
+ }
332
372
}
333
373
334
374
public static class Field extends Node {
0 commit comments