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 */
195package net .minecraftforge .mappingverifier ;
206
2410import java .util .ArrayList ;
2511import java .util .Arrays ;
2612import java .util .Collection ;
13+ import java .util .Collections ;
2714import java .util .HashMap ;
2815import java .util .HashSet ;
2916import java .util .List ;
3017import java .util .Map ;
3118import java .util .Queue ;
3219import java .util .Set ;
20+ import java .util .TreeMap ;
21+ import java .util .TreeSet ;
3322import java .util .function .Predicate ;
3423import java .util .stream .Collectors ;
3524import 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