From 74edc74c2c7b3236f00bf92499bb884837673b7d Mon Sep 17 00:00:00 2001 From: lclc98 Date: Sat, 2 Jul 2016 20:13:13 +1000 Subject: Reformatting code --- src/main/java/cuchaz/enigma/CommandMain.java | 2 +- src/main/java/cuchaz/enigma/Constants.java | 8 +- src/main/java/cuchaz/enigma/ConvertMain.java | 46 ++-- src/main/java/cuchaz/enigma/Deobfuscator.java | 43 +--- .../java/cuchaz/enigma/MainFormatConverter.java | 18 +- .../java/cuchaz/enigma/TranslatingTypeLoader.java | 4 +- .../java/cuchaz/enigma/analysis/EntryRenamer.java | 20 +- src/main/java/cuchaz/enigma/analysis/JarIndex.java | 20 +- .../analysis/MethodImplementationsTreeNode.java | 4 +- .../enigma/analysis/MethodInheritanceTreeNode.java | 4 +- .../enigma/analysis/RelatedMethodChecker.java | 104 -------- .../java/cuchaz/enigma/analysis/SourceIndex.java | 4 +- .../cuchaz/enigma/analysis/TranslationIndex.java | 2 +- src/main/java/cuchaz/enigma/bytecode/InfoType.java | 5 +- .../enigma/bytecode/MethodParameterWriter.java | 2 +- .../enigma/bytecode/MethodParametersAttribute.java | 2 +- .../java/cuchaz/enigma/convert/ClassIdentity.java | 2 +- .../java/cuchaz/enigma/convert/ClassMatches.java | 4 +- .../java/cuchaz/enigma/convert/ClassMatching.java | 15 +- .../java/cuchaz/enigma/convert/FieldMatches.java | 151 ------------ .../cuchaz/enigma/convert/MappingsConverter.java | 47 ++-- .../java/cuchaz/enigma/convert/MatchesReader.java | 13 +- src/main/java/cuchaz/enigma/gui/AboutDialog.java | 8 +- .../cuchaz/enigma/gui/BoxHighlightPainter.java | 16 +- src/main/java/cuchaz/enigma/gui/BrowserCaret.java | 5 +- .../cuchaz/enigma/gui/ClassListCellRenderer.java | 36 --- .../java/cuchaz/enigma/gui/ClassMatchingGui.java | 263 ++++++++++----------- src/main/java/cuchaz/enigma/gui/ClassSelector.java | 16 +- .../cuchaz/enigma/gui/ClassSelectorClassNode.java | 19 +- .../enigma/gui/ClassSelectorPackageNode.java | 15 +- src/main/java/cuchaz/enigma/gui/CodeReader.java | 66 ++---- src/main/java/cuchaz/enigma/gui/CrashDialog.java | 24 +- .../enigma/gui/DeobfuscatedHighlightPainter.java | 1 - src/main/java/cuchaz/enigma/gui/Gui.java | 221 +++++------------ src/main/java/cuchaz/enigma/gui/GuiController.java | 212 +++++++---------- src/main/java/cuchaz/enigma/gui/GuiTricks.java | 8 +- .../java/cuchaz/enigma/gui/MemberMatchingGui.java | 86 ++----- .../enigma/gui/ObfuscatedHighlightPainter.java | 1 - .../cuchaz/enigma/gui/OtherHighlightPainter.java | 1 - .../java/cuchaz/enigma/gui/ProgressDialog.java | 54 ++--- .../java/cuchaz/enigma/gui/RenameListener.java | 17 -- .../java/cuchaz/enigma/gui/ScoredClassEntry.java | 7 +- .../cuchaz/enigma/gui/TokenListCellRenderer.java | 12 +- .../java/cuchaz/enigma/mapping/ArgumentEntry.java | 5 +- .../java/cuchaz/enigma/mapping/ClassMapping.java | 5 +- .../cuchaz/enigma/mapping/ConstructorEntry.java | 5 +- .../java/cuchaz/enigma/mapping/FieldMapping.java | 49 ++-- .../cuchaz/enigma/mapping/MappingsChecker.java | 7 - .../java/cuchaz/enigma/mapping/MappingsReader.java | 24 +- .../cuchaz/enigma/mapping/MappingsReaderOld.java | 2 +- .../cuchaz/enigma/mapping/MappingsRenamer.java | 8 +- .../java/cuchaz/enigma/mapping/MappingsWriter.java | 2 +- src/main/java/cuchaz/enigma/mapping/Signature.java | 5 +- .../cuchaz/enigma/mapping/SignatureUpdater.java | 13 +- .../java/cuchaz/enigma/mapping/Translator.java | 9 +- src/main/java/cuchaz/enigma/mapping/Type.java | 6 +- 56 files changed, 541 insertions(+), 1207 deletions(-) delete mode 100644 src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java delete mode 100644 src/main/java/cuchaz/enigma/convert/FieldMatches.java delete mode 100644 src/main/java/cuchaz/enigma/gui/ClassListCellRenderer.java delete mode 100644 src/main/java/cuchaz/enigma/gui/RenameListener.java (limited to 'src/main/java') diff --git a/src/main/java/cuchaz/enigma/CommandMain.java b/src/main/java/cuchaz/enigma/CommandMain.java index b715c6e2..8dfbe24d 100644 --- a/src/main/java/cuchaz/enigma/CommandMain.java +++ b/src/main/java/cuchaz/enigma/CommandMain.java @@ -79,7 +79,7 @@ public class CommandMain { } private static void printHelp() { - System.out.println(String.format("%s - %s", Constants.Name, Constants.Version)); + System.out.println(String.format("%s - %s", Constants.NAME, Constants.VERSION)); System.out.println("Usage:"); System.out.println("\tjava -cp enigma.jar cuchaz.enigma.CommandMain "); System.out.println("\twhere is one of:"); diff --git a/src/main/java/cuchaz/enigma/Constants.java b/src/main/java/cuchaz/enigma/Constants.java index 5d2c84bf..c6a58259 100644 --- a/src/main/java/cuchaz/enigma/Constants.java +++ b/src/main/java/cuchaz/enigma/Constants.java @@ -11,10 +11,10 @@ package cuchaz.enigma; public class Constants { - public static final String Name = "Enigma"; - public static final String Version = "0.2 - Beta"; - public static final String Url = "http://www.cuchazinteractive.com/enigma"; + public static final String NAME = "Enigma"; + public static final String VERSION = "0.2 - Beta"; + public static final String URL = "http://www.cuchazinteractive.com/enigma"; public static final int MiB = 1024 * 1024; // 1 mebibyte public static final int KiB = 1024; // 1 kebibyte - public static final String NonePackage = "none"; + public static final String NONE_PACKAGE = "none"; } diff --git a/src/main/java/cuchaz/enigma/ConvertMain.java b/src/main/java/cuchaz/enigma/ConvertMain.java index a68ab614..caa61545 100644 --- a/src/main/java/cuchaz/enigma/ConvertMain.java +++ b/src/main/java/cuchaz/enigma/ConvertMain.java @@ -76,7 +76,7 @@ public class ConvertMain { } private static void printHelp() { - System.out.println(String.format("%s - %s", Constants.Name, Constants.Version)); + System.out.println(String.format("%s - %s", Constants.NAME, Constants.VERSION)); System.out.println("Usage:"); System.out.println("\tjava -cp enigma.jar cuchaz.enigma.ConvertMain "); System.out.println("\tWhere is one of:"); @@ -121,14 +121,11 @@ public class ConvertMain { Deobfuscators deobfuscators = new Deobfuscators(sourceJar, destJar); deobfuscators.source.setMappings(mappings); System.out.println("Starting GUI..."); - new ClassMatchingGui(classMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new ClassMatchingGui.SaveListener() { - @Override - public void save(ClassMatches matches) { - try { - MatchesWriter.writeClasses(matches, classMatchesFile); - } catch (IOException ex) { - throw new Error(ex); - } + new ClassMatchingGui(classMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(matches -> { + try { + MatchesWriter.writeClasses(matches, classMatchesFile); + } catch (IOException ex) { + throw new Error(ex); } }); } @@ -185,14 +182,11 @@ public class ConvertMain { checker.dropBrokenMappings(destMappings); deobfuscators.dest.setMappings(destMappings); - new MemberMatchingGui<>(classMatches, fieldMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new MemberMatchingGui.SaveListener() { - @Override - public void save(MemberMatches matches) { - try { - MatchesWriter.writeMembers(matches, fieldMatchesFile); - } catch (IOException ex) { - throw new Error(ex); - } + new MemberMatchingGui<>(classMatches, fieldMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(matches -> { + try { + MatchesWriter.writeMembers(matches, fieldMatchesFile); + } catch (IOException ex) { + throw new Error(ex); } }); } @@ -258,14 +252,11 @@ public class ConvertMain { checker.dropBrokenMappings(destMappings); deobfuscators.dest.setMappings(destMappings); - new MemberMatchingGui<>(classMatches, methodMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(new MemberMatchingGui.SaveListener() { - @Override - public void save(MemberMatches matches) { - try { - MatchesWriter.writeMembers(matches, methodMatchesFile); - } catch (IOException ex) { - throw new Error(ex); - } + new MemberMatchingGui<>(classMatches, methodMatches, deobfuscators.source, deobfuscators.dest).setSaveListener(matches -> { + try { + MatchesWriter.writeMembers(matches, methodMatchesFile); + } catch (IOException ex) { + throw new Error(ex); } }); } @@ -303,11 +294,8 @@ public class ConvertMain { System.out.println("WARNING: Broken behavior entry " + mapping.getKey() + " (" + mapping.getValue().getDeobfName() + ")"); } - //TODO Fix // write out the converted mappings -// try (FileWriter out = new FileWriter(outMappingsFile)) { -// new MappingsWriter().write(out, newMappings); -// } + new MappingsWriter().write(outMappingsFile, newMappings); System.out.println("Wrote converted mappings to:\n\t" + outMappingsFile.getAbsolutePath()); } diff --git a/src/main/java/cuchaz/enigma/Deobfuscator.java b/src/main/java/cuchaz/enigma/Deobfuscator.java index 2a18e657..f917deb7 100644 --- a/src/main/java/cuchaz/enigma/Deobfuscator.java +++ b/src/main/java/cuchaz/enigma/Deobfuscator.java @@ -120,11 +120,6 @@ public class Deobfuscator { } } - // check for related method inconsistencies - if (checker.getRelatedMethodChecker().hasProblems()) { - throw new Error("Related methods are inconsistent! Need to fix the mappings manually.\n" + checker.getRelatedMethodChecker().getReport()); - } - m_mappings = val; m_renamer = new MappingsRenamer(m_jarIndex, val); m_translatorCache.clear(); @@ -151,7 +146,7 @@ public class Deobfuscator { if (!deobfClassEntry.equals(obfClassEntry)) { // if the class has a mapping, clearly it's deobfuscated deobfClasses.add(deobfClassEntry); - } else if (!obfClassEntry.getPackageName().equals(Constants.NonePackage)) { + } else if (!obfClassEntry.getPackageName().equals(Constants.NONE_PACKAGE)) { // also call it deobufscated if it's not in the none package deobfClasses.add(obfClassEntry); } else { @@ -308,33 +303,15 @@ public class Deobfuscator { getTranslator(TranslationDirection.Obfuscating), getTranslator(TranslationDirection.Deobfuscating) ); - transformJar(out, progress, new ClassTransformer() { - - @Override - public CtClass transform(CtClass c) throws Exception { - return loader.transformClass(c); - } - }); + transformJar(out, progress, loader::transformClass); } public void protectifyJar(File out, ProgressListener progress) { - transformJar(out, progress, new ClassTransformer() { - - @Override - public CtClass transform(CtClass c) throws Exception { - return ClassProtectifier.protectify(c); - } - }); + transformJar(out, progress, ClassProtectifier::protectify); } public void publifyJar(File out, ProgressListener progress) { - transformJar(out, progress, new ClassTransformer() { - - @Override - public CtClass transform(CtClass c) throws Exception { - return ClassPublifier.publify(c); - } - }); + transformJar(out, progress, ClassPublifier::publify); } private interface ClassTransformer { @@ -390,22 +367,14 @@ public class Deobfuscator { if (deobfReference == null) { return null; } - return new EntryReference( - obfuscateEntry(deobfReference.entry), - obfuscateEntry(deobfReference.context), - deobfReference - ); + return new EntryReference<>(obfuscateEntry(deobfReference.entry), obfuscateEntry(deobfReference.context), deobfReference); } public EntryReference deobfuscateReference(EntryReference obfReference) { if (obfReference == null) { return null; } - return new EntryReference( - deobfuscateEntry(obfReference.entry), - deobfuscateEntry(obfReference.context), - obfReference - ); + return new EntryReference<>(deobfuscateEntry(obfReference.entry), deobfuscateEntry(obfReference.context), obfReference); } public boolean isObfuscatedIdentifier(Entry obfEntry) { diff --git a/src/main/java/cuchaz/enigma/MainFormatConverter.java b/src/main/java/cuchaz/enigma/MainFormatConverter.java index 712b0f89..4dd19ea8 100644 --- a/src/main/java/cuchaz/enigma/MainFormatConverter.java +++ b/src/main/java/cuchaz/enigma/MainFormatConverter.java @@ -59,24 +59,18 @@ public class MainFormatConverter { System.out.println("Saving mappings..."); - //TODO Fix -// try (FileWriter writer = new FileWriter(fileMappings)) { -// new MappingsWriter().write(writer, mappings); -// } + new MappingsWriter().write(fileMappings, mappings); System.out.println("Done!"); } private static Type moveClasssesOutOfDefaultPackage(Type type) { - return new Type(type, new ClassNameReplacer() { - @Override - public String replace(String className) { - ClassEntry entry = new ClassEntry(className); - if (entry.isInDefaultPackage()) { - return Constants.NonePackage + "/" + className; - } - return null; + return new Type(type, className -> { + ClassEntry entry = new ClassEntry(className); + if (entry.isInDefaultPackage()) { + return Constants.NONE_PACKAGE + "/" + className; } + return null; }); } diff --git a/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java b/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java index 6c429a6a..a4f53e4b 100644 --- a/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java +++ b/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java @@ -191,7 +191,7 @@ public class TranslatingTypeLoader implements ITypeLoader { public List getClassNamesToTry(ClassEntry obfClassEntry) { List classNamesToTry = Lists.newArrayList(); classNamesToTry.add(obfClassEntry.getName()); - if (obfClassEntry.getPackageName().equals(Constants.NonePackage)) { + if (obfClassEntry.getPackageName().equals(Constants.NONE_PACKAGE)) { // taking off the none package, if any classNamesToTry.add(obfClassEntry.getSimpleName()); } @@ -207,7 +207,7 @@ public class TranslatingTypeLoader implements ITypeLoader { // we moved a lot of classes out of the default package into the none package // make sure all the class references are consistent - ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); + ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NONE_PACKAGE); // reconstruct inner classes new InnerClassWriter(m_jarIndex).write(c); diff --git a/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java b/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java index 9c3d051b..a885c6a4 100644 --- a/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java +++ b/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java @@ -36,10 +36,7 @@ public class EntryRenamer { // for each key/value pair... Set> entriesToAdd = Sets.newHashSet(); for (Map.Entry entry : map.entrySet()) { - entriesToAdd.add(new AbstractMap.SimpleEntry<>( - renameClassesInThing(renames, entry.getKey()), - renameClassesInThing(renames, entry.getValue()) - )); + entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameClassesInThing(renames, entry.getKey()), renameClassesInThing(renames, entry.getValue()))); } map.clear(); for (Map.Entry entry : entriesToAdd) { @@ -51,10 +48,7 @@ public class EntryRenamer { // for each key/value pair... Set> entriesToAdd = Sets.newHashSet(); for (Map.Entry entry : map.entries()) { - entriesToAdd.add(new AbstractMap.SimpleEntry<>( - renameClassesInThing(renames, entry.getKey()), - renameClassesInThing(renames, entry.getValue()) - )); + entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameClassesInThing(renames, entry.getKey()), renameClassesInThing(renames, entry.getValue()))); } map.clear(); for (Map.Entry entry : entriesToAdd) { @@ -66,10 +60,7 @@ public class EntryRenamer { // for each key/value pair... Set> entriesToAdd = Sets.newHashSet(); for (Map.Entry entry : map.entries()) { - entriesToAdd.add(new AbstractMap.SimpleEntry<>( - renameMethodsInThing(renames, entry.getKey()), - renameMethodsInThing(renames, entry.getValue()) - )); + entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameMethodsInThing(renames, entry.getKey()), renameMethodsInThing(renames, entry.getValue()))); } map.clear(); for (Map.Entry entry : entriesToAdd) { @@ -81,10 +72,7 @@ public class EntryRenamer { // for each key/value pair... Set> entriesToAdd = Sets.newHashSet(); for (Map.Entry entry : map.entrySet()) { - entriesToAdd.add(new AbstractMap.SimpleEntry<>( - renameMethodsInThing(renames, entry.getKey()), - renameMethodsInThing(renames, entry.getValue()) - )); + entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameMethodsInThing(renames, entry.getKey()), renameMethodsInThing(renames, entry.getValue()))); } map.clear(); for (Map.Entry entry : entriesToAdd) { diff --git a/src/main/java/cuchaz/enigma/analysis/JarIndex.java b/src/main/java/cuchaz/enigma/analysis/JarIndex.java index 8b30f9eb..377a8cb2 100644 --- a/src/main/java/cuchaz/enigma/analysis/JarIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/JarIndex.java @@ -60,14 +60,14 @@ public class JarIndex { for (ClassEntry classEntry : JarClassIterator.getClassEntries(jar)) { if (classEntry.isInDefaultPackage()) { // move out of default package - classEntry = new ClassEntry(Constants.NonePackage + "/" + classEntry.getName()); + classEntry = new ClassEntry(Constants.NONE_PACKAGE + "/" + classEntry.getName()); } this.obfClassEntries.add(classEntry); } // step 2: index field/method/constructor access for (CtClass c : JarClassIterator.classes(jar)) { - ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); + ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NONE_PACKAGE); for (CtField field : c.getDeclaredFields()) { FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); this.access.put(fieldEntry, Access.get(field)); @@ -82,7 +82,7 @@ public class JarIndex { // step 3: index extends, implements, fields, and methods for (CtClass c : JarClassIterator.classes(jar)) { - ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); + ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NONE_PACKAGE); this.translationIndex.indexClass(c); String className = Descriptor.toJvmName(c.getName()); for (String interfaceName : c.getClassFile().getInterfaces()) { @@ -99,7 +99,7 @@ public class JarIndex { // step 4: index field, method, constructor references for (CtClass c : JarClassIterator.classes(jar)) { - ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); + ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NONE_PACKAGE); for (CtBehavior behavior : c.getDeclaredBehaviors()) { indexBehaviorReferences(behavior); } @@ -109,7 +109,7 @@ public class JarIndex { // step 5: index inner classes and anonymous classes for (CtClass c : JarClassIterator.classes(jar)) { - ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NonePackage); + ClassRenamer.moveAllClassesOutOfDefaultPackage(c, Constants.NONE_PACKAGE); ClassEntry innerClassEntry = EntryFactory.getClassEntry(c); ClassEntry outerClassEntry = findOuterClass(c); if (outerClassEntry != null) { @@ -183,7 +183,7 @@ public class JarIndex { calledMethodEntry.getSignature() ); } - EntryReference reference = new EntryReference( + EntryReference reference = new EntryReference<>( calledMethodEntry, call.getMethodName(), behaviorEntry @@ -198,7 +198,7 @@ public class JarIndex { if (resolvedClassEntry != null && !resolvedClassEntry.equals(calledFieldEntry.getClassEntry())) { calledFieldEntry = new FieldEntry(calledFieldEntry, resolvedClassEntry); } - EntryReference reference = new EntryReference( + EntryReference reference = new EntryReference<>( calledFieldEntry, call.getFieldName(), behaviorEntry @@ -209,7 +209,7 @@ public class JarIndex { @Override public void edit(ConstructorCall call) { ConstructorEntry calledConstructorEntry = EntryFactory.getConstructorEntry(call); - EntryReference reference = new EntryReference( + EntryReference reference = new EntryReference<>( calledConstructorEntry, call.getMethodName(), behaviorEntry @@ -220,7 +220,7 @@ public class JarIndex { @Override public void edit(NewExpr call) { ConstructorEntry calledConstructorEntry = EntryFactory.getConstructorEntry(call); - EntryReference reference = new EntryReference( + EntryReference reference = new EntryReference<>( calledConstructorEntry, call.getClassName(), behaviorEntry @@ -711,7 +711,7 @@ public class JarIndex { public Set getInterfaces(String className) { ClassEntry classEntry = new ClassEntry(className); - Set interfaces = new HashSet(); + Set interfaces = new HashSet<>(); interfaces.addAll(this.translationIndex.getInterfaces(classEntry)); for (ClassEntry ancestor : this.translationIndex.getAncestry(classEntry)) { interfaces.addAll(this.translationIndex.getInterfaces(ancestor)); diff --git a/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java b/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java index 1cf80d91..7919b5d5 100644 --- a/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/MethodImplementationsTreeNode.java @@ -75,9 +75,7 @@ public class MethodImplementationsTreeNode extends DefaultMutableTreeNode { } // add them to this node - for (MethodImplementationsTreeNode node : nodes) { - this.add(node); - } + nodes.forEach(this::add); } public static MethodImplementationsTreeNode findNode(MethodImplementationsTreeNode node, MethodEntry entry) { diff --git a/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java b/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java index a3bed6ed..63837830 100644 --- a/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java @@ -79,9 +79,7 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode { } // add them to this node - for (MethodInheritanceTreeNode node : nodes) { - this.add(node); - } + nodes.forEach(this::add); if (recurse) { for (MethodInheritanceTreeNode node : nodes) { diff --git a/src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java b/src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java deleted file mode 100644 index 08e2dbf0..00000000 --- a/src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *

- * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ -package cuchaz.enigma.analysis; - -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; - -import java.util.Map; -import java.util.Set; - -import cuchaz.enigma.mapping.*; - -public class RelatedMethodChecker { - - private JarIndex m_jarIndex; - private Map, String> m_deobfNamesByGroup; - private Map m_deobfNamesByObfMethod; - private Map> m_groupsByObfMethod; - private Set> m_inconsistentGroups; - - public RelatedMethodChecker(JarIndex jarIndex) { - m_jarIndex = jarIndex; - m_deobfNamesByGroup = Maps.newHashMap(); - m_deobfNamesByObfMethod = Maps.newHashMap(); - m_groupsByObfMethod = Maps.newHashMap(); - m_inconsistentGroups = Sets.newHashSet(); - } - - public void checkMethod(ClassEntry classEntry, MethodMapping methodMapping) { - - // TEMP: disable the expensive check for now, maybe we can optimize it later, or just use it for debugging - if (true) { - return; - } - - BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); - if (!(obfBehaviorEntry instanceof MethodEntry)) { - // only methods have related implementations - return; - } - MethodEntry obfMethodEntry = (MethodEntry) obfBehaviorEntry; - String deobfName = methodMapping.getDeobfName(); - m_deobfNamesByObfMethod.put(obfMethodEntry, deobfName); - - // have we seen this method's group before? - Set group = m_groupsByObfMethod.get(obfMethodEntry); - if (group == null) { - - // no, compute the group and save the name - group = m_jarIndex.getRelatedMethodImplementations(obfMethodEntry); - m_deobfNamesByGroup.put(group, deobfName); - - assert (group.contains(obfMethodEntry)); - for (MethodEntry relatedMethodEntry : group) { - m_groupsByObfMethod.put(relatedMethodEntry, group); - } - } - - // check the name - if (!sameName(m_deobfNamesByGroup.get(group), deobfName)) { - m_inconsistentGroups.add(group); - } - } - - private boolean sameName(String a, String b) { - if (a == null && b == null) { - return true; - } else if (a != null && b != null) { - return a.equals(b); - } - return false; - } - - public boolean hasProblems() { - return m_inconsistentGroups.size() > 0; - } - - public String getReport() { - StringBuilder buf = new StringBuilder(); - buf.append(m_inconsistentGroups.size()); - buf.append(" groups of methods related by inheritance and/or interfaces have different deobf names!\n"); - for (Set group : m_inconsistentGroups) { - buf.append("\tGroup with "); - buf.append(group.size()); - buf.append(" methods:\n"); - for (MethodEntry methodEntry : group) { - buf.append("\t\t"); - buf.append(methodEntry.toString()); - buf.append(" => "); - buf.append(m_deobfNamesByObfMethod.get(methodEntry)); - buf.append("\n"); - } - } - return buf.toString(); - } -} diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndex.java b/src/main/java/cuchaz/enigma/analysis/SourceIndex.java index cbc2945c..719930e9 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndex.java @@ -98,7 +98,7 @@ public class SourceIndex { public void addReference(AstNode node, Entry deobfEntry, Entry deobfContext) { Token token = getToken(node); if (token != null) { - EntryReference deobfReference = new EntryReference(deobfEntry, token.text, deobfContext); + EntryReference deobfReference = new EntryReference<>(deobfEntry, token.text, deobfContext); this.tokenToReference.put(token, deobfReference); this.referenceToTokens.put(deobfReference, token); } @@ -107,7 +107,7 @@ public class SourceIndex { public void addDeclaration(AstNode node, Entry deobfEntry) { Token token = getToken(node); if (token != null) { - EntryReference reference = new EntryReference(deobfEntry, token.text); + EntryReference reference = new EntryReference<>(deobfEntry, token.text); this.tokenToReference.put(token, reference); this.referenceToTokens.put(reference, token); this.declarationToToken.put(deobfEntry, token); diff --git a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java index f020ae2c..adb87b6f 100644 --- a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java @@ -119,7 +119,7 @@ public class TranslationIndex implements Serializable { public void renameClasses(Map renames) { EntryRenamer.renameClassesInMap(renames, this.superclasses); - EntryRenamer.renameClassesInMultimap(renames,this.fieldEntries); + EntryRenamer.renameClassesInMultimap(renames, this.fieldEntries); EntryRenamer.renameClassesInMultimap(renames, this.behaviorEntries); } diff --git a/src/main/java/cuchaz/enigma/bytecode/InfoType.java b/src/main/java/cuchaz/enigma/bytecode/InfoType.java index 86e57ab5..bd9e7d1a 100644 --- a/src/main/java/cuchaz/enigma/bytecode/InfoType.java +++ b/src/main/java/cuchaz/enigma/bytecode/InfoType.java @@ -253,10 +253,7 @@ public enum InfoType { public boolean selfIndexIsValid(ConstInfoAccessor entry, ConstPoolEditor pool) { ConstInfoAccessor entryCheck = pool.getItem(entry.getIndex()); - if (entryCheck == null) { - return false; - } - return entryCheck.getItem().equals(entry.getItem()); + return entryCheck != null && entryCheck.getItem().equals(entry.getItem()); } public static InfoType getByTag(int tag) { diff --git a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java index 17ecbbe9..28ad04ad 100644 --- a/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java +++ b/src/main/java/cuchaz/enigma/bytecode/MethodParameterWriter.java @@ -54,7 +54,7 @@ public class MethodParameterWriter { } // get the list of argument names - List names = new ArrayList(numParams); + List names = new ArrayList<>(numParams); for (int i = 0; i < numParams; i++) { names.add(this.translator.translate(new ArgumentEntry(behaviorEntry, i, ""))); } diff --git a/src/main/java/cuchaz/enigma/bytecode/MethodParametersAttribute.java b/src/main/java/cuchaz/enigma/bytecode/MethodParametersAttribute.java index ee7ed874..bace3a0d 100644 --- a/src/main/java/cuchaz/enigma/bytecode/MethodParametersAttribute.java +++ b/src/main/java/cuchaz/enigma/bytecode/MethodParametersAttribute.java @@ -30,7 +30,7 @@ public class MethodParametersAttribute extends AttributeInfo { // add the names to the class const pool ConstPool constPool = info.getConstPool(); - List parameterNameIndices = new ArrayList(); + List parameterNameIndices = new ArrayList<>(); for (String name : names) { if (name != null) { parameterNameIndices.add(constPool.addUtf8Info(name)); diff --git a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java index 2317a3d9..606c1df1 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassIdentity.java +++ b/src/main/java/cuchaz/enigma/convert/ClassIdentity.java @@ -58,7 +58,7 @@ public class ClassIdentity { // classes not in the none package can be passed through ClassEntry classEntry = new ClassEntry(className); - if (!classEntry.getPackageName().equals(Constants.NonePackage)) { + if (!classEntry.getPackageName().equals(Constants.NONE_PACKAGE)) { return className; } diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatches.java b/src/main/java/cuchaz/enigma/convert/ClassMatches.java index 3a254357..0b7e8034 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatches.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatches.java @@ -45,9 +45,7 @@ public class ClassMatches implements Iterable { m_unmatchedSourceClasses = Sets.newHashSet(); m_unmatchedDestClasses = Sets.newHashSet(); - for (ClassMatch match : matches) { - indexMatch(match); - } + matches.forEach(this::indexMatch); } public void add(ClassMatch match) { diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatching.java b/src/main/java/cuchaz/enigma/convert/ClassMatching.java index 9350ea7f..194b6c4a 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatching.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatching.java @@ -55,23 +55,14 @@ public class ClassMatching { public Collection matches() { List matches = Lists.newArrayList(); for (Entry entry : m_knownMatches.entrySet()) { - matches.add(new ClassMatch( - entry.getKey(), - entry.getValue() - )); + matches.add(new ClassMatch(entry.getKey(), entry.getValue())); } for (ClassIdentity identity : m_sourceClasses.identities()) { - matches.add(new ClassMatch( - m_sourceClasses.getClasses(identity), - m_destClasses.getClasses(identity) - )); + matches.add(new ClassMatch(m_sourceClasses.getClasses(identity), m_destClasses.getClasses(identity))); } for (ClassIdentity identity : m_destClasses.identities()) { if (!m_sourceClasses.containsIdentity(identity)) { - matches.add(new ClassMatch( - new ArrayList<>(), - m_destClasses.getClasses(identity) - )); + matches.add(new ClassMatch(new ArrayList<>(), m_destClasses.getClasses(identity))); } } return matches; diff --git a/src/main/java/cuchaz/enigma/convert/FieldMatches.java b/src/main/java/cuchaz/enigma/convert/FieldMatches.java deleted file mode 100644 index 0899cd2e..00000000 --- a/src/main/java/cuchaz/enigma/convert/FieldMatches.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *

- * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ -package cuchaz.enigma.convert; - -import com.google.common.collect.*; - -import java.util.Collection; -import java.util.Set; - -import cuchaz.enigma.mapping.ClassEntry; -import cuchaz.enigma.mapping.FieldEntry; - - -public class FieldMatches { - - private BiMap m_matches; - private Multimap m_matchedSourceFields; - private Multimap m_unmatchedSourceFields; - private Multimap m_unmatchedDestFields; - private Multimap m_unmatchableSourceFields; - - public FieldMatches() { - m_matches = HashBiMap.create(); - m_matchedSourceFields = HashMultimap.create(); - m_unmatchedSourceFields = HashMultimap.create(); - m_unmatchedDestFields = HashMultimap.create(); - m_unmatchableSourceFields = HashMultimap.create(); - } - - public void addMatch(FieldEntry srcField, FieldEntry destField) { - boolean wasAdded = m_matches.put(srcField, destField) == null; - assert (wasAdded); - wasAdded = m_matchedSourceFields.put(srcField.getClassEntry(), srcField); - assert (wasAdded); - } - - public void addUnmatchedSourceField(FieldEntry fieldEntry) { - boolean wasAdded = m_unmatchedSourceFields.put(fieldEntry.getClassEntry(), fieldEntry); - assert (wasAdded); - } - - public void addUnmatchedSourceFields(Iterable fieldEntries) { - for (FieldEntry fieldEntry : fieldEntries) { - addUnmatchedSourceField(fieldEntry); - } - } - - public void addUnmatchedDestField(FieldEntry fieldEntry) { - boolean wasAdded = m_unmatchedDestFields.put(fieldEntry.getClassEntry(), fieldEntry); - assert (wasAdded); - } - - public void addUnmatchedDestFields(Iterable fieldEntries) { - for (FieldEntry fieldEntry : fieldEntries) { - addUnmatchedDestField(fieldEntry); - } - } - - public void addUnmatchableSourceField(FieldEntry sourceField) { - boolean wasAdded = m_unmatchableSourceFields.put(sourceField.getClassEntry(), sourceField); - assert (wasAdded); - } - - public Set getSourceClassesWithUnmatchedFields() { - return m_unmatchedSourceFields.keySet(); - } - - public Collection getSourceClassesWithoutUnmatchedFields() { - Set out = Sets.newHashSet(); - out.addAll(m_matchedSourceFields.keySet()); - out.removeAll(m_unmatchedSourceFields.keySet()); - return out; - } - - public Collection getUnmatchedSourceFields() { - return m_unmatchedSourceFields.values(); - } - - public Collection getUnmatchedSourceFields(ClassEntry sourceClass) { - return m_unmatchedSourceFields.get(sourceClass); - } - - public Collection getUnmatchedDestFields() { - return m_unmatchedDestFields.values(); - } - - public Collection getUnmatchedDestFields(ClassEntry destClass) { - return m_unmatchedDestFields.get(destClass); - } - - public Collection getUnmatchableSourceFields() { - return m_unmatchableSourceFields.values(); - } - - public boolean hasSource(FieldEntry fieldEntry) { - return m_matches.containsKey(fieldEntry) || m_unmatchedSourceFields.containsValue(fieldEntry); - } - - public boolean hasDest(FieldEntry fieldEntry) { - return m_matches.containsValue(fieldEntry) || m_unmatchedDestFields.containsValue(fieldEntry); - } - - public BiMap matches() { - return m_matches; - } - - public boolean isMatchedSourceField(FieldEntry sourceField) { - return m_matches.containsKey(sourceField); - } - - public boolean isMatchedDestField(FieldEntry destField) { - return m_matches.containsValue(destField); - } - - public void makeMatch(FieldEntry sourceField, FieldEntry destField) { - boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); - assert (wasRemoved); - wasRemoved = m_unmatchedDestFields.remove(destField.getClassEntry(), destField); - assert (wasRemoved); - addMatch(sourceField, destField); - } - - public boolean isMatched(FieldEntry sourceField, FieldEntry destField) { - FieldEntry match = m_matches.get(sourceField); - return match != null && match.equals(destField); - } - - public void unmakeMatch(FieldEntry sourceField, FieldEntry destField) { - boolean wasRemoved = m_matches.remove(sourceField) != null; - assert (wasRemoved); - wasRemoved = m_matchedSourceFields.remove(sourceField.getClassEntry(), sourceField); - assert (wasRemoved); - addUnmatchedSourceField(sourceField); - addUnmatchedDestField(destField); - } - - public void makeSourceUnmatchable(FieldEntry sourceField) { - assert (!isMatchedSourceField(sourceField)); - boolean wasRemoved = m_unmatchedSourceFields.remove(sourceField.getClassEntry(), sourceField); - assert (wasRemoved); - addUnmatchableSourceField(sourceField); - } -} diff --git a/src/main/java/cuchaz/enigma/convert/MappingsConverter.java b/src/main/java/cuchaz/enigma/convert/MappingsConverter.java index 394b8c81..d1daadb0 100644 --- a/src/main/java/cuchaz/enigma/convert/MappingsConverter.java +++ b/src/main/java/cuchaz/enigma/convert/MappingsConverter.java @@ -151,7 +151,9 @@ public class MappingsConverter { } } } - destMapping.addInnerClassMapping(migrateClassMapping(obfDestClassEntry, sourceMapping, matches, true)); + if (destMapping != null) { + destMapping.addInnerClassMapping(migrateClassMapping(obfDestClassEntry, sourceMapping, matches, true)); + } } } } @@ -160,15 +162,12 @@ public class MappingsConverter { private static ClassMapping migrateClassMapping(ClassEntry newObfClass, ClassMapping oldClassMapping, final ClassMatches matches, boolean useSimpleName) { - ClassNameReplacer replacer = new ClassNameReplacer() { - @Override - public String replace(String className) { - ClassEntry newClassEntry = matches.getUniqueMatches().get(new ClassEntry(className)); - if (newClassEntry != null) { - return newClassEntry.getName(); - } - return null; + ClassNameReplacer replacer = className -> { + ClassEntry newClassEntry = matches.getUniqueMatches().get(new ClassEntry(className)); + if (newClassEntry != null) { + return newClassEntry.getName(); } + return null; }; ClassMapping newClassMapping; @@ -229,7 +228,7 @@ public class MappingsConverter { // non obfuscated classes can be migrated ClassEntry classEntry = oldObfType.getClassEntry(); - if (!classEntry.getPackageName().equals(Constants.NonePackage)) { + if (!classEntry.getPackageName().equals(Constants.NONE_PACKAGE)) { return true; } @@ -390,7 +389,7 @@ public class MappingsConverter { public static MemberMatches computeMemberMatches(Deobfuscator destDeobfuscator, Mappings destMappings, ClassMatches classMatches, Doer doer) { - MemberMatches memberMatches = new MemberMatches(); + MemberMatches memberMatches = new MemberMatches<>(); // unmatched source fields are easy MappingsChecker checker = new MappingsChecker(destDeobfuscator.getJarIndex()); @@ -481,15 +480,12 @@ public class MappingsConverter { } private static Type translate(Type type, final BiMap map) { - return new Type(type, new ClassNameReplacer() { - @Override - public String replace(String inClassName) { - ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); - if (outClassEntry == null) { - return null; - } - return outClassEntry.getName(); + return new Type(type, inClassName -> { + ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); + if (outClassEntry == null) { + return null; } + return outClassEntry.getName(); }); } @@ -497,15 +493,12 @@ public class MappingsConverter { if (signature == null) { return null; } - return new Signature(signature, new ClassNameReplacer() { - @Override - public String replace(String inClassName) { - ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); - if (outClassEntry == null) { - return null; - } - return outClassEntry.getName(); + return new Signature(signature, inClassName -> { + ClassEntry outClassEntry = map.get(new ClassEntry(inClassName)); + if (outClassEntry == null) { + return null; } + return outClassEntry.getName(); }); } diff --git a/src/main/java/cuchaz/enigma/convert/MatchesReader.java b/src/main/java/cuchaz/enigma/convert/MatchesReader.java index 773566df..f7853acf 100644 --- a/src/main/java/cuchaz/enigma/convert/MatchesReader.java +++ b/src/main/java/cuchaz/enigma/convert/MatchesReader.java @@ -28,7 +28,7 @@ public class MatchesReader { throws IOException { try (BufferedReader in = new BufferedReader(new FileReader(file))) { ClassMatches matches = new ClassMatches(); - String line = null; + String line; while ((line = in.readLine()) != null) { matches.add(readClassMatch(line)); } @@ -56,8 +56,8 @@ public class MatchesReader { public static MemberMatches readMembers(File file) throws IOException { try (BufferedReader in = new BufferedReader(new FileReader(file))) { - MemberMatches matches = new MemberMatches(); - String line = null; + MemberMatches matches = new MemberMatches<>(); + String line; while ((line = in.readLine()) != null) { readMemberMatch(matches, line); } @@ -90,13 +90,8 @@ public class MatchesReader { } String[] parts = in.split(" "); if (parts.length == 3 && parts[2].indexOf('(') < 0) { - return (T) new FieldEntry( - new ClassEntry(parts[0]), - parts[1], - new Type(parts[2]) - ); + return (T) new FieldEntry(new ClassEntry(parts[0]), parts[1], new Type(parts[2])); } else { - assert (parts.length == 2 || parts.length == 3); if (parts.length == 2) { return (T) EntryFactory.getBehaviorEntry(parts[0], parts[1]); } else if (parts.length == 3) { diff --git a/src/main/java/cuchaz/enigma/gui/AboutDialog.java b/src/main/java/cuchaz/enigma/gui/AboutDialog.java index a8743998..bb12466f 100644 --- a/src/main/java/cuchaz/enigma/gui/AboutDialog.java +++ b/src/main/java/cuchaz/enigma/gui/AboutDialog.java @@ -25,14 +25,14 @@ public class AboutDialog { public static void show(JFrame parent) { // init frame - final JFrame frame = new JFrame(Constants.Name + " - About"); + final JFrame frame = new JFrame(Constants.NAME + " - About"); final Container pane = frame.getContentPane(); pane.setLayout(new FlowLayout()); // load the content try { String html = Util.readResourceToString("/about.html"); - html = String.format(html, Constants.Name, Constants.Version); + html = String.format(html, Constants.NAME, Constants.VERSION); JLabel label = new JLabel(html); label.setHorizontalAlignment(JLabel.CENTER); pane.add(label); @@ -42,9 +42,9 @@ public class AboutDialog { // show the link String html = "%s"; - html = String.format(html, Constants.Url, Constants.Url); + html = String.format(html, Constants.URL, Constants.URL); JButton link = new JButton(html); - link.addActionListener(event -> Util.openUrl(Constants.Url)); + link.addActionListener(event -> Util.openUrl(Constants.URL)); link.setBorderPainted(false); link.setOpaque(false); link.setBackground(Color.WHITE); diff --git a/src/main/java/cuchaz/enigma/gui/BoxHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/BoxHighlightPainter.java index efe6b506..b66d13da 100644 --- a/src/main/java/cuchaz/enigma/gui/BoxHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/BoxHighlightPainter.java @@ -21,12 +21,12 @@ import javax.swing.text.JTextComponent; public abstract class BoxHighlightPainter implements Highlighter.HighlightPainter { - private Color m_fillColor; - private Color m_borderColor; + private Color fillColor; + private Color borderColor; protected BoxHighlightPainter(Color fillColor, Color borderColor) { - m_fillColor = fillColor; - m_borderColor = borderColor; + this.fillColor = fillColor; + this.borderColor = borderColor; } @Override @@ -34,17 +34,17 @@ public abstract class BoxHighlightPainter implements Highlighter.HighlightPainte Rectangle bounds = getBounds(text, start, end); // fill the area - if (m_fillColor != null) { - g.setColor(m_fillColor); + if (this.fillColor != null) { + g.setColor(this.fillColor); g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); } // draw a box around the area - g.setColor(m_borderColor); + g.setColor(this.borderColor); g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4); } - protected static Rectangle getBounds(JTextComponent text, int start, int end) { + public static Rectangle getBounds(JTextComponent text, int start, int end) { try { // determine the bounds of the text Rectangle bounds = text.modelToView(start).union(text.modelToView(end)); diff --git a/src/main/java/cuchaz/enigma/gui/BrowserCaret.java b/src/main/java/cuchaz/enigma/gui/BrowserCaret.java index b4acbce9..094b69b2 100644 --- a/src/main/java/cuchaz/enigma/gui/BrowserCaret.java +++ b/src/main/java/cuchaz/enigma/gui/BrowserCaret.java @@ -17,8 +17,7 @@ public class BrowserCaret extends DefaultCaret { private static final long serialVersionUID = 1158977422507969940L; - private static final Highlighter.HighlightPainter m_selectionPainter = (g, p0, p1, bounds, c) -> { - // don't paint anything + private static final Highlighter.HighlightPainter selectionPainter = (g, p0, p1, bounds, c) -> { }; @Override @@ -33,6 +32,6 @@ public class BrowserCaret extends DefaultCaret { @Override public Highlighter.HighlightPainter getSelectionPainter() { - return m_selectionPainter; + return this.selectionPainter; } } diff --git a/src/main/java/cuchaz/enigma/gui/ClassListCellRenderer.java b/src/main/java/cuchaz/enigma/gui/ClassListCellRenderer.java deleted file mode 100644 index 89b9bdd4..00000000 --- a/src/main/java/cuchaz/enigma/gui/ClassListCellRenderer.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *

- * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ -package cuchaz.enigma.gui; - -import java.awt.Component; - -import javax.swing.DefaultListCellRenderer; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.ListCellRenderer; - -import javassist.bytecode.Descriptor; - -public class ClassListCellRenderer implements ListCellRenderer { - - private DefaultListCellRenderer m_defaultRenderer; - - public ClassListCellRenderer() { - m_defaultRenderer = new DefaultListCellRenderer(); - } - - @Override - public Component getListCellRendererComponent(JList list, String className, int index, boolean isSelected, boolean hasFocus) { - JLabel label = (JLabel) m_defaultRenderer.getListCellRendererComponent(list, className, index, isSelected, hasFocus); - label.setText(Descriptor.toJavaName(className)); - return label; - } -} diff --git a/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java b/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java index 440565c3..a069bcac 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java +++ b/src/main/java/cuchaz/enigma/gui/ClassMatchingGui.java @@ -77,35 +77,35 @@ public class ClassMatchingGui { } // controls - private JFrame m_frame; - private ClassSelector m_sourceClasses; - private ClassSelector m_destClasses; - private CodeReader m_sourceReader; - private CodeReader m_destReader; - private JLabel m_sourceClassLabel; - private JLabel m_destClassLabel; - private JButton m_matchButton; - private Map m_sourceTypeButtons; - private JCheckBox m_advanceCheck; - private JCheckBox m_top10Matches; - - private ClassMatches m_classMatches; - private Deobfuscator m_sourceDeobfuscator; - private Deobfuscator m_destDeobfuscator; - private ClassEntry m_sourceClass; - private ClassEntry m_destClass; - private SourceType m_sourceType; - private SaveListener m_saveListener; + private JFrame frame; + private ClassSelector sourceClasses; + private ClassSelector destClasses; + private CodeReader sourceReader; + private CodeReader destReader; + private JLabel sourceClassLabel; + private JLabel destClassLabel; + private JButton matchButton; + private Map sourceTypeButtons; + private JCheckBox advanceCheck; + private JCheckBox top10Matches; + + private ClassMatches classMatches; + private Deobfuscator sourceDeobfuscator; + private Deobfuscator destDeobfuscator; + private ClassEntry sourceClass; + private ClassEntry destClass; + private SourceType sourceType; + private SaveListener saveListener; public ClassMatchingGui(ClassMatches matches, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) { - m_classMatches = matches; - m_sourceDeobfuscator = sourceDeobfuscator; - m_destDeobfuscator = destDeobfuscator; + this.classMatches = matches; + this.sourceDeobfuscator = sourceDeobfuscator; + this.destDeobfuscator = destDeobfuscator; // init frame - m_frame = new JFrame(Constants.Name + " - Class Matcher"); - final Container pane = m_frame.getContentPane(); + this.frame = new JFrame(Constants.NAME + " - Class Matcher"); + final Container pane = this.frame.getContentPane(); pane.setLayout(new BorderLayout()); // init source side @@ -121,16 +121,16 @@ public class ClassMatchingGui { sourceTypePanel.setLayout(new BoxLayout(sourceTypePanel, BoxLayout.PAGE_AXIS)); ActionListener sourceTypeListener = event -> setSourceType(SourceType.valueOf(event.getActionCommand())); ButtonGroup sourceTypeButtons = new ButtonGroup(); - m_sourceTypeButtons = Maps.newHashMap(); + this.sourceTypeButtons = Maps.newHashMap(); for (SourceType sourceType : SourceType.values()) { JRadioButton button = sourceType.newRadio(sourceTypeListener, sourceTypeButtons); - m_sourceTypeButtons.put(sourceType, button); + this.sourceTypeButtons.put(sourceType, button); sourceTypePanel.add(button); } - m_sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); - m_sourceClasses.setListener(classEntry -> setSourceClass(classEntry)); - JScrollPane sourceScroller = new JScrollPane(m_sourceClasses); + this.sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); + this.sourceClasses.setListener(this::setSourceClass); + JScrollPane sourceScroller = new JScrollPane(this.sourceClasses); sourcePanel.add(sourceScroller); // init dest side @@ -140,13 +140,13 @@ public class ClassMatchingGui { pane.add(destPanel, BorderLayout.WEST); destPanel.add(new JLabel("Destination Classes")); - m_top10Matches = new JCheckBox("Show only top 10 matches"); - destPanel.add(m_top10Matches); - m_top10Matches.addActionListener(event -> toggleTop10Matches()); + this.top10Matches = new JCheckBox("Show only top 10 matches"); + destPanel.add(this.top10Matches); + this.top10Matches.addActionListener(event -> toggleTop10Matches()); - m_destClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); - m_destClasses.setListener(this::setDestClass); - JScrollPane destScroller = new JScrollPane(m_destClasses); + this.destClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); + this.destClasses.setListener(this::setDestClass); + JScrollPane destScroller = new JScrollPane(this.destClasses); destPanel.add(destScroller); JButton autoMatchButton = new JButton("AutoMatch"); @@ -155,13 +155,13 @@ public class ClassMatchingGui { // init source panels DefaultSyntaxKit.initKit(); - m_sourceReader = new CodeReader(); - m_destReader = new CodeReader(); + this.sourceReader = new CodeReader(); + this.destReader = new CodeReader(); // init all the splits - JSplitPane splitLeft = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, sourcePanel, new JScrollPane(m_sourceReader)); + JSplitPane splitLeft = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, sourcePanel, new JScrollPane(this.sourceReader)); splitLeft.setResizeWeight(0); // let the right side take all the slack - JSplitPane splitRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, new JScrollPane(m_destReader), destPanel); + JSplitPane splitRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, new JScrollPane(this.destReader), destPanel); splitRight.setResizeWeight(1); // let the left side take all the slack JSplitPane splitCenter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, splitLeft, splitRight); splitCenter.setResizeWeight(0.5); // resize 50:50 @@ -172,81 +172,75 @@ public class ClassMatchingGui { JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new FlowLayout()); - m_sourceClassLabel = new JLabel(); - m_sourceClassLabel.setHorizontalAlignment(SwingConstants.RIGHT); - m_destClassLabel = new JLabel(); - m_destClassLabel.setHorizontalAlignment(SwingConstants.LEFT); + this.sourceClassLabel = new JLabel(); + this.sourceClassLabel.setHorizontalAlignment(SwingConstants.RIGHT); + this.destClassLabel = new JLabel(); + this.destClassLabel.setHorizontalAlignment(SwingConstants.LEFT); - m_matchButton = new JButton(); + this.matchButton = new JButton(); - m_advanceCheck = new JCheckBox("Advance to next likely match"); - m_advanceCheck.addActionListener(event -> { - if (m_advanceCheck.isSelected()) { + this.advanceCheck = new JCheckBox("Advance to next likely match"); + this.advanceCheck.addActionListener(event -> { + if (this.advanceCheck.isSelected()) { advance(); } }); - bottomPanel.add(m_sourceClassLabel); - bottomPanel.add(m_matchButton); - bottomPanel.add(m_destClassLabel); - bottomPanel.add(m_advanceCheck); + bottomPanel.add(this.sourceClassLabel); + bottomPanel.add(this.matchButton); + bottomPanel.add(this.destClassLabel); + bottomPanel.add(this.advanceCheck); pane.add(bottomPanel, BorderLayout.SOUTH); // show the frame pane.doLayout(); - m_frame.setSize(1024, 576); - m_frame.setMinimumSize(new Dimension(640, 480)); - m_frame.setVisible(true); - m_frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + this.frame.setSize(1024, 576); + this.frame.setMinimumSize(new Dimension(640, 480)); + this.frame.setVisible(true); + this.frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // init state updateDestMappings(); setSourceType(SourceType.getDefault()); updateMatchButton(); - m_saveListener = null; + this.saveListener = null; } public void setSaveListener(SaveListener val) { - m_saveListener = val; + this.saveListener = val; } private void updateDestMappings() { - Mappings newMappings = MappingsConverter.newMappings( - m_classMatches, - m_sourceDeobfuscator.getMappings(), - m_sourceDeobfuscator, - m_destDeobfuscator - ); + Mappings newMappings = MappingsConverter.newMappings(this.classMatches, this.sourceDeobfuscator.getMappings(), this.sourceDeobfuscator, this.destDeobfuscator); // look for dropped mappings - MappingsChecker checker = new MappingsChecker(m_destDeobfuscator.getJarIndex()); + MappingsChecker checker = new MappingsChecker(this.destDeobfuscator.getJarIndex()); checker.dropBrokenMappings(newMappings); // count them int numDroppedFields = checker.getDroppedFieldMappings().size(); int numDroppedMethods = checker.getDroppedMethodMappings().size(); - System.out.println(String.format( - "%d mappings from matched classes don't match the dest jar:\n\t%5d fields\n\t%5d methods", + System.out.println(String.format("%d mappings from matched classes don't match the dest jar:\n\t%5d fields\n\t%5d methods", numDroppedFields + numDroppedMethods, numDroppedFields, numDroppedMethods )); - m_destDeobfuscator.setMappings(newMappings); + this.destDeobfuscator.setMappings(newMappings); } protected void setSourceType(SourceType val) { // show the source classes - m_sourceType = val; - m_sourceClasses.setClasses(deobfuscateClasses(m_sourceType.getSourceClasses(m_classMatches), m_sourceDeobfuscator)); + this.sourceType = val; + this.sourceClasses.setClasses(deobfuscateClasses(this.sourceType.getSourceClasses(this.classMatches), this.sourceDeobfuscator)); // update counts for (SourceType sourceType : SourceType.values()) { - m_sourceTypeButtons.get(sourceType).setText(String.format("%s (%d)", + this.sourceTypeButtons.get(sourceType).setText(String.format("%s (%d)", sourceType.name(), - sourceType.getSourceClasses(m_classMatches).size() + sourceType.getSourceClasses(this.classMatches).size() )); } } @@ -270,7 +264,7 @@ public class ClassMatchingGui { protected void setSourceClass(ClassEntry classEntry) { Runnable onGetDestClasses = null; - if (m_advanceCheck.isSelected()) { + if (this.advanceCheck.isSelected()) { onGetDestClasses = this::pickBestDestClass; } @@ -280,24 +274,24 @@ public class ClassMatchingGui { protected void setSourceClass(ClassEntry classEntry, final Runnable onGetDestClasses) { // update the current source class - m_sourceClass = classEntry; - m_sourceClassLabel.setText(m_sourceClass != null ? m_sourceClass.getName() : ""); + this.sourceClass = classEntry; + this.sourceClassLabel.setText(this.sourceClass != null ? this.sourceClass.getName() : ""); - if (m_sourceClass != null) { + if (this.sourceClass != null) { // show the dest class(es) - ClassMatch match = m_classMatches.getMatchBySource(m_sourceDeobfuscator.obfuscateEntry(m_sourceClass)); + ClassMatch match = this.classMatches.getMatchBySource(this.sourceDeobfuscator.obfuscateEntry(this.sourceClass)); assert (match != null); if (match.destClasses.isEmpty()) { - m_destClasses.setClasses(null); + this.destClasses.setClasses(null); // run in a separate thread to keep ui responsive new Thread() { @Override public void run() { - m_destClasses.setClasses(deobfuscateClasses(getLikelyMatches(m_sourceClass), m_destDeobfuscator)); - m_destClasses.expandAll(); + destClasses.setClasses(deobfuscateClasses(getLikelyMatches(sourceClass), destDeobfuscator)); + destClasses.expandAll(); if (onGetDestClasses != null) { onGetDestClasses.run(); @@ -307,8 +301,8 @@ public class ClassMatchingGui { } else { - m_destClasses.setClasses(deobfuscateClasses(match.destClasses, m_destDeobfuscator)); - m_destClasses.expandAll(); + this.destClasses.setClasses(deobfuscateClasses(match.destClasses, this.destDeobfuscator)); + this.destClasses.expandAll(); if (onGetDestClasses != null) { onGetDestClasses.run(); @@ -317,39 +311,33 @@ public class ClassMatchingGui { } setDestClass(null); - m_sourceReader.decompileClass(m_sourceClass, m_sourceDeobfuscator, () -> m_sourceReader.navigateToClassDeclaration(m_sourceClass)); + this.sourceReader.decompileClass(this.sourceClass, this.sourceDeobfuscator, () -> this.sourceReader.navigateToClassDeclaration(this.sourceClass)); updateMatchButton(); } private Collection getLikelyMatches(ClassEntry sourceClass) { - ClassEntry obfSourceClass = m_sourceDeobfuscator.obfuscateEntry(sourceClass); + ClassEntry obfSourceClass = this.sourceDeobfuscator.obfuscateEntry(sourceClass); // set up identifiers - ClassNamer namer = new ClassNamer(m_classMatches.getUniqueMatches()); - ClassIdentifier sourceIdentifier = new ClassIdentifier( - m_sourceDeobfuscator.getJar(), m_sourceDeobfuscator.getJarIndex(), - namer.getSourceNamer(), true - ); - ClassIdentifier destIdentifier = new ClassIdentifier( - m_destDeobfuscator.getJar(), m_destDeobfuscator.getJarIndex(), - namer.getDestNamer(), true - ); + ClassNamer namer = new ClassNamer(this.classMatches.getUniqueMatches()); + ClassIdentifier sourceIdentifier = new ClassIdentifier(this.sourceDeobfuscator.getJar(), this.sourceDeobfuscator.getJarIndex(), namer.getSourceNamer(), true); + ClassIdentifier destIdentifier = new ClassIdentifier(this.destDeobfuscator.getJar(), this.destDeobfuscator.getJarIndex(), namer.getDestNamer(), true); try { // rank all the unmatched dest classes against the source class ClassIdentity sourceIdentity = sourceIdentifier.identify(obfSourceClass); List scoredDestClasses = Lists.newArrayList(); - for (ClassEntry unmatchedDestClass : m_classMatches.getUnmatchedDestClasses()) { + for (ClassEntry unmatchedDestClass : this.classMatches.getUnmatchedDestClasses()) { ClassIdentity destIdentity = destIdentifier.identify(unmatchedDestClass); float score = 100.0f * (sourceIdentity.getMatchScore(destIdentity) + destIdentity.getMatchScore(sourceIdentity)) / (sourceIdentity.getMaxMatchScore() + destIdentity.getMaxMatchScore()); scoredDestClasses.add(new ScoredClassEntry(unmatchedDestClass, score)); } - if (m_top10Matches.isSelected() && scoredDestClasses.size() > 10) { + if (this.top10Matches.isSelected() && scoredDestClasses.size() > 10) { Collections.sort(scoredDestClasses, (a, b) -> { ScoredClassEntry sa = (ScoredClassEntry) a; ScoredClassEntry sb = (ScoredClassEntry) b; @@ -368,30 +356,30 @@ public class ClassMatchingGui { protected void setDestClass(ClassEntry classEntry) { // update the current source class - m_destClass = classEntry; - m_destClassLabel.setText(m_destClass != null ? m_destClass.getName() : ""); + this.destClass = classEntry; + this.destClassLabel.setText(this.destClass != null ? this.destClass.getName() : ""); - m_destReader.decompileClass(m_destClass, m_destDeobfuscator, () -> m_destReader.navigateToClassDeclaration(m_destClass)); + this.destReader.decompileClass(this.destClass, this.destDeobfuscator, () -> this.destReader.navigateToClassDeclaration(this.destClass)); updateMatchButton(); } private void updateMatchButton() { - ClassEntry obfSource = m_sourceDeobfuscator.obfuscateEntry(m_sourceClass); - ClassEntry obfDest = m_destDeobfuscator.obfuscateEntry(m_destClass); + ClassEntry obfSource = this.sourceDeobfuscator.obfuscateEntry(this.sourceClass); + ClassEntry obfDest = this.destDeobfuscator.obfuscateEntry(this.destClass); - BiMap uniqueMatches = m_classMatches.getUniqueMatches(); - boolean twoSelected = m_sourceClass != null && m_destClass != null; + BiMap uniqueMatches = this.classMatches.getUniqueMatches(); + boolean twoSelected = this.sourceClass != null && this.destClass != null; boolean isMatched = uniqueMatches.containsKey(obfSource) && uniqueMatches.containsValue(obfDest); boolean canMatch = !uniqueMatches.containsKey(obfSource) && !uniqueMatches.containsValue(obfDest); - GuiTricks.deactivateButton(m_matchButton); + GuiTricks.deactivateButton(this.matchButton); if (twoSelected) { if (isMatched) { - GuiTricks.activateButton(m_matchButton, "Unmatch", event -> onUnmatchClick()); + GuiTricks.activateButton(this.matchButton, "Unmatch", event -> onUnmatchClick()); } else if (canMatch) { - GuiTricks.activateButton(m_matchButton, "Match", event -> onMatchClick()); + GuiTricks.activateButton(this.matchButton, "Match", event -> onMatchClick()); } } } @@ -399,19 +387,19 @@ public class ClassMatchingGui { private void onMatchClick() { // precondition: source and dest classes are set correctly - ClassEntry obfSource = m_sourceDeobfuscator.obfuscateEntry(m_sourceClass); - ClassEntry obfDest = m_destDeobfuscator.obfuscateEntry(m_destClass); + ClassEntry obfSource = this.sourceDeobfuscator.obfuscateEntry(this.sourceClass); + ClassEntry obfDest = this.destDeobfuscator.obfuscateEntry(this.destClass); // remove the classes from their match - m_classMatches.removeSource(obfSource); - m_classMatches.removeDest(obfDest); + this.classMatches.removeSource(obfSource); + this.classMatches.removeDest(obfDest); // add them as matched classes - m_classMatches.add(new ClassMatch(obfSource, obfDest)); + this.classMatches.add(new ClassMatch(obfSource, obfDest)); ClassEntry nextClass = null; - if (m_advanceCheck.isSelected()) { - nextClass = m_sourceClasses.getNextClass(m_sourceClass); + if (this.advanceCheck.isSelected()) { + nextClass = this.sourceClasses.getNextClass(this.sourceClass); } save(); @@ -425,11 +413,11 @@ public class ClassMatchingGui { private void onUnmatchClick() { // precondition: source and dest classes are set to a unique match - ClassEntry obfSource = m_sourceDeobfuscator.obfuscateEntry(m_sourceClass); + ClassEntry obfSource = this.sourceDeobfuscator.obfuscateEntry(this.sourceClass); // remove the source to break the match, then add the source back as unmatched - m_classMatches.removeSource(obfSource); - m_classMatches.add(new ClassMatch(obfSource, null)); + this.classMatches.removeSource(obfSource); + this.classMatches.add(new ClassMatch(obfSource, null)); save(); updateMatches(); @@ -438,20 +426,20 @@ public class ClassMatchingGui { private void updateMatches() { updateDestMappings(); setDestClass(null); - m_destClasses.setClasses(null); + this.destClasses.setClasses(null); updateMatchButton(); // remember where we were in the source tree - String packageName = m_sourceClasses.getSelectedPackage(); + String packageName = this.sourceClasses.getSelectedPackage(); - setSourceType(m_sourceType); + setSourceType(this.sourceType); - m_sourceClasses.expandPackage(packageName); + this.sourceClasses.expandPackage(packageName); } private void save() { - if (m_saveListener != null) { - m_saveListener.save(m_classMatches); + if (this.saveListener != null) { + this.saveListener.save(this.classMatches); } } @@ -460,18 +448,13 @@ public class ClassMatchingGui { System.out.println("Automatching..."); // compute a new matching - ClassMatching matching = MappingsConverter.computeMatching( - m_sourceDeobfuscator.getJar(), m_sourceDeobfuscator.getJarIndex(), - m_destDeobfuscator.getJar(), m_destDeobfuscator.getJarIndex(), - m_classMatches.getUniqueMatches() - ); + ClassMatching matching = MappingsConverter.computeMatching(this.sourceDeobfuscator.getJar(), this.sourceDeobfuscator.getJarIndex(), + this.destDeobfuscator.getJar(), this.destDeobfuscator.getJarIndex(), this.classMatches.getUniqueMatches()); ClassMatches newMatches = new ClassMatches(matching.matches()); - System.out.println(String.format("Automatch found %d new matches", - newMatches.getUniqueMatches().size() - m_classMatches.getUniqueMatches().size() - )); + System.out.println(String.format("Automatch found %d new matches", newMatches.getUniqueMatches().size() - this.classMatches.getUniqueMatches().size())); // update the current matches - m_classMatches = newMatches; + this.classMatches = newMatches; save(); updateMatches(); } @@ -484,17 +467,17 @@ public class ClassMatchingGui { // make sure we have a source class if (sourceClass == null) { - sourceClass = m_sourceClasses.getSelectedClass(); + sourceClass = this.sourceClasses.getSelectedClass(); if (sourceClass != null) { - sourceClass = m_sourceClasses.getNextClass(sourceClass); + sourceClass = this.sourceClasses.getNextClass(sourceClass); } else { - sourceClass = m_sourceClasses.getFirstClass(); + sourceClass = this.sourceClasses.getFirstClass(); } } // set the source class setSourceClass(sourceClass, this::pickBestDestClass); - m_sourceClasses.setSelectionClass(sourceClass); + this.sourceClasses.setSelectionClass(sourceClass); } private void pickBestDestClass() { @@ -502,8 +485,8 @@ public class ClassMatchingGui { // then, pick the best dest class ClassEntry firstClass = null; ScoredClassEntry bestDestClass = null; - for (ClassSelectorPackageNode packageNode : m_destClasses.packageNodes()) { - for (ClassSelectorClassNode classNode : m_destClasses.classNodes(packageNode)) { + for (ClassSelectorPackageNode packageNode : this.destClasses.packageNodes()) { + for (ClassSelectorClassNode classNode : this.destClasses.classNodes(packageNode)) { if (firstClass == null) { firstClass = classNode.getClassEntry(); } @@ -525,14 +508,14 @@ public class ClassMatchingGui { } setDestClass(destClass); - m_destClasses.setSelectionClass(destClass); + this.destClasses.setSelectionClass(destClass); } private void toggleTop10Matches() { - if (m_sourceClass != null) { - m_destClasses.clearSelection(); - m_destClasses.setClasses(deobfuscateClasses(getLikelyMatches(m_sourceClass), m_destDeobfuscator)); - m_destClasses.expandAll(); + if (this.sourceClass != null) { + this.destClasses.clearSelection(); + this.destClasses.setClasses(deobfuscateClasses(getLikelyMatches(this.sourceClass), this.destDeobfuscator)); + this.destClasses.expandAll(); } } } diff --git a/src/main/java/cuchaz/enigma/gui/ClassSelector.java b/src/main/java/cuchaz/enigma/gui/ClassSelector.java index 0c93c439..f6abd51e 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassSelector.java +++ b/src/main/java/cuchaz/enigma/gui/ClassSelector.java @@ -58,11 +58,11 @@ public class ClassSelector extends JTree { }; } - private ClassSelectionListener m_listener; - private Comparator m_comparator; + private ClassSelectionListener listener; + private Comparator comparator; public ClassSelector(Comparator comparator) { - m_comparator = comparator; + this.comparator = comparator; // configure the tree control setRootVisible(false); @@ -73,23 +73,23 @@ public class ClassSelector extends JTree { addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent event) { - if (m_listener != null && event.getClickCount() == 2) { + if (listener != null && event.getClickCount() == 2) { // get the selected node TreePath path = getSelectionPath(); if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode) { ClassSelectorClassNode node = (ClassSelectorClassNode) path.getLastPathComponent(); - m_listener.onSelectClass(node.getClassEntry()); + listener.onSelectClass(node.getClassEntry()); } } } }); // init defaults - m_listener = null; + this.listener = null; } public void setListener(ClassSelectionListener val) { - m_listener = val; + this.listener = val; } public void setClasses(Collection classEntries) { @@ -144,7 +144,7 @@ public class ClassSelector extends JTree { for (String packageName : packagedClassEntries.keySet()) { // sort the class entries List classEntriesInPackage = Lists.newArrayList(packagedClassEntries.get(packageName)); - Collections.sort(classEntriesInPackage, m_comparator); + Collections.sort(classEntriesInPackage, this.comparator); // create the nodes in order for (ClassEntry classEntry : classEntriesInPackage) { diff --git a/src/main/java/cuchaz/enigma/gui/ClassSelectorClassNode.java b/src/main/java/cuchaz/enigma/gui/ClassSelectorClassNode.java index 6da9782f..e73340a6 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassSelectorClassNode.java +++ b/src/main/java/cuchaz/enigma/gui/ClassSelectorClassNode.java @@ -18,33 +18,30 @@ public class ClassSelectorClassNode extends DefaultMutableTreeNode { private static final long serialVersionUID = -8956754339813257380L; - private ClassEntry m_classEntry; + private ClassEntry classEntry; public ClassSelectorClassNode(ClassEntry classEntry) { - m_classEntry = classEntry; + this.classEntry = classEntry; } public ClassEntry getClassEntry() { - return m_classEntry; + return this.classEntry; } @Override public String toString() { - if (m_classEntry instanceof ScoredClassEntry) { - return String.format("%d%% %s", (int) ((ScoredClassEntry) m_classEntry).getScore(), m_classEntry.getSimpleName()); + if (this.classEntry instanceof ScoredClassEntry) { + return String.format("%d%% %s", (int) ((ScoredClassEntry) this.classEntry).getScore(), this.classEntry.getSimpleName()); } - return m_classEntry.getSimpleName(); + return this.classEntry.getSimpleName(); } @Override public boolean equals(Object other) { - if (other instanceof ClassSelectorClassNode) { - return equals((ClassSelectorClassNode) other); - } - return false; + return other instanceof ClassSelectorClassNode && equals((ClassSelectorClassNode) other); } public boolean equals(ClassSelectorClassNode other) { - return m_classEntry.equals(other.m_classEntry); + return this.classEntry.equals(other.classEntry); } } diff --git a/src/main/java/cuchaz/enigma/gui/ClassSelectorPackageNode.java b/src/main/java/cuchaz/enigma/gui/ClassSelectorPackageNode.java index 36220423..3b5ba8ca 100644 --- a/src/main/java/cuchaz/enigma/gui/ClassSelectorPackageNode.java +++ b/src/main/java/cuchaz/enigma/gui/ClassSelectorPackageNode.java @@ -16,30 +16,27 @@ public class ClassSelectorPackageNode extends DefaultMutableTreeNode { private static final long serialVersionUID = -3730868701219548043L; - private String m_packageName; + private String packageName; public ClassSelectorPackageNode(String packageName) { - m_packageName = packageName; + this.packageName = packageName; } public String getPackageName() { - return m_packageName; + return this.packageName; } @Override public String toString() { - return m_packageName; + return this.packageName; } @Override public boolean equals(Object other) { - if (other instanceof ClassSelectorPackageNode) { - return equals((ClassSelectorPackageNode) other); - } - return false; + return other instanceof ClassSelectorPackageNode && equals((ClassSelectorPackageNode) other); } public boolean equals(ClassSelectorPackageNode other) { - return m_packageName.equals(other.m_packageName); + return this.packageName.equals(other.packageName); } } diff --git a/src/main/java/cuchaz/enigma/gui/CodeReader.java b/src/main/java/cuchaz/enigma/gui/CodeReader.java index 93f9a75b..a476fa51 100644 --- a/src/main/java/cuchaz/enigma/gui/CodeReader.java +++ b/src/main/java/cuchaz/enigma/gui/CodeReader.java @@ -19,8 +19,6 @@ import java.awt.event.ActionListener; import javax.swing.JEditorPane; import javax.swing.SwingUtilities; import javax.swing.Timer; -import javax.swing.event.CaretEvent; -import javax.swing.event.CaretListener; import javax.swing.text.BadLocationException; import javax.swing.text.Highlighter.HighlightPainter; @@ -37,15 +35,15 @@ public class CodeReader extends JEditorPane { private static final long serialVersionUID = 3673180950485748810L; - private static final Object m_lock = new Object(); + private static final Object lock = new Object(); public interface SelectionListener { void onSelect(EntryReference reference); } - private SelectionHighlightPainter m_selectionHighlightPainter; - private SourceIndex m_sourceIndex; - private SelectionListener m_selectionListener; + private SelectionHighlightPainter selectionHighlightPainter; + private SourceIndex sourceIndex; + private SelectionListener selectionListener; public CodeReader() { @@ -57,42 +55,35 @@ public class CodeReader extends JEditorPane { kit.toggleComponent(this, "de.sciss.syntaxpane.components.TokenMarker"); // hook events - addCaretListener(new CaretListener() { - @Override - public void caretUpdate(CaretEvent event) { - if (m_selectionListener != null && m_sourceIndex != null) { - Token token = m_sourceIndex.getReferenceToken(event.getDot()); - if (token != null) { - m_selectionListener.onSelect(m_sourceIndex.getDeobfReference(token)); - } else { - m_selectionListener.onSelect(null); - } + addCaretListener(event -> { + if (this.selectionListener != null && this.sourceIndex != null) { + Token token = this.sourceIndex.getReferenceToken(event.getDot()); + if (token != null) { + this.selectionListener.onSelect(this.sourceIndex.getDeobfReference(token)); + } else { + this.selectionListener.onSelect(null); } } }); - m_selectionHighlightPainter = new SelectionHighlightPainter(); - m_sourceIndex = null; - m_selectionListener = null; + this.selectionHighlightPainter = new SelectionHighlightPainter(); + this.sourceIndex = null; + this.selectionListener = null; } public void setSelectionListener(SelectionListener val) { - m_selectionListener = val; + this.selectionListener = val; } public void setCode(String code) { // sadly, the java lexer is not thread safe, so we have to serialize all these calls - synchronized (m_lock) { + synchronized (lock) { setText(code); } } public SourceIndex getSourceIndex() { - return m_sourceIndex; - } - - public void decompileClass(ClassEntry classEntry, Deobfuscator deobfuscator) { - decompileClass(classEntry, deobfuscator, null); + return this.sourceIndex; } public void decompileClass(ClassEntry classEntry, Deobfuscator deobfuscator, Runnable callback) { @@ -117,7 +108,7 @@ public class CodeReader extends JEditorPane { CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getOutermostClassName()); String source = deobfuscator.getSource(sourceTree); setCode(source); - m_sourceIndex = deobfuscator.getSourceIndex(sourceTree, source, ignoreBadTokens); + sourceIndex = deobfuscator.getSourceIndex(sourceTree, source, ignoreBadTokens); if (callback != null) { callback.run(); @@ -129,13 +120,13 @@ public class CodeReader extends JEditorPane { public void navigateToClassDeclaration(ClassEntry classEntry) { // navigate to the class declaration - Token token = m_sourceIndex.getDeclarationToken(classEntry); + Token token = this.sourceIndex.getDeclarationToken(classEntry); if (token == null) { // couldn't find the class declaration token, might be an anonymous class // look for any declaration in that class instead - for (Entry entry : m_sourceIndex.declarations()) { + for (Entry entry : this.sourceIndex.declarations()) { if (entry.getClassEntry().equals(classEntry)) { - token = m_sourceIndex.getDeclarationToken(entry); + token = this.sourceIndex.getDeclarationToken(entry); break; } } @@ -150,7 +141,7 @@ public class CodeReader extends JEditorPane { } public void navigateToToken(final Token token) { - navigateToToken(this, token, m_selectionHighlightPainter); + navigateToToken(this, token, this.selectionHighlightPainter); } // HACKHACK: someday we can update the main GUI to use this code reader @@ -166,12 +157,7 @@ public class CodeReader extends JEditorPane { Rectangle end = editor.modelToView(token.end); final Rectangle show = start.union(end); show.grow(start.width * 10, start.height * 6); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - editor.scrollRectToVisible(show); - } - }); + SwingUtilities.invokeLater(() -> editor.scrollRectToVisible(show)); } catch (BadLocationException ex) { throw new Error(ex); } @@ -202,12 +188,6 @@ public class CodeReader extends JEditorPane { timer.start(); } - public void setHighlightedTokens(Iterable tokens, HighlightPainter painter) { - for (Token token : tokens) { - setHighlightedToken(token, painter); - } - } - public void setHighlightedToken(Token token, HighlightPainter painter) { try { getHighlighter().addHighlight(token.start, token.end, painter); diff --git a/src/main/java/cuchaz/enigma/gui/CrashDialog.java b/src/main/java/cuchaz/enigma/gui/CrashDialog.java index c0c0869b..3806f54e 100644 --- a/src/main/java/cuchaz/enigma/gui/CrashDialog.java +++ b/src/main/java/cuchaz/enigma/gui/CrashDialog.java @@ -13,8 +13,6 @@ package cuchaz.enigma.gui; import java.awt.BorderLayout; import java.awt.Container; import java.awt.FlowLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.io.PrintWriter; import java.io.StringWriter; @@ -31,11 +29,11 @@ public class CrashDialog { private CrashDialog(JFrame parent) { // init frame - m_frame = new JFrame(Constants.Name + " - Crash Report"); + m_frame = new JFrame(Constants.NAME + " - Crash Report"); final Container pane = m_frame.getContentPane(); pane.setLayout(new BorderLayout()); - JLabel label = new JLabel(Constants.Name + " has crashed! =("); + JLabel label = new JLabel(Constants.NAME + " has crashed! =("); label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); pane.add(label, BorderLayout.NORTH); @@ -51,21 +49,15 @@ public class CrashDialog { buttonsPanel.setLayout(buttonsLayout); buttonsPanel.add(GuiTricks.unboldLabel(new JLabel("If you choose exit, you will lose any unsaved work."))); JButton ignoreButton = new JButton("Ignore"); - ignoreButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - // close (hide) the dialog - m_frame.setVisible(false); - } + ignoreButton.addActionListener(event -> { + // close (hide) the dialog + m_frame.setVisible(false); }); buttonsPanel.add(ignoreButton); JButton exitButton = new JButton("Exit"); - exitButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - // exit enigma - System.exit(1); - } + exitButton.addActionListener(event -> { + // exit enigma + System.exit(1); }); buttonsPanel.add(exitButton); pane.add(buttonsPanel, BorderLayout.SOUTH); diff --git a/src/main/java/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java index d92bb0d2..d5ad0c8a 100644 --- a/src/main/java/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/DeobfuscatedHighlightPainter.java @@ -15,7 +15,6 @@ import java.awt.Color; public class DeobfuscatedHighlightPainter extends BoxHighlightPainter { public DeobfuscatedHighlightPainter() { - // green ish super(new Color(220, 255, 220), new Color(80, 160, 80)); } } diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index eb26ddd1..fee9c9f6 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java @@ -16,7 +16,6 @@ import java.awt.*; import java.awt.event.*; import java.io.File; import java.io.IOException; -import java.lang.Thread.UncaughtExceptionHandler; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -24,8 +23,6 @@ import java.util.Vector; import java.util.jar.JarFile; import javax.swing.*; -import javax.swing.event.CaretEvent; -import javax.swing.event.CaretListener; import javax.swing.text.BadLocationException; import javax.swing.text.Highlighter; import javax.swing.tree.DefaultTreeModel; @@ -35,7 +32,6 @@ import javax.swing.tree.TreePath; import cuchaz.enigma.Constants; import cuchaz.enigma.ExceptionIgnorer; import cuchaz.enigma.analysis.*; -import cuchaz.enigma.gui.ClassSelector.ClassSelectionListener; import cuchaz.enigma.mapping.*; import de.sciss.syntaxpane.DefaultSyntaxKit; @@ -90,20 +86,17 @@ public class Gui { public Gui() { // init frame - m_frame = new JFrame(Constants.Name); + m_frame = new JFrame(Constants.NAME); final Container pane = m_frame.getContentPane(); pane.setLayout(new BorderLayout()); if (Boolean.parseBoolean(System.getProperty("enigma.catchExceptions", "true"))) { // install a global exception handler to the event thread CrashDialog.init(m_frame); - Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread thread, Throwable t) { - t.printStackTrace(System.err); - if (!ExceptionIgnorer.shouldIgnore(t)) { - CrashDialog.show(t); - } + Thread.setDefaultUncaughtExceptionHandler((thread, t) -> { + t.printStackTrace(System.err); + if (!ExceptionIgnorer.shouldIgnore(t)) { + CrashDialog.show(t); } }); } @@ -116,19 +109,14 @@ public class Gui { m_mappingsFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); m_mappingsFileChooser.setAcceptAllFileFilterUsed(false); - m_oldMappingsFileChooser= new JFileChooser(); + m_oldMappingsFileChooser = new JFileChooser(); m_exportSourceFileChooser = new JFileChooser(); m_exportSourceFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); m_exportJarFileChooser = new JFileChooser(); // init obfuscated classes list m_obfClasses = new ClassSelector(ClassSelector.ObfuscatedClassEntryComparator); - m_obfClasses.setListener(new ClassSelectionListener() { - @Override - public void onSelectClass(ClassEntry classEntry) { - navigateTo(classEntry); - } - }); + m_obfClasses.setListener(this::navigateTo); JScrollPane obfScroller = new JScrollPane(m_obfClasses); JPanel obfPanel = new JPanel(); obfPanel.setLayout(new BorderLayout()); @@ -137,12 +125,7 @@ public class Gui { // init deobfuscated classes list m_deobfClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); - m_deobfClasses.setListener(new ClassSelectionListener() { - @Override - public void onSelectClass(ClassEntry classEntry) { - navigateTo(classEntry); - } - }); + m_deobfClasses.setListener(this::navigateTo); JScrollPane deobfScroller = new JScrollPane(m_deobfClasses); JPanel deobfPanel = new JPanel(); deobfPanel.setLayout(new BorderLayout()); @@ -174,12 +157,7 @@ public class Gui { m_editor.setCaret(new BrowserCaret()); JScrollPane sourceScroller = new JScrollPane(m_editor); m_editor.setContentType("text/java"); - m_editor.addCaretListener(new CaretListener() { - @Override - public void caretUpdate(CaretEvent event) { - onCaretMove(event.getDot()); - } - }); + m_editor.addCaretListener(event -> onCaretMove(event.getDot())); m_editor.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { @@ -224,12 +202,7 @@ public class Gui { m_editor.setComponentPopupMenu(popupMenu); { JMenuItem menu = new JMenuItem("Rename"); - menu.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - startRename(); - } - }); + menu.addActionListener(event -> startRename()); menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, 0)); menu.setEnabled(false); popupMenu.add(menu); @@ -237,12 +210,7 @@ public class Gui { } { JMenuItem menu = new JMenuItem("Show Inheritance"); - menu.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - showInheritance(); - } - }); + menu.addActionListener(event -> showInheritance()); menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, 0)); menu.setEnabled(false); popupMenu.add(menu); @@ -250,12 +218,7 @@ public class Gui { } { JMenuItem menu = new JMenuItem("Show Implementations"); - menu.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - showImplementations(); - } - }); + menu.addActionListener(event -> showImplementations()); menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, 0)); menu.setEnabled(false); popupMenu.add(menu); @@ -263,12 +226,7 @@ public class Gui { } { JMenuItem menu = new JMenuItem("Show Calls"); - menu.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - showCalls(); - } - }); + menu.addActionListener(event -> showCalls()); menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 0)); menu.setEnabled(false); popupMenu.add(menu); @@ -276,12 +234,7 @@ public class Gui { } { JMenuItem menu = new JMenuItem("Go to Declaration"); - menu.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - navigateTo(m_reference.entry); - } - }); + menu.addActionListener(event -> navigateTo(m_reference.entry)); menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 0)); menu.setEnabled(false); popupMenu.add(menu); @@ -289,12 +242,7 @@ public class Gui { } { JMenuItem menu = new JMenuItem("Go to previous"); - menu.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - m_controller.openPreviousReference(); - } - }); + menu.addActionListener(event -> m_controller.openPreviousReference()); menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, 0)); menu.setEnabled(false); popupMenu.add(menu); @@ -302,12 +250,7 @@ public class Gui { } { JMenuItem menu = new JMenuItem("Mark as deobfuscated"); - menu.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - toggleMapping(); - } - }); + menu.addActionListener(event -> toggleMapping()); menu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, 0)); menu.setEnabled(false); popupMenu.add(menu); @@ -398,7 +341,7 @@ public class Gui { } } }); - m_tokens = new JList(); + m_tokens = new JList<>(); m_tokens.setCellRenderer(new TokenListCellRenderer(m_controller)); m_tokens.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m_tokens.setLayoutOrientation(JList.VERTICAL); @@ -450,51 +393,40 @@ public class Gui { { JMenuItem item = new JMenuItem("Open Jar..."); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - if (m_jarFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { - // load the jar in a separate thread - new Thread() { - @Override - public void run() { - try { - m_controller.openJar(new JarFile(m_jarFileChooser.getSelectedFile())); - } catch (IOException ex) { - throw new Error(ex); - } + item.addActionListener(event -> { + if (m_jarFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + // load the jar in a separate thread + new Thread() { + @Override + public void run() { + try { + m_controller.openJar(new JarFile(m_jarFileChooser.getSelectedFile())); + } catch (IOException ex) { + throw new Error(ex); } - }.start(); - } + } + }.start(); } }); } { JMenuItem item = new JMenuItem("Close Jar"); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - m_controller.closeJar(); - } - }); + item.addActionListener(event -> m_controller.closeJar()); m_closeJarMenu = item; } menu.addSeparator(); { JMenuItem item = new JMenuItem("Open Mappings..."); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - if (m_mappingsFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { - try { - m_controller.openMappings(m_mappingsFileChooser.getSelectedFile()); - } catch (IOException ex) { - throw new Error(ex); - } catch (MappingParseException ex) { - JOptionPane.showMessageDialog(m_frame, ex.getMessage()); - } + item.addActionListener(event -> { + if (m_mappingsFileChooser.showOpenDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + try { + m_controller.openMappings(m_mappingsFileChooser.getSelectedFile()); + } catch (IOException ex) { + throw new Error(ex); + } catch (MappingParseException ex) { + JOptionPane.showMessageDialog(m_frame, ex.getMessage()); } } }); @@ -520,14 +452,11 @@ public class Gui { { JMenuItem item = new JMenuItem("Save Mappings"); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - try { - m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); - } catch (IOException ex) { - throw new Error(ex); - } + item.addActionListener(event -> { + try { + m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); + } catch (IOException ex) { + throw new Error(ex); } }); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); @@ -536,16 +465,13 @@ public class Gui { { JMenuItem item = new JMenuItem("Save Mappings As..."); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - if (m_mappingsFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { - try { - m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); - m_saveMappingsMenu.setEnabled(true); - } catch (IOException ex) { - throw new Error(ex); - } + item.addActionListener(event -> { + if (m_mappingsFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + try { + m_controller.saveMappings(m_mappingsFileChooser.getSelectedFile()); + m_saveMappingsMenu.setEnabled(true); + } catch (IOException ex) { + throw new Error(ex); } } }); @@ -555,24 +481,16 @@ public class Gui { { JMenuItem item = new JMenuItem("Close Mappings"); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - m_controller.closeMappings(); - } - }); + item.addActionListener(event -> m_controller.closeMappings()); m_closeMappingsMenu = item; } menu.addSeparator(); { JMenuItem item = new JMenuItem("Export Source..."); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - if (m_exportSourceFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { - m_controller.exportSource(m_exportSourceFileChooser.getSelectedFile()); - } + item.addActionListener(event -> { + if (m_exportSourceFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + m_controller.exportSource(m_exportSourceFileChooser.getSelectedFile()); } }); m_exportSourceMenu = item; @@ -580,12 +498,9 @@ public class Gui { { JMenuItem item = new JMenuItem("Export Jar..."); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - if (m_exportJarFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { - m_controller.exportJar(m_exportJarFileChooser.getSelectedFile()); - } + item.addActionListener(event -> { + if (m_exportJarFileChooser.showSaveDialog(m_frame) == JFileChooser.APPROVE_OPTION) { + m_controller.exportJar(m_exportJarFileChooser.getSelectedFile()); } }); m_exportJarMenu = item; @@ -594,12 +509,7 @@ public class Gui { { JMenuItem item = new JMenuItem("Exit"); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - close(); - } - }); + item.addActionListener(event -> close()); } } { @@ -608,12 +518,7 @@ public class Gui { { JMenuItem item = new JMenuItem("About"); menu.add(item); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - AboutDialog.show(m_frame); - } - }); + item.addActionListener(event -> AboutDialog.show(m_frame)); } } @@ -654,7 +559,7 @@ public class Gui { public void onFinishOpenJar(String jarName) { // update gui - m_frame.setTitle(Constants.Name + " - " + jarName); + m_frame.setTitle(Constants.NAME + " - " + jarName); m_classesPanel.removeAll(); m_classesPanel.add(m_splitClasses); setSource(null); @@ -674,7 +579,7 @@ public class Gui { public void onCloseJar() { // update gui - m_frame.setTitle(Constants.Name); + m_frame.setTitle(Constants.NAME); setObfClasses(null); setDeobfClasses(null); setSource(null); @@ -720,14 +625,14 @@ public class Gui { } public void showTokens(Collection tokens) { - Vector sortedTokens = new Vector(tokens); + Vector sortedTokens = new Vector<>(tokens); Collections.sort(sortedTokens); if (sortedTokens.size() > 1) { // sort the tokens and update the tokens panel m_tokens.setListData(sortedTokens); m_tokens.setSelectedIndex(0); } else { - m_tokens.setListData(new Vector()); + m_tokens.setListData(new Vector<>()); } // show the first token diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index a6a2ec52..868e0d48 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java @@ -24,162 +24,138 @@ import java.util.List; import java.util.jar.JarFile; import cuchaz.enigma.Deobfuscator; -import cuchaz.enigma.Deobfuscator.ProgressListener; import cuchaz.enigma.analysis.*; -import cuchaz.enigma.gui.ProgressDialog.ProgressRunnable; import cuchaz.enigma.mapping.*; public class GuiController { - private Deobfuscator m_deobfuscator; - private Gui m_gui; - private SourceIndex m_index; - private ClassEntry m_currentObfClass; - private boolean m_isDirty; - private Deque> m_referenceStack; + private Deobfuscator deobfuscator; + private Gui gui; + private SourceIndex index; + private ClassEntry currentObfClass; + private boolean isDirty; + private Deque> referenceStack; public GuiController(Gui gui) { - m_gui = gui; - m_deobfuscator = null; - m_index = null; - m_currentObfClass = null; - m_isDirty = false; - m_referenceStack = Queues.newArrayDeque(); + this.gui = gui; + this.deobfuscator = null; + this.index = null; + this.currentObfClass = null; + this.isDirty = false; + this.referenceStack = Queues.newArrayDeque(); } public boolean isDirty() { - return m_isDirty; + return this.isDirty; } public void openJar(final JarFile jar) throws IOException { - m_gui.onStartOpenJar(); - m_deobfuscator = new Deobfuscator(jar); - m_gui.onFinishOpenJar(m_deobfuscator.getJarName()); + this.gui.onStartOpenJar(); + this.deobfuscator = new Deobfuscator(jar); + this.gui.onFinishOpenJar(this.deobfuscator.getJarName()); refreshClasses(); } public void closeJar() { - m_deobfuscator = null; - m_gui.onCloseJar(); + this.deobfuscator = null; + this.gui.onCloseJar(); } public void openOldMappings(File file) throws IOException, MappingParseException { FileReader in = new FileReader(file); - m_deobfuscator.setMappings(new MappingsReaderOld().read(in)); + this.deobfuscator.setMappings(new MappingsReaderOld().read(in)); in.close(); - m_isDirty = false; - m_gui.setMappingsFile(file); + this.isDirty = false; + this.gui.setMappingsFile(file); refreshClasses(); refreshCurrentClass(); } public void openMappings(File file) throws IOException, MappingParseException { - m_deobfuscator.setMappings(new MappingsReader().read(file)); - m_isDirty = false; - m_gui.setMappingsFile(file); + this.deobfuscator.setMappings(new MappingsReader().read(file)); + this.isDirty = false; + this.gui.setMappingsFile(file); refreshClasses(); refreshCurrentClass(); } public void saveMappings(File file) throws IOException { - new MappingsWriter().write(file, m_deobfuscator.getMappings()); - m_isDirty = false; + new MappingsWriter().write(file, this.deobfuscator.getMappings()); + this.isDirty = false; } public void closeMappings() { - m_deobfuscator.setMappings(null); - m_gui.setMappingsFile(null); + this.deobfuscator.setMappings(null); + this.gui.setMappingsFile(null); refreshClasses(); refreshCurrentClass(); } public void exportSource(final File dirOut) { - ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { - @Override - public void run(ProgressListener progress) throws Exception { - m_deobfuscator.writeSources(dirOut, progress); - } - }); + ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeSources(dirOut, progress)); } public void exportJar(final File fileOut) { - ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { - @Override - public void run(ProgressListener progress) { - m_deobfuscator.writeJar(fileOut, progress); - } - }); + ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeJar(fileOut, progress)); } public Token getToken(int pos) { - if (m_index == null) { + if (this.index == null) { return null; } - return m_index.getReferenceToken(pos); + return this.index.getReferenceToken(pos); } public EntryReference getDeobfReference(Token token) { - if (m_index == null) { + if (this.index == null) { return null; } - return m_index.getDeobfReference(token); + return this.index.getDeobfReference(token); } public ReadableToken getReadableToken(Token token) { - if (m_index == null) { + if (this.index == null) { return null; } return new ReadableToken( - m_index.getLineNumber(token.start), - m_index.getColumnNumber(token.start), - m_index.getColumnNumber(token.end) + this.index.getLineNumber(token.start), + this.index.getColumnNumber(token.start), + this.index.getColumnNumber(token.end) ); } public boolean entryHasDeobfuscatedName(Entry deobfEntry) { - return m_deobfuscator.hasDeobfuscatedName(m_deobfuscator.obfuscateEntry(deobfEntry)); + return this.deobfuscator.hasDeobfuscatedName(this.deobfuscator.obfuscateEntry(deobfEntry)); } public boolean entryIsInJar(Entry deobfEntry) { - return m_deobfuscator.isObfuscatedIdentifier(m_deobfuscator.obfuscateEntry(deobfEntry)); + return this.deobfuscator.isObfuscatedIdentifier(this.deobfuscator.obfuscateEntry(deobfEntry)); } public boolean referenceIsRenameable(EntryReference deobfReference) { - return m_deobfuscator.isRenameable(m_deobfuscator.obfuscateReference(deobfReference)); + return this.deobfuscator.isRenameable(this.deobfuscator.obfuscateReference(deobfReference)); } public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) { - ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); - ClassInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getClassInheritance( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfClassEntry - ); + ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); + ClassInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getClassInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); return ClassInheritanceTreeNode.findNode(rootNode, obfClassEntry); } public ClassImplementationsTreeNode getClassImplementations(ClassEntry deobfClassEntry) { - ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); - return m_deobfuscator.getJarIndex().getClassImplementations( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfClassEntry - ); + ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); + return this.deobfuscator.getJarIndex().getClassImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); } public MethodInheritanceTreeNode getMethodInheritance(MethodEntry deobfMethodEntry) { - MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); - MethodInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodInheritance( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfMethodEntry - ); + MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); + MethodInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getMethodInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); return MethodInheritanceTreeNode.findNode(rootNode, obfMethodEntry); } public MethodImplementationsTreeNode getMethodImplementations(MethodEntry deobfMethodEntry) { - MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); - List rootNodes = m_deobfuscator.getJarIndex().getMethodImplementations( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfMethodEntry - ); + MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); + List rootNodes = this.deobfuscator.getJarIndex().getMethodImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); if (rootNodes.isEmpty()) { return null; } @@ -190,45 +166,39 @@ public class GuiController { } public FieldReferenceTreeNode getFieldReferences(FieldEntry deobfFieldEntry) { - FieldEntry obfFieldEntry = m_deobfuscator.obfuscateEntry(deobfFieldEntry); - FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfFieldEntry - ); - rootNode.load(m_deobfuscator.getJarIndex(), true); + FieldEntry obfFieldEntry = this.deobfuscator.obfuscateEntry(deobfFieldEntry); + FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfFieldEntry); + rootNode.load(this.deobfuscator.getJarIndex(), true); return rootNode; } public BehaviorReferenceTreeNode getMethodReferences(BehaviorEntry deobfBehaviorEntry) { - BehaviorEntry obfBehaviorEntry = m_deobfuscator.obfuscateEntry(deobfBehaviorEntry); - BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfBehaviorEntry - ); - rootNode.load(m_deobfuscator.getJarIndex(), true); + BehaviorEntry obfBehaviorEntry = this.deobfuscator.obfuscateEntry(deobfBehaviorEntry); + BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfBehaviorEntry); + rootNode.load(this.deobfuscator.getJarIndex(), true); return rootNode; } public void rename(EntryReference deobfReference, String newName) { - EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); - m_deobfuscator.rename(obfReference.getNameableEntry(), newName); - m_isDirty = true; + EntryReference obfReference = this.deobfuscator.obfuscateReference(deobfReference); + this.deobfuscator.rename(obfReference.getNameableEntry(), newName); + this.isDirty = true; refreshClasses(); refreshCurrentClass(obfReference); } public void removeMapping(EntryReference deobfReference) { - EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); - m_deobfuscator.removeMapping(obfReference.getNameableEntry()); - m_isDirty = true; + EntryReference obfReference = this.deobfuscator.obfuscateReference(deobfReference); + this.deobfuscator.removeMapping(obfReference.getNameableEntry()); + this.isDirty = true; refreshClasses(); refreshCurrentClass(obfReference); } public void markAsDeobfuscated(EntryReference deobfReference) { - EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); - m_deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); - m_isDirty = true; + EntryReference obfReference = this.deobfuscator.obfuscateReference(deobfReference); + this.deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); + this.isDirty = true; refreshClasses(); refreshCurrentClass(obfReference); } @@ -237,7 +207,7 @@ public class GuiController { if (deobfEntry == null) { throw new IllegalArgumentException("Entry cannot be null!"); } - openReference(new EntryReference(deobfEntry, deobfEntry.getName())); + openReference(new EntryReference<>(deobfEntry, deobfEntry.getName())); } public void openReference(EntryReference deobfReference) { @@ -246,51 +216,51 @@ public class GuiController { } // get the reference target class - EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); + EntryReference obfReference = this.deobfuscator.obfuscateReference(deobfReference); ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOutermostClassEntry(); - if (!m_deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { + if (!this.deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { throw new IllegalArgumentException("Obfuscated class " + obfClassEntry + " was not found in the jar!"); } - if (m_currentObfClass == null || !m_currentObfClass.equals(obfClassEntry)) { + if (this.currentObfClass == null || !this.currentObfClass.equals(obfClassEntry)) { // deobfuscate the class, then navigate to the reference - m_currentObfClass = obfClassEntry; - deobfuscate(m_currentObfClass, obfReference); + this.currentObfClass = obfClassEntry; + deobfuscate(this.currentObfClass, obfReference); } else { showReference(obfReference); } } private void showReference(EntryReference obfReference) { - EntryReference deobfReference = m_deobfuscator.deobfuscateReference(obfReference); - Collection tokens = m_index.getReferenceTokens(deobfReference); + EntryReference deobfReference = this.deobfuscator.deobfuscateReference(obfReference); + Collection tokens = this.index.getReferenceTokens(deobfReference); if (tokens.isEmpty()) { // DEBUG - System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, m_currentObfClass)); + System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, this.currentObfClass)); } else { - m_gui.showTokens(tokens); + this.gui.showTokens(tokens); } } public void savePreviousReference(EntryReference deobfReference) { - m_referenceStack.push(m_deobfuscator.obfuscateReference(deobfReference)); + this.referenceStack.push(this.deobfuscator.obfuscateReference(deobfReference)); } public void openPreviousReference() { if (hasPreviousLocation()) { - openReference(m_deobfuscator.deobfuscateReference(m_referenceStack.pop())); + openReference(this.deobfuscator.deobfuscateReference(this.referenceStack.pop())); } } public boolean hasPreviousLocation() { - return !m_referenceStack.isEmpty(); + return !this.referenceStack.isEmpty(); } private void refreshClasses() { List obfClasses = Lists.newArrayList(); List deobfClasses = Lists.newArrayList(); - m_deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); - m_gui.setObfClasses(obfClasses); - m_gui.setDeobfClasses(deobfClasses); + this.deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); + this.gui.setObfClasses(obfClasses); + this.gui.setDeobfClasses(deobfClasses); } private void refreshCurrentClass() { @@ -298,29 +268,29 @@ public class GuiController { } private void refreshCurrentClass(EntryReference obfReference) { - if (m_currentObfClass != null) { - deobfuscate(m_currentObfClass, obfReference); + if (this.currentObfClass != null) { + deobfuscate(this.currentObfClass, obfReference); } } private void deobfuscate(final ClassEntry classEntry, final EntryReference obfReference) { - m_gui.setSource("(deobfuscating...)"); + this.gui.setSource("(deobfuscating...)"); // run the deobfuscator in a separate thread so we don't block the GUI event queue new Thread() { @Override public void run() { // decompile,deobfuscate the bytecode - CompilationUnit sourceTree = m_deobfuscator.getSourceTree(classEntry.getClassName()); + CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getClassName()); if (sourceTree == null) { // decompilation of this class is not supported - m_gui.setSource("Unable to find class: " + classEntry); + gui.setSource("Unable to find class: " + classEntry); return; } - String source = m_deobfuscator.getSource(sourceTree); - m_index = m_deobfuscator.getSourceIndex(sourceTree, source); - m_gui.setSource(m_index.getSource()); + String source = deobfuscator.getSource(sourceTree); + index = deobfuscator.getSourceIndex(sourceTree, source); + gui.setSource(index.getSource()); if (obfReference != null) { showReference(obfReference); } @@ -329,8 +299,8 @@ public class GuiController { List obfuscatedTokens = Lists.newArrayList(); List deobfuscatedTokens = Lists.newArrayList(); List otherTokens = Lists.newArrayList(); - for (Token token : m_index.referenceTokens()) { - EntryReference reference = m_index.getDeobfReference(token); + for (Token token : index.referenceTokens()) { + EntryReference reference = index.getDeobfReference(token); if (referenceIsRenameable(reference)) { if (entryHasDeobfuscatedName(reference.getNameableEntry())) { deobfuscatedTokens.add(token); @@ -341,7 +311,7 @@ public class GuiController { otherTokens.add(token); } } - m_gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); + gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); } }.start(); } diff --git a/src/main/java/cuchaz/enigma/gui/GuiTricks.java b/src/main/java/cuchaz/enigma/gui/GuiTricks.java index da2ec74f..ffacfecf 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiTricks.java +++ b/src/main/java/cuchaz/enigma/gui/GuiTricks.java @@ -40,17 +40,13 @@ public class GuiTricks { public static void deactivateButton(JButton button) { button.setEnabled(false); button.setText(""); - for (ActionListener listener : Arrays.asList(button.getActionListeners())) { - button.removeActionListener(listener); - } + Arrays.asList(button.getActionListeners()).forEach(button::removeActionListener); } public static void activateButton(JButton button, String text, ActionListener newListener) { button.setText(text); button.setEnabled(true); - for (ActionListener listener : Arrays.asList(button.getActionListeners())) { - button.removeActionListener(listener); - } + Arrays.asList(button.getActionListeners()).forEach(button::removeActionListener); button.addActionListener(newListener); } } diff --git a/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java b/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java index 4b79b77c..f083e50f 100644 --- a/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java +++ b/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java @@ -17,7 +17,6 @@ import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; -import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; @@ -30,12 +29,10 @@ import javax.swing.text.Highlighter.HighlightPainter; import cuchaz.enigma.Constants; import cuchaz.enigma.Deobfuscator; -import cuchaz.enigma.analysis.EntryReference; import cuchaz.enigma.analysis.SourceIndex; import cuchaz.enigma.analysis.Token; import cuchaz.enigma.convert.ClassMatches; import cuchaz.enigma.convert.MemberMatches; -import cuchaz.enigma.gui.ClassSelector.ClassSelectionListener; import cuchaz.enigma.mapping.ClassEntry; import cuchaz.enigma.mapping.Entry; import de.sciss.syntaxpane.DefaultSyntaxKit; @@ -108,7 +105,7 @@ public class MemberMatchingGui { m_destDeobfuscator = destDeobfuscator; // init frame - m_frame = new JFrame(Constants.Name + " - Member Matcher"); + m_frame = new JFrame(Constants.NAME + " - Member Matcher"); final Container pane = m_frame.getContentPane(); pane.setLayout(new BorderLayout()); @@ -123,12 +120,7 @@ public class MemberMatchingGui { JPanel sourceTypePanel = new JPanel(); classesPanel.add(sourceTypePanel); sourceTypePanel.setLayout(new BoxLayout(sourceTypePanel, BoxLayout.PAGE_AXIS)); - ActionListener sourceTypeListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - setSourceType(SourceType.valueOf(event.getActionCommand())); - } - }; + ActionListener sourceTypeListener = event -> setSourceType(SourceType.valueOf(event.getActionCommand())); ButtonGroup sourceTypeButtons = new ButtonGroup(); m_sourceTypeButtons = Maps.newHashMap(); for (SourceType sourceType : SourceType.values()) { @@ -138,37 +130,26 @@ public class MemberMatchingGui { } m_sourceClasses = new ClassSelector(ClassSelector.DeobfuscatedClassEntryComparator); - m_sourceClasses.setListener(new ClassSelectionListener() { - @Override - public void onSelectClass(ClassEntry classEntry) { - setSourceClass(classEntry); - } - }); + m_sourceClasses.setListener(this::setSourceClass); JScrollPane sourceScroller = new JScrollPane(m_sourceClasses); classesPanel.add(sourceScroller); // init readers DefaultSyntaxKit.initKit(); m_sourceReader = new CodeReader(); - m_sourceReader.setSelectionListener(new CodeReader.SelectionListener() { - @Override - public void onSelect(EntryReference reference) { - if (reference != null) { - onSelectSource(reference.entry); - } else { - onSelectSource(null); - } + m_sourceReader.setSelectionListener(reference -> { + if (reference != null) { + onSelectSource(reference.entry); + } else { + onSelectSource(null); } }); m_destReader = new CodeReader(); - m_destReader.setSelectionListener(new CodeReader.SelectionListener() { - @Override - public void onSelect(EntryReference reference) { - if (reference != null) { - onSelectDest(reference.entry); - } else { - onSelectDest(null); - } + m_destReader.setSelectionListener(reference -> { + if (reference != null) { + onSelectDest(reference.entry); + } else { + onSelectDest(null); } }); @@ -267,18 +248,8 @@ public class MemberMatchingGui { throw new Error("No matching dest class for source class: " + m_obfSourceClass); } - m_sourceReader.decompileClass(m_obfSourceClass, m_sourceDeobfuscator, false, new Runnable() { - @Override - public void run() { - updateSourceHighlights(); - } - }); - m_destReader.decompileClass(m_obfDestClass, m_destDeobfuscator, false, new Runnable() { - @Override - public void run() { - updateDestHighlights(); - } - }); + m_sourceReader.decompileClass(m_obfSourceClass, m_sourceDeobfuscator, false, this::updateSourceHighlights); + m_destReader.decompileClass(m_obfDestClass, m_destDeobfuscator, false, this::updateDestHighlights); } protected void updateSourceHighlights() { @@ -382,21 +353,19 @@ public class MemberMatchingGui { } private void setSource(T obfEntry) { + m_obfSourceEntry = obfEntry; if (obfEntry == null) { - m_obfSourceEntry = obfEntry; m_sourceLabel.setText(""); } else { - m_obfSourceEntry = obfEntry; m_sourceLabel.setText(getEntryLabel(obfEntry, m_sourceDeobfuscator)); } } private void setDest(T obfEntry) { + m_obfDestEntry = obfEntry; if (obfEntry == null) { - m_obfDestEntry = obfEntry; m_destLabel.setText(""); } else { - m_obfDestEntry = obfEntry; m_destLabel.setText(getEntryLabel(obfEntry, m_destDeobfuscator)); } } @@ -414,27 +383,12 @@ public class MemberMatchingGui { if (m_obfSourceEntry != null && m_obfDestEntry != null) { if (m_memberMatches.isMatched(m_obfSourceEntry, m_obfDestEntry)) { - GuiTricks.activateButton(m_matchButton, "Unmatch", new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - unmatch(); - } - }); + GuiTricks.activateButton(m_matchButton, "Unmatch", event -> unmatch()); } else if (!m_memberMatches.isMatchedSourceEntry(m_obfSourceEntry) && !m_memberMatches.isMatchedDestEntry(m_obfDestEntry)) { - GuiTricks.activateButton(m_matchButton, "Match", new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - match(); - } - }); + GuiTricks.activateButton(m_matchButton, "Match", event -> match()); } } else if (m_obfSourceEntry != null) { - GuiTricks.activateButton(m_unmatchableButton, "Set Unmatchable", new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - unmatchable(); - } - }); + GuiTricks.activateButton(m_unmatchableButton, "Set Unmatchable", event -> unmatchable()); } } diff --git a/src/main/java/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java index caaf99c3..5afc767f 100644 --- a/src/main/java/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/ObfuscatedHighlightPainter.java @@ -15,7 +15,6 @@ import java.awt.Color; public class ObfuscatedHighlightPainter extends BoxHighlightPainter { public ObfuscatedHighlightPainter() { - // red ish super(new Color(255, 220, 220), new Color(160, 80, 80)); } } diff --git a/src/main/java/cuchaz/enigma/gui/OtherHighlightPainter.java b/src/main/java/cuchaz/enigma/gui/OtherHighlightPainter.java index d2a2f02f..256f69eb 100644 --- a/src/main/java/cuchaz/enigma/gui/OtherHighlightPainter.java +++ b/src/main/java/cuchaz/enigma/gui/OtherHighlightPainter.java @@ -15,7 +15,6 @@ import java.awt.Color; public class OtherHighlightPainter extends BoxHighlightPainter { public OtherHighlightPainter() { - // grey super(null, new Color(180, 180, 180)); } } diff --git a/src/main/java/cuchaz/enigma/gui/ProgressDialog.java b/src/main/java/cuchaz/enigma/gui/ProgressDialog.java index 087d843b..70bca15b 100644 --- a/src/main/java/cuchaz/enigma/gui/ProgressDialog.java +++ b/src/main/java/cuchaz/enigma/gui/ProgressDialog.java @@ -22,63 +22,63 @@ import cuchaz.enigma.Deobfuscator.ProgressListener; public class ProgressDialog implements ProgressListener, AutoCloseable { - private JFrame m_frame; - private JLabel m_title; - private JLabel m_text; - private JProgressBar m_progress; + private JFrame frame; + private JLabel labelTitle; + private JLabel labelText; + private JProgressBar progress; public ProgressDialog(JFrame parent) { // init frame - m_frame = new JFrame(Constants.Name + " - Operation in progress"); - final Container pane = m_frame.getContentPane(); + this.frame = new JFrame(Constants.NAME + " - Operation in progress"); + final Container pane = this.frame.getContentPane(); FlowLayout layout = new FlowLayout(); layout.setAlignment(FlowLayout.LEFT); pane.setLayout(layout); - m_title = new JLabel(); - pane.add(m_title); + this.labelTitle = new JLabel(); + pane.add(this.labelTitle); // set up the progress bar JPanel panel = new JPanel(); pane.add(panel); panel.setLayout(new BorderLayout()); - m_text = GuiTricks.unboldLabel(new JLabel()); - m_progress = new JProgressBar(); - m_text.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); - panel.add(m_text, BorderLayout.NORTH); - panel.add(m_progress, BorderLayout.CENTER); + this.labelText = GuiTricks.unboldLabel(new JLabel()); + this.progress = new JProgressBar(); + this.labelText.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); + panel.add(this.labelText, BorderLayout.NORTH); + panel.add(this.progress, BorderLayout.CENTER); panel.setPreferredSize(new Dimension(360, 50)); // show the frame pane.doLayout(); - m_frame.setSize(400, 120); - m_frame.setResizable(false); - m_frame.setLocationRelativeTo(parent); - m_frame.setVisible(true); - m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + this.frame.setSize(400, 120); + this.frame.setResizable(false); + this.frame.setLocationRelativeTo(parent); + this.frame.setVisible(true); + this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); } public void close() { - m_frame.dispose(); + this.frame.dispose(); } @Override public void init(int totalWork, String title) { - m_title.setText(title); - m_progress.setMinimum(0); - m_progress.setMaximum(totalWork); - m_progress.setValue(0); + this.labelTitle.setText(title); + this.progress.setMinimum(0); + this.progress.setMaximum(totalWork); + this.progress.setValue(0); } @Override public void onProgress(int numDone, String message) { - m_text.setText(message); - m_progress.setValue(numDone); + this.labelText.setText(message); + this.progress.setValue(numDone); // update the frame - m_frame.validate(); - m_frame.repaint(); + this.frame.validate(); + this.frame.repaint(); } public interface ProgressRunnable { diff --git a/src/main/java/cuchaz/enigma/gui/RenameListener.java b/src/main/java/cuchaz/enigma/gui/RenameListener.java deleted file mode 100644 index f0f9dcc4..00000000 --- a/src/main/java/cuchaz/enigma/gui/RenameListener.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *

- * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ -package cuchaz.enigma.gui; - -import cuchaz.enigma.mapping.Entry; - -public interface RenameListener { - void rename(Entry obfEntry, String newName); -} diff --git a/src/main/java/cuchaz/enigma/gui/ScoredClassEntry.java b/src/main/java/cuchaz/enigma/gui/ScoredClassEntry.java index d1e2de0e..359ec7ae 100644 --- a/src/main/java/cuchaz/enigma/gui/ScoredClassEntry.java +++ b/src/main/java/cuchaz/enigma/gui/ScoredClassEntry.java @@ -12,19 +12,18 @@ package cuchaz.enigma.gui; import cuchaz.enigma.mapping.ClassEntry; - public class ScoredClassEntry extends ClassEntry { private static final long serialVersionUID = -8798725308554217105L; - private float m_score; + private float score; public ScoredClassEntry(ClassEntry other, float score) { super(other); - m_score = score; + this.score = score; } public float getScore() { - return m_score; + return this.score; } } diff --git a/src/main/java/cuchaz/enigma/gui/TokenListCellRenderer.java b/src/main/java/cuchaz/enigma/gui/TokenListCellRenderer.java index efc8df8b..518055fd 100644 --- a/src/main/java/cuchaz/enigma/gui/TokenListCellRenderer.java +++ b/src/main/java/cuchaz/enigma/gui/TokenListCellRenderer.java @@ -21,18 +21,18 @@ import cuchaz.enigma.analysis.Token; public class TokenListCellRenderer implements ListCellRenderer { - private GuiController m_controller; - private DefaultListCellRenderer m_defaultRenderer; + private GuiController controller; + private DefaultListCellRenderer defaultRenderer; public TokenListCellRenderer(GuiController controller) { - m_controller = controller; - m_defaultRenderer = new DefaultListCellRenderer(); + this.controller = controller; + this.defaultRenderer = new DefaultListCellRenderer(); } @Override public Component getListCellRendererComponent(JList list, Token token, int index, boolean isSelected, boolean hasFocus) { - JLabel label = (JLabel) m_defaultRenderer.getListCellRendererComponent(list, token, index, isSelected, hasFocus); - label.setText(m_controller.getReadableToken(token).toString()); + JLabel label = (JLabel) this.defaultRenderer.getListCellRendererComponent(list, token, index, isSelected, hasFocus); + label.setText(this.controller.getReadableToken(token).toString()); return label; } } diff --git a/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java b/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java index 886e7be2..c89f7e33 100644 --- a/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java @@ -97,10 +97,7 @@ public class ArgumentEntry implements Entry, Serializable { @Override public boolean equals(Object other) { - if (other instanceof ArgumentEntry) { - return equals((ArgumentEntry) other); - } - return false; + return other instanceof ArgumentEntry && equals((ArgumentEntry) other); } public boolean equals(ArgumentEntry other) { diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index 84fb6dd8..99e463de 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java @@ -444,10 +444,7 @@ public class ClassMapping implements Serializable, Comparable { public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfBehaviorEntry.getName(), obfBehaviorEntry.getSignature())); - if (methodMapping != null) { - return methodMapping.containsArgument(name); - } - return false; + return methodMapping != null && methodMapping.containsArgument(name); } public static boolean isSimpleClassName(String name) { diff --git a/src/main/java/cuchaz/enigma/mapping/ConstructorEntry.java b/src/main/java/cuchaz/enigma/mapping/ConstructorEntry.java index 907bd4ce..ac1a7f2b 100644 --- a/src/main/java/cuchaz/enigma/mapping/ConstructorEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/ConstructorEntry.java @@ -87,10 +87,7 @@ public class ConstructorEntry implements BehaviorEntry, Serializable { @Override public boolean equals(Object other) { - if (other instanceof ConstructorEntry) { - return equals((ConstructorEntry) other); - } - return false; + return other instanceof ConstructorEntry && equals((ConstructorEntry) other); } public boolean equals(ConstructorEntry other) { diff --git a/src/main/java/cuchaz/enigma/mapping/FieldMapping.java b/src/main/java/cuchaz/enigma/mapping/FieldMapping.java index 3f5a3822..19d68a97 100644 --- a/src/main/java/cuchaz/enigma/mapping/FieldMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/FieldMapping.java @@ -16,67 +16,64 @@ public class FieldMapping implements Serializable, Comparable, Mem private static final long serialVersionUID = 8610742471440861315L; - private String m_obfName; - private String m_deobfName; - private Type m_obfType; + private String obfName; + private String deobfName; + private Type obfType; public FieldMapping(String obfName, Type obfType, String deobfName) { - m_obfName = obfName; - m_deobfName = NameValidator.validateFieldName(deobfName); - m_obfType = obfType; + this.obfName = obfName; + this.deobfName = NameValidator.validateFieldName(deobfName); + this.obfType = obfType; } public FieldMapping(FieldMapping other, ClassNameReplacer obfClassNameReplacer) { - m_obfName = other.m_obfName; - m_deobfName = other.m_deobfName; - m_obfType = new Type(other.m_obfType, obfClassNameReplacer); + this.obfName = other.obfName; + this.deobfName = other.deobfName; + this.obfType = new Type(other.obfType, obfClassNameReplacer); } @Override public String getObfName() { - return m_obfName; + return this.obfName; } public void setObfName(String val) { - m_obfName = NameValidator.validateFieldName(val); + this.obfName = NameValidator.validateFieldName(val); } public String getDeobfName() { - return m_deobfName; + return this.deobfName; } public void setDeobfName(String val) { - m_deobfName = NameValidator.validateFieldName(val); + this.deobfName = NameValidator.validateFieldName(val); } public Type getObfType() { - return m_obfType; + return this.obfType; } public void setObfType(Type val) { - m_obfType = val; + this.obfType = val; } @Override public int compareTo(FieldMapping other) { - return (m_obfName + m_obfType).compareTo(other.m_obfName + other.m_obfType); + return (this.obfName + this.obfType).compareTo(other.obfName + other.obfType); } public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { // rename obf classes in the type - Type newType = new Type(m_obfType, new ClassNameReplacer() { - @Override - public String replace(String className) { - if (className.equals(oldObfClassName)) { - return newObfClassName; - } - return null; + Type newType = new Type(this.obfType, className -> { + if (className.equals(oldObfClassName)) { + return newObfClassName; } + return null; }); - if (!newType.equals(m_obfType)) { - m_obfType = newType; + if (!newType.equals(this.obfType)) { + this.obfType = newType; return true; } return false; @@ -84,6 +81,6 @@ public class FieldMapping implements Serializable, Comparable, Mem @Override public FieldEntry getObfEntry(ClassEntry classEntry) { - return new FieldEntry(classEntry, m_obfName, new Type(m_obfType)); + return new FieldEntry(classEntry, this.obfName, new Type(this.obfType)); } } diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java index 5e2b40b2..d8507877 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java @@ -16,13 +16,11 @@ import com.google.common.collect.Maps; import java.util.Map; import cuchaz.enigma.analysis.JarIndex; -import cuchaz.enigma.analysis.RelatedMethodChecker; public class MappingsChecker { private JarIndex m_index; - private RelatedMethodChecker m_relatedMethodChecker; private Map m_droppedClassMappings; private Map m_droppedInnerClassMappings; private Map m_droppedFieldMappings; @@ -30,17 +28,12 @@ public class MappingsChecker { public MappingsChecker(JarIndex index) { m_index = index; - m_relatedMethodChecker = new RelatedMethodChecker(m_index); m_droppedClassMappings = Maps.newHashMap(); m_droppedInnerClassMappings = Maps.newHashMap(); m_droppedFieldMappings = Maps.newHashMap(); m_droppedMethodMappings = Maps.newHashMap(); } - public RelatedMethodChecker getRelatedMethodChecker() { - return m_relatedMethodChecker; - } - public Map getDroppedClassMappings() { return m_droppedClassMappings; } diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java index b2c3a5c0..d1edb9b6 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java @@ -31,19 +31,21 @@ public class MappingsReader { public void readDirectory(Mappings mappings, File in) throws IOException, MappingParseException { File[] fList = in.listFiles(); - for (File file : fList) { - if (file.isFile()) { - readFile(mappings, new BufferedReader(new FileReader(file))); - } else if (file.isDirectory()) { - readDirectory(mappings, file.getAbsoluteFile()); + if (fList != null) { + for (File file : fList) { + if (file.isFile()) { + readFile(mappings, new BufferedReader(new FileReader(file))); + } else if (file.isDirectory()) { + readDirectory(mappings, file.getAbsoluteFile()); + } } } } public void readFile(Mappings mappings, BufferedReader in) throws IOException, MappingParseException { - StringBuffer buf = new StringBuffer(); - String line = null; + StringBuilder buf = new StringBuilder(); + String line; while ((line = in.readLine()) != null) { buf.append(line); } @@ -63,10 +65,10 @@ public class MappingsReader { jsonClass.getField().forEach(jsonField -> classMapping.addFieldMapping(readField(jsonField.getObf(), jsonField.getName(), jsonField.getType()))); jsonClass.getConstructors().forEach(jsonConstructor -> { - MethodMapping methodMapping = readMethod(jsonConstructor.isStatics() ? "" : "", null, jsonConstructor.getSignature()); - jsonConstructor.getArgs().forEach(jsonArgument -> methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName()))); - classMapping.addMethodMapping(methodMapping); - }); + MethodMapping methodMapping = readMethod(jsonConstructor.isStatics() ? "" : "", null, jsonConstructor.getSignature()); + jsonConstructor.getArgs().forEach(jsonArgument -> methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName()))); + classMapping.addMethodMapping(methodMapping); + }); jsonClass.getMethod().forEach(jsonMethod -> { MethodMapping methodMapping = readMethod(jsonMethod.getObf(), jsonMethod.getName(), jsonMethod.getSignature()); diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java b/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java index 1a93604a..a23a33fa 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java @@ -18,7 +18,7 @@ public class MappingsReaderOld { Deque mappingStack = Queues.newArrayDeque(); int lineNumber = 0; - String line = null; + String line; while ((line = in.readLine()) != null) { lineNumber++; diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java index de1635aa..2b112a24 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java @@ -129,9 +129,7 @@ public class MappingsRenamer { } public void removeMethodTreeMapping(MethodEntry obf) { - for (MethodEntry implementation : m_index.getRelatedMethodImplementations(obf)) { - removeMethodMapping(implementation); - } + m_index.getRelatedMethodImplementations(obf).forEach(this::removeMethodMapping); } public void removeMethodMapping(MethodEntry obf) { @@ -140,9 +138,7 @@ public class MappingsRenamer { } public void markMethodTreeAsDeobfuscated(MethodEntry obf) { - for (MethodEntry implementation : m_index.getRelatedMethodImplementations(obf)) { - markMethodAsDeobfuscated(implementation); - } + m_index.getRelatedMethodImplementations(obf).forEach(this::markMethodAsDeobfuscated); } public void markMethodAsDeobfuscated(MethodEntry obf) { diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java index aaab22fa..bfd60638 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsWriter.java @@ -76,7 +76,7 @@ public class MappingsWriter { } private > List sorted(Iterable classes) { - List out = new ArrayList(); + List out = new ArrayList<>(); for (T t : classes) { out.add(t); } diff --git a/src/main/java/cuchaz/enigma/mapping/Signature.java b/src/main/java/cuchaz/enigma/mapping/Signature.java index 117018ad..e2f9f091 100644 --- a/src/main/java/cuchaz/enigma/mapping/Signature.java +++ b/src/main/java/cuchaz/enigma/mapping/Signature.java @@ -91,10 +91,7 @@ public class Signature implements Serializable { @Override public boolean equals(Object other) { - if (other instanceof Signature) { - return equals((Signature) other); - } - return false; + return other instanceof Signature && equals((Signature) other); } public boolean equals(Signature other) { diff --git a/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java b/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java index dac692e4..98643330 100644 --- a/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java +++ b/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java @@ -28,7 +28,7 @@ public class SignatureUpdater { // read the signature character-by-character StringReader reader = new StringReader(signature); - int i = -1; + int i; while ((i = reader.read()) != -1) { char c = (char) i; @@ -60,7 +60,7 @@ public class SignatureUpdater { // remember to treat generics correctly StringBuilder buf = new StringBuilder(); int depth = 0; - int i = -1; + int i; while ((i = reader.read()) != -1) { char c = (char) i; @@ -82,12 +82,9 @@ public class SignatureUpdater { public static List getClasses(String signature) { final List classNames = Lists.newArrayList(); - update(signature, new ClassNameUpdater() { - @Override - public String update(String className) { - classNames.add(className); - return className; - } + update(signature, className -> { + classNames.add(className); + return className; }); return classNames; } diff --git a/src/main/java/cuchaz/enigma/mapping/Translator.java b/src/main/java/cuchaz/enigma/mapping/Translator.java index 2829a75f..1947d1c4 100644 --- a/src/main/java/cuchaz/enigma/mapping/Translator.java +++ b/src/main/java/cuchaz/enigma/mapping/Translator.java @@ -24,12 +24,7 @@ public class Translator { private Map m_classes; private TranslationIndex m_index; - private ClassNameReplacer m_classNameReplacer = new ClassNameReplacer() { - @Override - public String replace(String className) { - return translateEntry(new ClassEntry(className)).getName(); - } - }; + private ClassNameReplacer m_classNameReplacer = className -> translateEntry(new ClassEntry(className)).getName(); public Translator() { m_direction = null; @@ -76,7 +71,7 @@ public class Translator { } else if (entry instanceof MethodEntry) { return translate((MethodEntry) entry); } else if (entry instanceof ConstructorEntry) { - return translate((ConstructorEntry) entry); + return translate(entry); } else if (entry instanceof ArgumentEntry) { return translate((ArgumentEntry) entry); } else { diff --git a/src/main/java/cuchaz/enigma/mapping/Type.java b/src/main/java/cuchaz/enigma/mapping/Type.java index bfd836c6..f2fd34d9 100644 --- a/src/main/java/cuchaz/enigma/mapping/Type.java +++ b/src/main/java/cuchaz/enigma/mapping/Type.java @@ -205,10 +205,7 @@ public class Type implements Serializable { @Override public boolean equals(Object other) { - if (other instanceof Type) { - return equals((Type) other); - } - return false; + return other instanceof Type && equals((Type) other); } public boolean equals(Type other) { @@ -222,7 +219,6 @@ public class Type implements Serializable { private static int countArrayDimension(String in) { int i = 0; for (; i < in.length() && in.charAt(i) == '['; i++) { - ; } return i; } -- cgit v1.2.3