Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inner classes are not merged #1

Open
jaredlll08 opened this issue Sep 21, 2023 · 0 comments
Open

Inner classes are not merged #1

jaredlll08 opened this issue Sep 21, 2023 · 0 comments

Comments

@jaredlll08
Copy link

jaredlll08 commented Sep 21, 2023

I am trying to merge Create and a Create Fabric (remapped from intermediary to moj) and am running into an issue with this inner class:
https://github.com/Fabricators-of-Create/Create/blob/mc1.18/fabric/dev/src/main/java/com/simibubi/create/content/processing/recipe/ProcessingRecipeBuilder.java#L226
https://github.com/Creators-of-Create/Create/blob/mc1.18/dev/src/main/java/com/simibubi/create/content/processing/recipe/ProcessingRecipeBuilder.java#L213

It is exactly the same, so it should be there, however it is not included at all.

EDIT:
This patch appears to work for this, but I don't believe I have a situation where A has an inner class that B doesn't have, or a situation where A's inner class has a different signature than B's inner class.

diff --git a/src/main/java/agency/highlysuspect/crossroad/IntersectingClassVisitor.java b/src/main/java/agency/highlysuspect/crossroad/IntersectingClassVisitor.java
index c45d833..0f80a13 100644
--- a/src/main/java/agency/highlysuspect/crossroad/IntersectingClassVisitor.java
+++ b/src/main/java/agency/highlysuspect/crossroad/IntersectingClassVisitor.java
@@ -5,8 +5,6 @@ import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.FieldVisitor;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.signature.SignatureReader;
-import org.objectweb.asm.signature.SignatureVisitor;
 import org.objectweb.asm.tree.AnnotationNode;
 import org.objectweb.asm.tree.FieldNode;
 import org.objectweb.asm.tree.MethodNode;
@@ -20,7 +18,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
-import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 public class IntersectingClassVisitor extends ClassVisitor implements Opcodes {
@@ -36,6 +33,7 @@ public class IntersectingClassVisitor extends ClassVisitor implements Opcodes {
 	private String signature;
 	private String superName;
 	private final Set<String> interfaces = new LinkedHashSet<>();
+    private final Map<InnerClass, Integer> innerclasses = new LinkedHashMap<>();
 	
 	//this is a map from "annotations" to "number of times i've seen this annotation"
 	//n.b. this fails for repeatable annotations
@@ -165,10 +163,15 @@ public class IntersectingClassVisitor extends ClassVisitor implements Opcodes {
 			}
 		};
 	}
-	
-	public void accept(ClassVisitor out) {
+    
+    @Override
+    public void visitInnerClass(String name, String outerName, String innerName, int access) {
+        incr(innerclasses, new InnerClass(name, outerName, innerName, access));
+    }
+    
+    public void accept(ClassVisitor out) {
 		out.visit(version, access, name, signature, superName, interfaces.toArray(new String[0]));
-		
+        filter(innerclasses, classesSeen).forEach(innerclass -> innerclass.accept(out));
 		//for some reason this accept() method takes a methodvisitor instead of a cv
 		//mayb that "visible" parameter which isn't actually stored on the annotation node
 		//grm
@@ -193,4 +196,61 @@ public class IntersectingClassVisitor extends ClassVisitor implements Opcodes {
 			.map(Map.Entry::getKey)
 			.collect(Collectors.toList());
 	}
+    
+    private static class InnerClass {
+        private final String name;
+        private final String outerName;
+        private final String innerName;
+        private final int access;
+        
+        public InnerClass(String name, String outerName, String innerName, int access) {
+            
+            this.name = name;
+            this.outerName = outerName;
+            this.innerName = innerName;
+            this.access = access;
+        }
+        
+        public void accept(ClassVisitor cv){
+            cv.visitInnerClass(this.name(), this.outerName(), this.innerName(), this.access());
+        }
+        
+        public String name() {
+            
+            return name;
+        }
+        
+        public String outerName() {
+            
+            return outerName;
+        }
+        
+        public String innerName() {
+            
+            return innerName;
+        }
+        
+        public int access() {
+            
+            return access;
+        }
+        
+        @Override
+        public boolean equals(Object o) {
+            
+            if(this == o)
+                return true;
+            if(o == null || getClass() != o.getClass())
+                return false;
+            InnerClass that = (InnerClass) o;
+            return access == that.access && Objects.equals(name, that.name) && Objects.equals(outerName, that.outerName) && Objects.equals(innerName, that.innerName);
+        }
+        
+        @Override
+        public int hashCode() {
+            
+            return Objects.hash(name, outerName, innerName, access);
+        }
+        
+    }
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant