From 64c359d3c1d2347001e5c6becb1d7561457f52cc Mon Sep 17 00:00:00 2001 From: lclc98 Date: Sat, 2 Jul 2016 18:04:57 +1000 Subject: Renamed Fields --- .../java/cuchaz/enigma/convert/ClassForest.java | 18 +-- .../cuchaz/enigma/convert/ClassIdentifier.java | 28 ++-- .../java/cuchaz/enigma/convert/ClassIdentity.java | 167 ++++++++++----------- .../java/cuchaz/enigma/convert/ClassMatch.java | 8 +- .../java/cuchaz/enigma/convert/ClassMatches.java | 2 +- .../java/cuchaz/enigma/convert/ClassMatching.java | 2 +- .../java/cuchaz/enigma/convert/ClassNamer.java | 16 +- 7 files changed, 117 insertions(+), 124 deletions(-) (limited to 'src/main/java/cuchaz/enigma/convert') diff --git a/src/main/java/cuchaz/enigma/convert/ClassForest.java b/src/main/java/cuchaz/enigma/convert/ClassForest.java index 7123bbf..b08d48f 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassForest.java +++ b/src/main/java/cuchaz/enigma/convert/ClassForest.java @@ -20,12 +20,12 @@ import cuchaz.enigma.mapping.ClassEntry; public class ClassForest { - private ClassIdentifier m_identifier; - private Multimap m_forest; + private ClassIdentifier identifier; + private Multimap forest; public ClassForest(ClassIdentifier identifier) { - m_identifier = identifier; - m_forest = HashMultimap.create(); + this.identifier = identifier; + this.forest = HashMultimap.create(); } public void addAll(Iterable entries) { @@ -36,25 +36,25 @@ public class ClassForest { public void add(ClassEntry entry) { try { - m_forest.put(m_identifier.identify(entry), entry); + this.forest.put(this.identifier.identify(entry), entry); } catch (ClassNotFoundException ex) { throw new Error("Unable to find class " + entry.getName()); } } public Collection identities() { - return m_forest.keySet(); + return this.forest.keySet(); } public Collection classes() { - return m_forest.values(); + return this.forest.values(); } public Collection getClasses(ClassIdentity identity) { - return m_forest.get(identity); + return this.forest.get(identity); } public boolean containsIdentity(ClassIdentity identity) { - return m_forest.containsKey(identity); + return this.forest.containsKey(identity); } } diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java b/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java index e1153a6..cc7f25b 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java +++ b/src/main/java/cuchaz/enigma/convert/ClassIdentifier.java @@ -24,30 +24,30 @@ import javassist.CtClass; public class ClassIdentifier { - private JarIndex m_index; - private SidedClassNamer m_namer; - private boolean m_useReferences; - private TranslatingTypeLoader m_loader; - private Map m_cache; + private JarIndex index; + private SidedClassNamer namer; + private boolean useReferences; + private TranslatingTypeLoader loader; + private Map cache; public ClassIdentifier(JarFile jar, JarIndex index, SidedClassNamer namer, boolean useReferences) { - m_index = index; - m_namer = namer; - m_useReferences = useReferences; - m_loader = new TranslatingTypeLoader(jar, index); - m_cache = Maps.newHashMap(); + this.index = index; + this.namer = namer; + this.useReferences = useReferences; + this.loader = new TranslatingTypeLoader(jar, index); + this.cache = Maps.newHashMap(); } public ClassIdentity identify(ClassEntry classEntry) throws ClassNotFoundException { - ClassIdentity identity = m_cache.get(classEntry); + ClassIdentity identity = this.cache.get(classEntry); if (identity == null) { - CtClass c = m_loader.loadClass(classEntry.getName()); + CtClass c = this.loader.loadClass(classEntry.getName()); if (c == null) { throw new ClassNotFoundException(classEntry.getName()); } - identity = new ClassIdentity(c, m_namer, m_index, m_useReferences); - m_cache.put(classEntry, identity); + identity = new ClassIdentity(c, this.namer, this.index, this.useReferences); + this.cache.put(classEntry, identity); } return identity; } diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java index 76c48ab..2317a3d 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java +++ b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java @@ -36,18 +36,18 @@ import javassist.expr.*; public class ClassIdentity { - private ClassEntry m_classEntry; - private SidedClassNamer m_namer; - private Multiset m_fields; - private Multiset m_methods; - private Multiset m_constructors; - private String m_staticInitializer; - private String m_extends; - private Multiset m_implements; - private Set m_stringLiterals; - private Multiset m_implementations; - private Multiset m_references; - private String m_outer; + private ClassEntry classEntry; + private SidedClassNamer namer; + private Multiset fields; + private Multiset methods; + private Multiset constructors; + private String staticInitializer; + private String extendz; + private Multiset implementz; + private Set stringLiterals; + private Multiset implementations; + private Multiset references; + private String outer; private final ClassNameReplacer m_classNameReplacer = new ClassNameReplacer() { @@ -63,13 +63,13 @@ public class ClassIdentity { } // is this class ourself? - if (className.equals(m_classEntry.getName())) { + if (className.equals(classEntry.getName())) { return "CSelf"; } // try the namer - if (m_namer != null) { - String newName = m_namer.getName(className); + if (namer != null) { + String newName = namer.getName(className); if (newName != null) { return newName; } @@ -88,58 +88,58 @@ public class ClassIdentity { }; public ClassIdentity(CtClass c, SidedClassNamer namer, JarIndex index, boolean useReferences) { - m_namer = namer; + this.namer = namer; // stuff from the bytecode - m_classEntry = EntryFactory.getClassEntry(c); - m_fields = HashMultiset.create(); + this.classEntry = EntryFactory.getClassEntry(c); + this.fields = HashMultiset.create(); for (CtField field : c.getDeclaredFields()) { - m_fields.add(scrubType(field.getSignature())); + this.fields.add(scrubType(field.getSignature())); } - m_methods = HashMultiset.create(); + this.methods = HashMultiset.create(); for (CtMethod method : c.getDeclaredMethods()) { - m_methods.add(scrubSignature(method.getSignature()) + "0x" + getBehaviorSignature(method)); + this.methods.add(scrubSignature(method.getSignature()) + "0x" + getBehaviorSignature(method)); } - m_constructors = HashMultiset.create(); + this.constructors = HashMultiset.create(); for (CtConstructor constructor : c.getDeclaredConstructors()) { - m_constructors.add(scrubSignature(constructor.getSignature()) + "0x" + getBehaviorSignature(constructor)); + this.constructors.add(scrubSignature(constructor.getSignature()) + "0x" + getBehaviorSignature(constructor)); } - m_staticInitializer = ""; + this.staticInitializer = ""; if (c.getClassInitializer() != null) { - m_staticInitializer = getBehaviorSignature(c.getClassInitializer()); + this.staticInitializer = getBehaviorSignature(c.getClassInitializer()); } - m_extends = ""; + this.extendz = ""; if (c.getClassFile().getSuperclass() != null) { - m_extends = scrubClassName(Descriptor.toJvmName(c.getClassFile().getSuperclass())); + this.extendz = scrubClassName(Descriptor.toJvmName(c.getClassFile().getSuperclass())); } - m_implements = HashMultiset.create(); + this.implementz = HashMultiset.create(); for (String interfaceName : c.getClassFile().getInterfaces()) { - m_implements.add(scrubClassName(Descriptor.toJvmName(interfaceName))); + this.implementz.add(scrubClassName(Descriptor.toJvmName(interfaceName))); } - m_stringLiterals = Sets.newHashSet(); + this.stringLiterals = Sets.newHashSet(); ConstPool constants = c.getClassFile().getConstPool(); for (int i = 1; i < constants.getSize(); i++) { if (constants.getTag(i) == ConstPool.CONST_String) { - m_stringLiterals.add(constants.getStringInfo(i)); + this.stringLiterals.add(constants.getStringInfo(i)); } } // stuff from the jar index - m_implementations = HashMultiset.create(); - ClassImplementationsTreeNode implementationsNode = index.getClassImplementations(null, m_classEntry); + this.implementations = HashMultiset.create(); + ClassImplementationsTreeNode implementationsNode = index.getClassImplementations(null, this.classEntry); if (implementationsNode != null) { @SuppressWarnings("unchecked") Enumeration implementations = implementationsNode.children(); while (implementations.hasMoreElements()) { ClassImplementationsTreeNode node = implementations.nextElement(); - m_implementations.add(scrubClassName(node.getClassEntry().getName())); + this.implementations.add(scrubClassName(node.getClassEntry().getName())); } } - m_references = HashMultiset.create(); + this.references = HashMultiset.create(); if (useReferences) { for (CtField field : c.getDeclaredFields()) { FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); @@ -151,79 +151,79 @@ public class ClassIdentity { } } - m_outer = null; - if (m_classEntry.isInnerClass()) { - m_outer = m_classEntry.getOuterClassName(); + this.outer = null; + if (this.classEntry.isInnerClass()) { + this.outer = this.classEntry.getOuterClassName(); } } private void addReference(EntryReference reference) { if (reference.context.getSignature() != null) { - m_references.add(String.format("%s_%s", + this.references.add(String.format("%s_%s", scrubClassName(reference.context.getClassName()), scrubSignature(reference.context.getSignature()) )); } else { - m_references.add(String.format("%s_", + this.references.add(String.format("%s_", scrubClassName(reference.context.getClassName()) )); } } public ClassEntry getClassEntry() { - return m_classEntry; + return this.classEntry; } @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append("class: "); - buf.append(m_classEntry.getName()); + buf.append(this.classEntry.getName()); buf.append(" "); buf.append(hashCode()); buf.append("\n"); - for (String field : m_fields) { + for (String field : this.fields) { buf.append("\tfield "); buf.append(field); buf.append("\n"); } - for (String method : m_methods) { + for (String method : this.methods) { buf.append("\tmethod "); buf.append(method); buf.append("\n"); } - for (String constructor : m_constructors) { + for (String constructor : this.constructors) { buf.append("\tconstructor "); buf.append(constructor); buf.append("\n"); } - if (m_staticInitializer.length() > 0) { + if (this.staticInitializer.length() > 0) { buf.append("\tinitializer "); - buf.append(m_staticInitializer); + buf.append(this.staticInitializer); buf.append("\n"); } - if (m_extends.length() > 0) { + if (this.extendz.length() > 0) { buf.append("\textends "); - buf.append(m_extends); + buf.append(this.extendz); buf.append("\n"); } - for (String interfaceName : m_implements) { + for (String interfaceName : this.implementz) { buf.append("\timplements "); buf.append(interfaceName); buf.append("\n"); } - for (String implementation : m_implementations) { + for (String implementation : this.implementations) { buf.append("\timplemented by "); buf.append(implementation); buf.append("\n"); } - for (String reference : m_references) { + for (String reference : this.references) { buf.append("\treference "); buf.append(reference); buf.append("\n"); } buf.append("\touter "); - buf.append(m_outer); + buf.append(this.outer); buf.append("\n"); return buf.toString(); } @@ -253,7 +253,7 @@ public class ClassIdentity { } private boolean isClassMatchedUniquely(String className) { - return m_namer != null && m_namer.getName(Descriptor.toJvmName(className)) != null; + return this.namer != null && this.namer.getName(Descriptor.toJvmName(className)) != null; } private String getBehaviorSignature(CtBehavior behavior) { @@ -361,56 +361,53 @@ public class ClassIdentity { @Override public boolean equals(Object other) { - if (other instanceof ClassIdentity) { - return equals((ClassIdentity) other); - } - return false; + return other instanceof ClassIdentity && equals((ClassIdentity) other); } public boolean equals(ClassIdentity other) { - return m_fields.equals(other.m_fields) - && m_methods.equals(other.m_methods) - && m_constructors.equals(other.m_constructors) - && m_staticInitializer.equals(other.m_staticInitializer) - && m_extends.equals(other.m_extends) - && m_implements.equals(other.m_implements) - && m_implementations.equals(other.m_implementations) - && m_references.equals(other.m_references); + return this.fields.equals(other.fields) + && this.methods.equals(other.methods) + && this.constructors.equals(other.constructors) + && this.staticInitializer.equals(other.staticInitializer) + && this.extendz.equals(other.extendz) + && this.implementz.equals(other.implementz) + && this.implementations.equals(other.implementations) + && this.references.equals(other.references); } @Override public int hashCode() { List objs = Lists.newArrayList(); - objs.addAll(m_fields); - objs.addAll(m_methods); - objs.addAll(m_constructors); - objs.add(m_staticInitializer); - objs.add(m_extends); - objs.addAll(m_implements); - objs.addAll(m_implementations); - objs.addAll(m_references); + objs.addAll(this.fields); + objs.addAll(this.methods); + objs.addAll(this.constructors); + objs.add(this.staticInitializer); + objs.add(this.extendz); + objs.addAll(this.implementz); + objs.addAll(this.implementations); + objs.addAll(this.references); return Util.combineHashesOrdered(objs); } public int getMatchScore(ClassIdentity other) { - return 2 * getNumMatches(m_extends, other.m_extends) - + 2 * getNumMatches(m_outer, other.m_outer) - + 2 * getNumMatches(m_implements, other.m_implements) - + getNumMatches(m_stringLiterals, other.m_stringLiterals) - + getNumMatches(m_fields, other.m_fields) - + getNumMatches(m_methods, other.m_methods) - + getNumMatches(m_constructors, other.m_constructors); + return 2 * getNumMatches(this.extendz, other.extendz) + + 2 * getNumMatches(this.outer, other.outer) + + 2 * getNumMatches(this.implementz, other.implementz) + + getNumMatches(this.stringLiterals, other.stringLiterals) + + getNumMatches(this.fields, other.fields) + + getNumMatches(this.methods, other.methods) + + getNumMatches(this.constructors, other.constructors); } public int getMaxMatchScore() { - return 2 + 2 + 2 * m_implements.size() + m_stringLiterals.size() + m_fields.size() + m_methods.size() + m_constructors.size(); + return 2 + 2 + 2 * this.implementz.size() + this.stringLiterals.size() + this.fields.size() + this.methods.size() + this.constructors.size(); } public boolean matches(CtClass c) { // just compare declaration counts - return m_fields.size() == c.getDeclaredFields().length - && m_methods.size() == c.getDeclaredMethods().length - && m_constructors.size() == c.getDeclaredConstructors().length; + return this.fields.size() == c.getDeclaredFields().length + && this.methods.size() == c.getDeclaredMethods().length + && this.constructors.size() == c.getDeclaredConstructors().length; } private int getNumMatches(Set a, Set b) { diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatch.java b/src/main/java/cuchaz/enigma/convert/ClassMatch.java index f3530ed..422529e 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatch.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatch.java @@ -75,14 +75,10 @@ public class ClassMatch { @Override public boolean equals(Object other) { - if (other instanceof ClassMatch) { - return equals((ClassMatch) other); - } - return false; + return other instanceof ClassMatch && equals((ClassMatch) other); } public boolean equals(ClassMatch other) { - return this.sourceClasses.equals(other.sourceClasses) - && this.destClasses.equals(other.destClasses); + return this.sourceClasses.equals(other.sourceClasses) && this.destClasses.equals(other.destClasses); } } diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatches.java b/src/main/java/cuchaz/enigma/convert/ClassMatches.java index 2c5f6a5..3a25435 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatches.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatches.java @@ -32,7 +32,7 @@ public class ClassMatches implements Iterable { Set m_unmatchedDestClasses; public ClassMatches() { - this(new ArrayList()); + this(new ArrayList<>()); } public ClassMatches(Collection matches) { diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatching.java b/src/main/java/cuchaz/enigma/convert/ClassMatching.java index 14f8e2a..9350ea7 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatching.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatching.java @@ -69,7 +69,7 @@ public class ClassMatching { for (ClassIdentity identity : m_destClasses.identities()) { if (!m_sourceClasses.containsIdentity(identity)) { matches.add(new ClassMatch( - new ArrayList(), + new ArrayList<>(), m_destClasses.getClasses(identity) )); } diff --git a/src/main/java/cuchaz/enigma/convert/ClassNamer.java b/src/main/java/cuchaz/enigma/convert/ClassNamer.java index f1d9820..e471c7d 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassNamer.java +++ b/src/main/java/cuchaz/enigma/convert/ClassNamer.java @@ -23,27 +23,27 @@ public class ClassNamer { String getName(String name); } - private Map m_sourceNames; - private Map m_destNames; + private Map sourceNames; + private Map destNames; public ClassNamer(BiMap mappings) { // convert the identity mappings to name maps - m_sourceNames = Maps.newHashMap(); - m_destNames = Maps.newHashMap(); + this.sourceNames = Maps.newHashMap(); + this.destNames = Maps.newHashMap(); int i = 0; for (Map.Entry entry : mappings.entrySet()) { String name = String.format("M%04d", i++); - m_sourceNames.put(entry.getKey().getName(), name); - m_destNames.put(entry.getValue().getName(), name); + this.sourceNames.put(entry.getKey().getName(), name); + this.destNames.put(entry.getValue().getName(), name); } } public String getSourceName(String name) { - return m_sourceNames.get(name); + return this.sourceNames.get(name); } public String getDestName(String name) { - return m_destNames.get(name); + return this.destNames.get(name); } public SidedClassNamer getSourceNamer() { -- cgit v1.2.3