-
Notifications
You must be signed in to change notification settings - Fork 115
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
Fix mapping stats not skipping anonymous classes #469
base: master
Are you sure you want to change the base?
Changes from all commits
f992016
2265309
fd22417
9cd4b78
68a8078
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cuchaz.enigma.analysis.index; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import com.google.common.collect.ArrayListMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
import cuchaz.enigma.translation.representation.entry.ClassDefEntry; | ||
import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
|
||
public class InnerClassIndex implements JarIndexer { | ||
private Multimap<ClassDefEntry, InnerClassData> innerClasses = ArrayListMultimap.create(); | ||
private Map<ClassDefEntry, OuterClassData> outerClassesData = new HashMap<>(); | ||
|
||
@Override | ||
public void indexInnerClass(ClassDefEntry classEntry, InnerClassData innerClassData) { | ||
innerClasses.put(classEntry, innerClassData); | ||
} | ||
|
||
@Override | ||
public void indexOuterClass(ClassDefEntry classEntry, OuterClassData outerClassData) { | ||
outerClassesData.put(classEntry, outerClassData); | ||
} | ||
|
||
private Optional<Map.Entry<ClassDefEntry, InnerClassData>> findInnerClassEntry(ClassEntry classEntry) { | ||
return innerClasses.entries().stream().filter(entry -> entry.getValue().name().equals(classEntry.getFullName())).findFirst(); | ||
} | ||
|
||
public boolean isInnerClass(ClassEntry classEntry) { | ||
return findInnerClassEntry(classEntry).isPresent(); | ||
} | ||
|
||
public InnerClassData getInnerClassData(ClassEntry classEntry) { | ||
return findInnerClassEntry(classEntry).map(Map.Entry::getValue).orElse(null); | ||
} | ||
|
||
public ClassDefEntry getOuterClass(ClassEntry classEntry) { | ||
return findInnerClassEntry(classEntry).map(Map.Entry::getKey).orElse(null); | ||
} | ||
|
||
private Optional<Map.Entry<ClassDefEntry, OuterClassData>> findOuterClassDataEntry(ClassEntry classEntry) { | ||
return outerClassesData.entrySet().stream().filter(entry -> entry.getKey().equals(classEntry)).findFirst(); | ||
} | ||
|
||
public boolean hasOuterClassData(ClassEntry classEntry) { | ||
return findOuterClassDataEntry(classEntry).isPresent(); | ||
} | ||
|
||
public OuterClassData getOuterClassData(ClassEntry classEntry) { | ||
return findOuterClassDataEntry(classEntry).map(Map.Entry::getValue).orElse(null); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,28 @@ default void indexFieldReference(MethodDefEntry callerEntry, FieldEntry referenc | |
default void indexLambda(MethodDefEntry callerEntry, Lambda lambda, ReferenceTargetType targetType) { | ||
} | ||
|
||
default void indexInnerClass(ClassDefEntry classEntry, InnerClassData innerClassData) { | ||
} | ||
|
||
default void indexOuterClass(ClassDefEntry classEntry, OuterClassData outerClassData) { | ||
} | ||
|
||
default void processIndex(JarIndex index) { | ||
} | ||
|
||
record InnerClassData(String name, String innerName, String outerName, int access) { | ||
public boolean hasInnerName() { | ||
return innerName != null; | ||
} | ||
|
||
public boolean hasOuterName() { | ||
return outerName != null; | ||
} | ||
} | ||
|
||
record OuterClassData(String owner, String name, String descriptor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These names are wrong names from ASM, should've been like |
||
public boolean hasEnclosingMethod() { | ||
return name != null && descriptor != null; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This thing is wrong; we don't want to record one map entry for every
MethodHandles.Lookup
reference. To check if a class is an anonymous class, simply check itsEnclosingMethods
https://docs.oracle.com/javase/specs/jvms/se19/html/jvms-4.html#jvms-4.7.7 which asm somehow calls "OuterClass" and describes it incorrectly