diff options
| author | 2016-07-02 21:57:31 +1000 | |
|---|---|---|
| committer | 2016-07-02 21:57:31 +1000 | |
| commit | 1742190f784d0d62e7cc869eebafdfe1927e448f (patch) | |
| tree | e5855ecfc0e3129ef34f6f5ee56a937c35700ef9 /src/main/java | |
| parent | Reformatting code (diff) | |
| download | enigma-1742190f784d0d62e7cc869eebafdfe1927e448f.tar.gz enigma-1742190f784d0d62e7cc869eebafdfe1927e448f.tar.xz enigma-1742190f784d0d62e7cc869eebafdfe1927e448f.zip | |
Removed unused methods
Diffstat (limited to 'src/main/java')
39 files changed, 15 insertions, 989 deletions
diff --git a/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java b/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java index a4f53e4b..942c8308 100644 --- a/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java +++ b/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java | |||
| @@ -55,10 +55,6 @@ public class TranslatingTypeLoader implements ITypeLoader { | |||
| 55 | m_defaultTypeLoader = new ClasspathTypeLoader(); | 55 | m_defaultTypeLoader = new ClasspathTypeLoader(); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | public void clearCache() { | ||
| 59 | m_cache.clear(); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Override | 58 | @Override |
| 63 | public boolean tryLoadType(String className, Buffer out) { | 59 | public boolean tryLoadType(String className, Buffer out) { |
| 64 | 60 | ||
diff --git a/src/main/java/cuchaz/enigma/Util.java b/src/main/java/cuchaz/enigma/Util.java index 1bcdb9ea..9445b2b4 100644 --- a/src/main/java/cuchaz/enigma/Util.java +++ b/src/main/java/cuchaz/enigma/Util.java | |||
| @@ -41,27 +41,6 @@ public class Util { | |||
| 41 | return result; | 41 | return result; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | public static void closeQuietly(Closeable closeable) { | ||
| 45 | if (closeable != null) { | ||
| 46 | try { | ||
| 47 | closeable.close(); | ||
| 48 | } catch (IOException ex) { | ||
| 49 | // just ignore any further exceptions | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | public static void closeQuietly(JarFile jarFile) { | ||
| 55 | // silly library should implement Closeable... | ||
| 56 | if (jarFile != null) { | ||
| 57 | try { | ||
| 58 | jarFile.close(); | ||
| 59 | } catch (IOException ex) { | ||
| 60 | // just ignore any further exceptions | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | public static String readStreamToString(InputStream in) throws IOException { | 44 | public static String readStreamToString(InputStream in) throws IOException { |
| 66 | return CharStreams.toString(new InputStreamReader(in, "UTF-8")); | 45 | return CharStreams.toString(new InputStreamReader(in, "UTF-8")); |
| 67 | } | 46 | } |
| @@ -86,14 +65,4 @@ public class Util { | |||
| 86 | } | 65 | } |
| 87 | } | 66 | } |
| 88 | } | 67 | } |
| 89 | |||
| 90 | public static void writeClass(CtClass c) { | ||
| 91 | String name = Descriptor.toJavaName(c.getName()); | ||
| 92 | File file = new File(name + ".class"); | ||
| 93 | try (FileOutputStream out = new FileOutputStream(file)) { | ||
| 94 | out.write(c.toBytecode()); | ||
| 95 | } catch (IOException | CannotCompileException ex) { | ||
| 96 | throw new Error(ex); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | } | 68 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/Access.java b/src/main/java/cuchaz/enigma/analysis/Access.java index 877327f1..ec5ac1ec 100644 --- a/src/main/java/cuchaz/enigma/analysis/Access.java +++ b/src/main/java/cuchaz/enigma/analysis/Access.java | |||
| @@ -30,9 +30,7 @@ public enum Access { | |||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | public static Access get(int modifiers) { | 32 | public static Access get(int modifiers) { |
| 33 | if (Modifier.isPublic(modifiers)) { | 33 | if (Modifier.isProtected(modifiers)) { |
| 34 | return Public; | ||
| 35 | } else if (Modifier.isProtected(modifiers)) { | ||
| 36 | return Protected; | 34 | return Protected; |
| 37 | } else if (Modifier.isPrivate(modifiers)) { | 35 | } else if (Modifier.isPrivate(modifiers)) { |
| 38 | return Private; | 36 | return Private; |
diff --git a/src/main/java/cuchaz/enigma/analysis/BridgeMarker.java b/src/main/java/cuchaz/enigma/analysis/BridgeMarker.java index cd185846..d6db11c0 100644 --- a/src/main/java/cuchaz/enigma/analysis/BridgeMarker.java +++ b/src/main/java/cuchaz/enigma/analysis/BridgeMarker.java | |||
| @@ -18,7 +18,7 @@ import javassist.bytecode.AccessFlag; | |||
| 18 | 18 | ||
| 19 | public class BridgeMarker { | 19 | public class BridgeMarker { |
| 20 | 20 | ||
| 21 | private JarIndex m_jarIndex; | 21 | private final JarIndex m_jarIndex; |
| 22 | 22 | ||
| 23 | public BridgeMarker(JarIndex jarIndex) { | 23 | public BridgeMarker(JarIndex jarIndex) { |
| 24 | this.m_jarIndex = jarIndex; | 24 | this.m_jarIndex = jarIndex; |
diff --git a/src/main/java/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java b/src/main/java/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java index 3420cd6d..b1d1dee5 100644 --- a/src/main/java/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java +++ b/src/main/java/cuchaz/enigma/analysis/ClassImplementationsTreeNode.java | |||
| @@ -17,7 +17,6 @@ import java.util.List; | |||
| 17 | import javax.swing.tree.DefaultMutableTreeNode; | 17 | import javax.swing.tree.DefaultMutableTreeNode; |
| 18 | 18 | ||
| 19 | import cuchaz.enigma.mapping.ClassEntry; | 19 | import cuchaz.enigma.mapping.ClassEntry; |
| 20 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 21 | import cuchaz.enigma.mapping.Translator; | 20 | import cuchaz.enigma.mapping.Translator; |
| 22 | 21 | ||
| 23 | public class ClassImplementationsTreeNode extends DefaultMutableTreeNode { | 22 | public class ClassImplementationsTreeNode extends DefaultMutableTreeNode { |
| @@ -59,20 +58,4 @@ public class ClassImplementationsTreeNode extends DefaultMutableTreeNode { | |||
| 59 | // add them to this node | 58 | // add them to this node |
| 60 | nodes.forEach(this::add); | 59 | nodes.forEach(this::add); |
| 61 | } | 60 | } |
| 62 | |||
| 63 | public static ClassImplementationsTreeNode findNode(ClassImplementationsTreeNode node, MethodEntry entry) { | ||
| 64 | // is this the node? | ||
| 65 | if (node.entry.equals(entry)) { | ||
| 66 | return node; | ||
| 67 | } | ||
| 68 | |||
| 69 | // recurse | ||
| 70 | for (int i = 0; i < node.getChildCount(); i++) { | ||
| 71 | ClassImplementationsTreeNode foundNode = findNode((ClassImplementationsTreeNode) node.getChildAt(i), entry); | ||
| 72 | if (foundNode != null) { | ||
| 73 | return foundNode; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | return null; | ||
| 77 | } | ||
| 78 | } | 61 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java b/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java index a885c6a4..9a85f6ee 100644 --- a/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java +++ b/src/main/java/cuchaz/enigma/analysis/EntryRenamer.java | |||
| @@ -56,30 +56,6 @@ public class EntryRenamer { | |||
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | public static <Key, Val> void renameMethodsInMultimap(Map<MethodEntry, MethodEntry> renames, Multimap<Key, Val> map) { | ||
| 60 | // for each key/value pair... | ||
| 61 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); | ||
| 62 | for (Map.Entry<Key, Val> entry : map.entries()) { | ||
| 63 | entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameMethodsInThing(renames, entry.getKey()), renameMethodsInThing(renames, entry.getValue()))); | ||
| 64 | } | ||
| 65 | map.clear(); | ||
| 66 | for (Map.Entry<Key, Val> entry : entriesToAdd) { | ||
| 67 | map.put(entry.getKey(), entry.getValue()); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | public static <Key, Val> void renameMethodsInMap(Map<MethodEntry, MethodEntry> renames, Map<Key, Val> map) { | ||
| 72 | // for each key/value pair... | ||
| 73 | Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet(); | ||
| 74 | for (Map.Entry<Key, Val> entry : map.entrySet()) { | ||
| 75 | entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameMethodsInThing(renames, entry.getKey()), renameMethodsInThing(renames, entry.getValue()))); | ||
| 76 | } | ||
| 77 | map.clear(); | ||
| 78 | for (Map.Entry<Key, Val> entry : entriesToAdd) { | ||
| 79 | map.put(entry.getKey(), entry.getValue()); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | @SuppressWarnings("unchecked") | 59 | @SuppressWarnings("unchecked") |
| 84 | public static <T> T renameMethodsInThing(Map<MethodEntry, MethodEntry> renames, T thing) { | 60 | public static <T> T renameMethodsInThing(Map<MethodEntry, MethodEntry> renames, T thing) { |
| 85 | if (thing instanceof MethodEntry) { | 61 | if (thing instanceof MethodEntry) { |
diff --git a/src/main/java/cuchaz/enigma/analysis/JarIndex.java b/src/main/java/cuchaz/enigma/analysis/JarIndex.java index 377a8cb2..bd670905 100644 --- a/src/main/java/cuchaz/enigma/analysis/JarIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/JarIndex.java | |||
| @@ -507,18 +507,10 @@ public class JarIndex { | |||
| 507 | return this.fields.values(); | 507 | return this.fields.values(); |
| 508 | } | 508 | } |
| 509 | 509 | ||
| 510 | public Collection<FieldEntry> getObfFieldEntries(ClassEntry classEntry) { | ||
| 511 | return this.fields.get(classEntry); | ||
| 512 | } | ||
| 513 | |||
| 514 | public Collection<BehaviorEntry> getObfBehaviorEntries() { | 510 | public Collection<BehaviorEntry> getObfBehaviorEntries() { |
| 515 | return this.behaviors.values(); | 511 | return this.behaviors.values(); |
| 516 | } | 512 | } |
| 517 | 513 | ||
| 518 | public Collection<BehaviorEntry> getObfBehaviorEntries(ClassEntry classEntry) { | ||
| 519 | return this.behaviors.get(classEntry); | ||
| 520 | } | ||
| 521 | |||
| 522 | public TranslationIndex getTranslationIndex() { | 514 | public TranslationIndex getTranslationIndex() { |
| 523 | return this.translationIndex; | 515 | return this.translationIndex; |
| 524 | } | 516 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/SourceIndex.java b/src/main/java/cuchaz/enigma/analysis/SourceIndex.java index 719930e9..3fa1309a 100644 --- a/src/main/java/cuchaz/enigma/analysis/SourceIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/SourceIndex.java | |||
| @@ -145,10 +145,6 @@ public class SourceIndex { | |||
| 145 | return this.tokenToReference.keySet(); | 145 | return this.tokenToReference.keySet(); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | public Iterable<Token> declarationTokens() { | ||
| 149 | return this.declarationToToken.values(); | ||
| 150 | } | ||
| 151 | |||
| 152 | public Iterable<Entry> declarations() { | 148 | public Iterable<Entry> declarations() { |
| 153 | return this.declarationToToken.keySet(); | 149 | return this.declarationToToken.keySet(); |
| 154 | } | 150 | } |
diff --git a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java index adb87b6f..3d8f5560 100644 --- a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java | |||
| @@ -152,13 +152,6 @@ public class TranslationIndex implements Serializable { | |||
| 152 | return subclasses; | 152 | return subclasses; |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | public void getSubclassesRecursively(Set<ClassEntry> out, ClassEntry classEntry) { | ||
| 156 | for (ClassEntry subclassEntry : getSubclass(classEntry)) { | ||
| 157 | out.add(subclassEntry); | ||
| 158 | getSubclassesRecursively(out, subclassEntry); | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | public void getSubclassNamesRecursively(Set<String> out, ClassEntry classEntry) { | 155 | public void getSubclassNamesRecursively(Set<String> out, ClassEntry classEntry) { |
| 163 | for (ClassEntry subclassEntry : getSubclass(classEntry)) { | 156 | for (ClassEntry subclassEntry : getSubclass(classEntry)) { |
| 164 | out.add(subclassEntry.getName()); | 157 | out.add(subclassEntry.getName()); |
diff --git a/src/main/java/cuchaz/enigma/analysis/TreeDumpVisitor.java b/src/main/java/cuchaz/enigma/analysis/TreeDumpVisitor.java deleted file mode 100644 index ef8a190c..00000000 --- a/src/main/java/cuchaz/enigma/analysis/TreeDumpVisitor.java +++ /dev/null | |||
| @@ -1,441 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.analysis; | ||
| 12 | |||
| 13 | import com.strobel.componentmodel.Key; | ||
| 14 | import com.strobel.decompiler.languages.java.ast.*; | ||
| 15 | import com.strobel.decompiler.patterns.Pattern; | ||
| 16 | |||
| 17 | import java.io.File; | ||
| 18 | import java.io.FileWriter; | ||
| 19 | import java.io.IOException; | ||
| 20 | import java.io.Writer; | ||
| 21 | |||
| 22 | public class TreeDumpVisitor implements IAstVisitor<Void, Void> { | ||
| 23 | |||
| 24 | private File m_file; | ||
| 25 | private Writer m_out; | ||
| 26 | |||
| 27 | public TreeDumpVisitor(File file) { | ||
| 28 | m_file = file; | ||
| 29 | m_out = null; | ||
| 30 | } | ||
| 31 | |||
| 32 | @Override | ||
| 33 | public Void visitCompilationUnit(CompilationUnit node, Void ignored) { | ||
| 34 | try { | ||
| 35 | m_out = new FileWriter(m_file); | ||
| 36 | recurse(node, ignored); | ||
| 37 | m_out.close(); | ||
| 38 | return null; | ||
| 39 | } catch (IOException ex) { | ||
| 40 | throw new Error(ex); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | private Void recurse(AstNode node, Void ignored) { | ||
| 45 | // show the tree | ||
| 46 | try { | ||
| 47 | m_out.write(getIndent(node) + node.getClass().getSimpleName() + " " + getText(node) + " " + dumpUserData(node) + " " + node.getRegion() + "\n"); | ||
| 48 | } catch (IOException ex) { | ||
| 49 | throw new Error(ex); | ||
| 50 | } | ||
| 51 | |||
| 52 | // recurse | ||
| 53 | for (final AstNode child : node.getChildren()) { | ||
| 54 | child.acceptVisitor(this, ignored); | ||
| 55 | } | ||
| 56 | return null; | ||
| 57 | } | ||
| 58 | |||
| 59 | private String getText(AstNode node) { | ||
| 60 | if (node instanceof Identifier) { | ||
| 61 | return "\"" + ((Identifier) node).getName() + "\""; | ||
| 62 | } | ||
| 63 | return ""; | ||
| 64 | } | ||
| 65 | |||
| 66 | private String dumpUserData(AstNode node) { | ||
| 67 | StringBuilder buf = new StringBuilder(); | ||
| 68 | for (Key<?> key : Keys.ALL_KEYS) { | ||
| 69 | Object val = node.getUserData(key); | ||
| 70 | if (val != null) { | ||
| 71 | buf.append(String.format(" [%s=%s]", key, val)); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | return buf.toString(); | ||
| 75 | } | ||
| 76 | |||
| 77 | private String getIndent(AstNode node) { | ||
| 78 | StringBuilder buf = new StringBuilder(); | ||
| 79 | int depth = getDepth(node); | ||
| 80 | for (int i = 0; i < depth; i++) { | ||
| 81 | buf.append("\t"); | ||
| 82 | } | ||
| 83 | return buf.toString(); | ||
| 84 | } | ||
| 85 | |||
| 86 | private int getDepth(AstNode node) { | ||
| 87 | int depth = -1; | ||
| 88 | while (node != null) { | ||
| 89 | depth++; | ||
| 90 | node = node.getParent(); | ||
| 91 | } | ||
| 92 | return depth; | ||
| 93 | } | ||
| 94 | |||
| 95 | // OVERRIDES WE DON'T CARE ABOUT | ||
| 96 | |||
| 97 | @Override | ||
| 98 | public Void visitInvocationExpression(InvocationExpression node, Void ignored) { | ||
| 99 | return recurse(node, ignored); | ||
| 100 | } | ||
| 101 | |||
| 102 | @Override | ||
| 103 | public Void visitMemberReferenceExpression(MemberReferenceExpression node, Void ignored) { | ||
| 104 | return recurse(node, ignored); | ||
| 105 | } | ||
| 106 | |||
| 107 | @Override | ||
| 108 | public Void visitSimpleType(SimpleType node, Void ignored) { | ||
| 109 | return recurse(node, ignored); | ||
| 110 | } | ||
| 111 | |||
| 112 | @Override | ||
| 113 | public Void visitMethodDeclaration(MethodDeclaration node, Void ignored) { | ||
| 114 | return recurse(node, ignored); | ||
| 115 | } | ||
| 116 | |||
| 117 | @Override | ||
| 118 | public Void visitConstructorDeclaration(ConstructorDeclaration node, Void ignored) { | ||
| 119 | return recurse(node, ignored); | ||
| 120 | } | ||
| 121 | |||
| 122 | @Override | ||
| 123 | public Void visitParameterDeclaration(ParameterDeclaration node, Void ignored) { | ||
| 124 | return recurse(node, ignored); | ||
| 125 | } | ||
| 126 | |||
| 127 | @Override | ||
| 128 | public Void visitFieldDeclaration(FieldDeclaration node, Void ignored) { | ||
| 129 | return recurse(node, ignored); | ||
| 130 | } | ||
| 131 | |||
| 132 | @Override | ||
| 133 | public Void visitTypeDeclaration(TypeDeclaration node, Void ignored) { | ||
| 134 | return recurse(node, ignored); | ||
| 135 | } | ||
| 136 | |||
| 137 | @Override | ||
| 138 | public Void visitComment(Comment node, Void ignored) { | ||
| 139 | return recurse(node, ignored); | ||
| 140 | } | ||
| 141 | |||
| 142 | @Override | ||
| 143 | public Void visitPatternPlaceholder(AstNode node, Pattern pattern, Void ignored) { | ||
| 144 | return recurse(node, ignored); | ||
| 145 | } | ||
| 146 | |||
| 147 | @Override | ||
| 148 | public Void visitTypeReference(TypeReferenceExpression node, Void ignored) { | ||
| 149 | return recurse(node, ignored); | ||
| 150 | } | ||
| 151 | |||
| 152 | @Override | ||
| 153 | public Void visitJavaTokenNode(JavaTokenNode node, Void ignored) { | ||
| 154 | return recurse(node, ignored); | ||
| 155 | } | ||
| 156 | |||
| 157 | @Override | ||
| 158 | public Void visitIdentifier(Identifier node, Void ignored) { | ||
| 159 | return recurse(node, ignored); | ||
| 160 | } | ||
| 161 | |||
| 162 | @Override | ||
| 163 | public Void visitNullReferenceExpression(NullReferenceExpression node, Void ignored) { | ||
| 164 | return recurse(node, ignored); | ||
| 165 | } | ||
| 166 | |||
| 167 | @Override | ||
| 168 | public Void visitThisReferenceExpression(ThisReferenceExpression node, Void ignored) { | ||
| 169 | return recurse(node, ignored); | ||
| 170 | } | ||
| 171 | |||
| 172 | @Override | ||
| 173 | public Void visitSuperReferenceExpression(SuperReferenceExpression node, Void ignored) { | ||
| 174 | return recurse(node, ignored); | ||
| 175 | } | ||
| 176 | |||
| 177 | @Override | ||
| 178 | public Void visitClassOfExpression(ClassOfExpression node, Void ignored) { | ||
| 179 | return recurse(node, ignored); | ||
| 180 | } | ||
| 181 | |||
| 182 | @Override | ||
| 183 | public Void visitBlockStatement(BlockStatement node, Void ignored) { | ||
| 184 | return recurse(node, ignored); | ||
| 185 | } | ||
| 186 | |||
| 187 | @Override | ||
| 188 | public Void visitExpressionStatement(ExpressionStatement node, Void ignored) { | ||
| 189 | return recurse(node, ignored); | ||
| 190 | } | ||
| 191 | |||
| 192 | @Override | ||
| 193 | public Void visitBreakStatement(BreakStatement node, Void ignored) { | ||
| 194 | return recurse(node, ignored); | ||
| 195 | } | ||
| 196 | |||
| 197 | @Override | ||
| 198 | public Void visitContinueStatement(ContinueStatement node, Void ignored) { | ||
| 199 | return recurse(node, ignored); | ||
| 200 | } | ||
| 201 | |||
| 202 | @Override | ||
| 203 | public Void visitDoWhileStatement(DoWhileStatement node, Void ignored) { | ||
| 204 | return recurse(node, ignored); | ||
| 205 | } | ||
| 206 | |||
| 207 | @Override | ||
| 208 | public Void visitEmptyStatement(EmptyStatement node, Void ignored) { | ||
| 209 | return recurse(node, ignored); | ||
| 210 | } | ||
| 211 | |||
| 212 | @Override | ||
| 213 | public Void visitIfElseStatement(IfElseStatement node, Void ignored) { | ||
| 214 | return recurse(node, ignored); | ||
| 215 | } | ||
| 216 | |||
| 217 | @Override | ||
| 218 | public Void visitLabelStatement(LabelStatement node, Void ignored) { | ||
| 219 | return recurse(node, ignored); | ||
| 220 | } | ||
| 221 | |||
| 222 | @Override | ||
| 223 | public Void visitLabeledStatement(LabeledStatement node, Void ignored) { | ||
| 224 | return recurse(node, ignored); | ||
| 225 | } | ||
| 226 | |||
| 227 | @Override | ||
| 228 | public Void visitReturnStatement(ReturnStatement node, Void ignored) { | ||
| 229 | return recurse(node, ignored); | ||
| 230 | } | ||
| 231 | |||
| 232 | @Override | ||
| 233 | public Void visitSwitchStatement(SwitchStatement node, Void ignored) { | ||
| 234 | return recurse(node, ignored); | ||
| 235 | } | ||
| 236 | |||
| 237 | @Override | ||
| 238 | public Void visitSwitchSection(SwitchSection node, Void ignored) { | ||
| 239 | return recurse(node, ignored); | ||
| 240 | } | ||
| 241 | |||
| 242 | @Override | ||
| 243 | public Void visitCaseLabel(CaseLabel node, Void ignored) { | ||
| 244 | return recurse(node, ignored); | ||
| 245 | } | ||
| 246 | |||
| 247 | @Override | ||
| 248 | public Void visitThrowStatement(ThrowStatement node, Void ignored) { | ||
| 249 | return recurse(node, ignored); | ||
| 250 | } | ||
| 251 | |||
| 252 | @Override | ||
| 253 | public Void visitCatchClause(CatchClause node, Void ignored) { | ||
| 254 | return recurse(node, ignored); | ||
| 255 | } | ||
| 256 | |||
| 257 | @Override | ||
| 258 | public Void visitAnnotation(Annotation node, Void ignored) { | ||
| 259 | return recurse(node, ignored); | ||
| 260 | } | ||
| 261 | |||
| 262 | @Override | ||
| 263 | public Void visitNewLine(NewLineNode node, Void ignored) { | ||
| 264 | return recurse(node, ignored); | ||
| 265 | } | ||
| 266 | |||
| 267 | @Override | ||
| 268 | public Void visitVariableDeclaration(VariableDeclarationStatement node, Void ignored) { | ||
| 269 | return recurse(node, ignored); | ||
| 270 | } | ||
| 271 | |||
| 272 | @Override | ||
| 273 | public Void visitVariableInitializer(VariableInitializer node, Void ignored) { | ||
| 274 | return recurse(node, ignored); | ||
| 275 | } | ||
| 276 | |||
| 277 | @Override | ||
| 278 | public Void visitText(TextNode node, Void ignored) { | ||
| 279 | return recurse(node, ignored); | ||
| 280 | } | ||
| 281 | |||
| 282 | @Override | ||
| 283 | public Void visitImportDeclaration(ImportDeclaration node, Void ignored) { | ||
| 284 | return recurse(node, ignored); | ||
| 285 | } | ||
| 286 | |||
| 287 | @Override | ||
| 288 | public Void visitInitializerBlock(InstanceInitializer node, Void ignored) { | ||
| 289 | return recurse(node, ignored); | ||
| 290 | } | ||
| 291 | |||
| 292 | @Override | ||
| 293 | public Void visitTypeParameterDeclaration(TypeParameterDeclaration node, Void ignored) { | ||
| 294 | return recurse(node, ignored); | ||
| 295 | } | ||
| 296 | |||
| 297 | @Override | ||
| 298 | public Void visitPackageDeclaration(PackageDeclaration node, Void ignored) { | ||
| 299 | return recurse(node, ignored); | ||
| 300 | } | ||
| 301 | |||
| 302 | @Override | ||
| 303 | public Void visitArraySpecifier(ArraySpecifier node, Void ignored) { | ||
| 304 | return recurse(node, ignored); | ||
| 305 | } | ||
| 306 | |||
| 307 | @Override | ||
| 308 | public Void visitComposedType(ComposedType node, Void ignored) { | ||
| 309 | return recurse(node, ignored); | ||
| 310 | } | ||
| 311 | |||
| 312 | @Override | ||
| 313 | public Void visitWhileStatement(WhileStatement node, Void ignored) { | ||
| 314 | return recurse(node, ignored); | ||
| 315 | } | ||
| 316 | |||
| 317 | @Override | ||
| 318 | public Void visitPrimitiveExpression(PrimitiveExpression node, Void ignored) { | ||
| 319 | return recurse(node, ignored); | ||
| 320 | } | ||
| 321 | |||
| 322 | @Override | ||
| 323 | public Void visitCastExpression(CastExpression node, Void ignored) { | ||
| 324 | return recurse(node, ignored); | ||
| 325 | } | ||
| 326 | |||
| 327 | @Override | ||
| 328 | public Void visitBinaryOperatorExpression(BinaryOperatorExpression node, Void ignored) { | ||
| 329 | return recurse(node, ignored); | ||
| 330 | } | ||
| 331 | |||
| 332 | @Override | ||
| 333 | public Void visitInstanceOfExpression(InstanceOfExpression node, Void ignored) { | ||
| 334 | return recurse(node, ignored); | ||
| 335 | } | ||
| 336 | |||
| 337 | @Override | ||
| 338 | public Void visitIndexerExpression(IndexerExpression node, Void ignored) { | ||
| 339 | return recurse(node, ignored); | ||
| 340 | } | ||
| 341 | |||
| 342 | @Override | ||
| 343 | public Void visitIdentifierExpression(IdentifierExpression node, Void ignored) { | ||
| 344 | return recurse(node, ignored); | ||
| 345 | } | ||
| 346 | |||
| 347 | @Override | ||
| 348 | public Void visitUnaryOperatorExpression(UnaryOperatorExpression node, Void ignored) { | ||
| 349 | return recurse(node, ignored); | ||
| 350 | } | ||
| 351 | |||
| 352 | @Override | ||
| 353 | public Void visitConditionalExpression(ConditionalExpression node, Void ignored) { | ||
| 354 | return recurse(node, ignored); | ||
| 355 | } | ||
| 356 | |||
| 357 | @Override | ||
| 358 | public Void visitArrayInitializerExpression(ArrayInitializerExpression node, Void ignored) { | ||
| 359 | return recurse(node, ignored); | ||
| 360 | } | ||
| 361 | |||
| 362 | @Override | ||
| 363 | public Void visitObjectCreationExpression(ObjectCreationExpression node, Void ignored) { | ||
| 364 | return recurse(node, ignored); | ||
| 365 | } | ||
| 366 | |||
| 367 | @Override | ||
| 368 | public Void visitArrayCreationExpression(ArrayCreationExpression node, Void ignored) { | ||
| 369 | return recurse(node, ignored); | ||
| 370 | } | ||
| 371 | |||
| 372 | @Override | ||
| 373 | public Void visitAssignmentExpression(AssignmentExpression node, Void ignored) { | ||
| 374 | return recurse(node, ignored); | ||
| 375 | } | ||
| 376 | |||
| 377 | @Override | ||
| 378 | public Void visitForStatement(ForStatement node, Void ignored) { | ||
| 379 | return recurse(node, ignored); | ||
| 380 | } | ||
| 381 | |||
| 382 | @Override | ||
| 383 | public Void visitForEachStatement(ForEachStatement node, Void ignored) { | ||
| 384 | return recurse(node, ignored); | ||
| 385 | } | ||
| 386 | |||
| 387 | @Override | ||
| 388 | public Void visitTryCatchStatement(TryCatchStatement node, Void ignored) { | ||
| 389 | return recurse(node, ignored); | ||
| 390 | } | ||
| 391 | |||
| 392 | @Override | ||
| 393 | public Void visitGotoStatement(GotoStatement node, Void ignored) { | ||
| 394 | return recurse(node, ignored); | ||
| 395 | } | ||
| 396 | |||
| 397 | @Override | ||
| 398 | public Void visitParenthesizedExpression(ParenthesizedExpression node, Void ignored) { | ||
| 399 | return recurse(node, ignored); | ||
| 400 | } | ||
| 401 | |||
| 402 | @Override | ||
| 403 | public Void visitSynchronizedStatement(SynchronizedStatement node, Void ignored) { | ||
| 404 | return recurse(node, ignored); | ||
| 405 | } | ||
| 406 | |||
| 407 | @Override | ||
| 408 | public Void visitAnonymousObjectCreationExpression(AnonymousObjectCreationExpression node, Void ignored) { | ||
| 409 | return recurse(node, ignored); | ||
| 410 | } | ||
| 411 | |||
| 412 | @Override | ||
| 413 | public Void visitWildcardType(WildcardType node, Void ignored) { | ||
| 414 | return recurse(node, ignored); | ||
| 415 | } | ||
| 416 | |||
| 417 | @Override | ||
| 418 | public Void visitMethodGroupExpression(MethodGroupExpression node, Void ignored) { | ||
| 419 | return recurse(node, ignored); | ||
| 420 | } | ||
| 421 | |||
| 422 | @Override | ||
| 423 | public Void visitEnumValueDeclaration(EnumValueDeclaration node, Void ignored) { | ||
| 424 | return recurse(node, ignored); | ||
| 425 | } | ||
| 426 | |||
| 427 | @Override | ||
| 428 | public Void visitAssertStatement(AssertStatement node, Void ignored) { | ||
| 429 | return recurse(node, ignored); | ||
| 430 | } | ||
| 431 | |||
| 432 | @Override | ||
| 433 | public Void visitLambdaExpression(LambdaExpression node, Void ignored) { | ||
| 434 | return recurse(node, ignored); | ||
| 435 | } | ||
| 436 | |||
| 437 | @Override | ||
| 438 | public Void visitLocalTypeDeclarationStatement(LocalTypeDeclarationStatement node, Void ignored) { | ||
| 439 | return recurse(node, ignored); | ||
| 440 | } | ||
| 441 | } | ||
diff --git a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java index 19c39d3c..c47a7703 100644 --- a/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java +++ b/src/main/java/cuchaz/enigma/bytecode/CheckCastIterator.java | |||
| @@ -22,8 +22,8 @@ public class CheckCastIterator implements Iterator<CheckCast> { | |||
| 22 | 22 | ||
| 23 | public static class CheckCast { | 23 | public static class CheckCast { |
| 24 | 24 | ||
| 25 | public String className; | 25 | public final String className; |
| 26 | public MethodEntry prevMethodEntry; | 26 | public final MethodEntry prevMethodEntry; |
| 27 | 27 | ||
| 28 | public CheckCast(String className, MethodEntry prevMethodEntry) { | 28 | public CheckCast(String className, MethodEntry prevMethodEntry) { |
| 29 | this.className = className; | 29 | this.className = className; |
| @@ -31,9 +31,9 @@ public class CheckCastIterator implements Iterator<CheckCast> { | |||
| 31 | } | 31 | } |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | private ConstPool constants; | 34 | private final ConstPool constants; |
| 35 | private CodeAttribute attribute; | 35 | private final CodeAttribute attribute; |
| 36 | private CodeIterator iter; | 36 | private final CodeIterator iter; |
| 37 | private CheckCast next; | 37 | private CheckCast next; |
| 38 | 38 | ||
| 39 | public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { | 39 | public CheckCastIterator(CodeAttribute codeAttribute) throws BadBytecode { |
| @@ -110,8 +110,4 @@ public class CheckCastIterator implements Iterator<CheckCast> { | |||
| 110 | } | 110 | } |
| 111 | return null; | 111 | return null; |
| 112 | } | 112 | } |
| 113 | |||
| 114 | public Iterable<CheckCast> casts() { | ||
| 115 | return () -> CheckCastIterator.this; | ||
| 116 | } | ||
| 117 | } | 113 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java index d8e79711..944e486b 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java +++ b/src/main/java/cuchaz/enigma/bytecode/ClassRenamer.java | |||
| @@ -90,16 +90,6 @@ public class ClassRenamer { | |||
| 90 | }); | 90 | }); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | public static void moveAllClassesIntoDefaultPackage(CtClass c, final String oldPackageName) { | ||
| 94 | renameClasses(c, className -> { | ||
| 95 | ClassEntry entry = new ClassEntry(className); | ||
| 96 | if (entry.getPackageName().equals(oldPackageName)) { | ||
| 97 | return entry.getSimpleName(); | ||
| 98 | } | ||
| 99 | return null; | ||
| 100 | }); | ||
| 101 | } | ||
| 102 | |||
| 103 | @SuppressWarnings("unchecked") | 93 | @SuppressWarnings("unchecked") |
| 104 | public static void renameClasses(CtClass c, ClassNameReplacer replacer) { | 94 | public static void renameClasses(CtClass c, ClassNameReplacer replacer) { |
| 105 | 95 | ||
diff --git a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java index 256df61e..e49ffdbd 100644 --- a/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java +++ b/src/main/java/cuchaz/enigma/bytecode/ConstPoolEditor.java | |||
| @@ -78,22 +78,6 @@ public class ConstPoolEditor { | |||
| 78 | this.pool = pool; | 78 | this.pool = pool; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | public void writePool(DataOutputStream out) { | ||
| 82 | try { | ||
| 83 | methodWritePool.invoke(this.pool, out); | ||
| 84 | } catch (Exception ex) { | ||
| 85 | throw new Error(ex); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | public static ConstPool readPool(DataInputStream in) { | ||
| 90 | try { | ||
| 91 | return constructorPool.newInstance(in); | ||
| 92 | } catch (Exception ex) { | ||
| 93 | throw new Error(ex); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | public String getMemberrefClassname(int memberrefIndex) { | 81 | public String getMemberrefClassname(int memberrefIndex) { |
| 98 | return Descriptor.toJvmName(this.pool.getClassInfo(this.pool.getMemberClass(memberrefIndex))); | 82 | return Descriptor.toJvmName(this.pool.getClassInfo(this.pool.getMemberClass(memberrefIndex))); |
| 99 | } | 83 | } |
| @@ -117,23 +101,6 @@ public class ConstPoolEditor { | |||
| 117 | throw new Error(ex); | 101 | throw new Error(ex); |
| 118 | } | 102 | } |
| 119 | } | 103 | } |
| 120 | |||
| 121 | public int addItem(Object item) { | ||
| 122 | try { | ||
| 123 | return (Integer) addItem.invoke(this.pool, item); | ||
| 124 | } catch (Exception ex) { | ||
| 125 | throw new Error(ex); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | public int addItemForceNew(Object item) { | ||
| 130 | try { | ||
| 131 | return (Integer) addItem0.invoke(this.pool, item); | ||
| 132 | } catch (Exception ex) { | ||
| 133 | throw new Error(ex); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | @SuppressWarnings("rawtypes") | 104 | @SuppressWarnings("rawtypes") |
| 138 | public void removeLastItem() { | 105 | public void removeLastItem() { |
| 139 | try { | 106 | try { |
| @@ -197,67 +164,4 @@ public class ConstPoolEditor { | |||
| 197 | assert (newName.equals(getMemberrefName(memberrefIndex))); | 164 | assert (newName.equals(getMemberrefName(memberrefIndex))); |
| 198 | assert (newType.equals(getMemberrefType(memberrefIndex))); | 165 | assert (newType.equals(getMemberrefType(memberrefIndex))); |
| 199 | } | 166 | } |
| 200 | |||
| 201 | @SuppressWarnings({"rawtypes", "unchecked"}) | ||
| 202 | public void changeClassName(int classNameIndex, String newName) { | ||
| 203 | // NOTE: when changing values, we always need to copy-on-write | ||
| 204 | try { | ||
| 205 | // get the class item | ||
| 206 | Object item = getItem(classNameIndex).getItem(); | ||
| 207 | |||
| 208 | // update the cache | ||
| 209 | HashMap cache = getCache(); | ||
| 210 | if (cache != null) { | ||
| 211 | cache.remove(item); | ||
| 212 | } | ||
| 213 | |||
| 214 | // add the new name and repoint the name-and-type to it | ||
| 215 | new ClassInfoAccessor(item).setNameIndex(this.pool.addUtf8Info(newName)); | ||
| 216 | |||
| 217 | // update the cache | ||
| 218 | if (cache != null) { | ||
| 219 | cache.put(item, item); | ||
| 220 | } | ||
| 221 | } catch (Exception ex) { | ||
| 222 | throw new Error(ex); | ||
| 223 | } | ||
| 224 | } | ||
| 225 | |||
| 226 | public static ConstPool newConstPool() { | ||
| 227 | // const pool expects the name of a class to initialize itself | ||
| 228 | // but we want an empty pool | ||
| 229 | // so give it a bogus name, and then clear the entries afterwards | ||
| 230 | ConstPool pool = new ConstPool("a"); | ||
| 231 | |||
| 232 | ConstPoolEditor editor = new ConstPoolEditor(pool); | ||
| 233 | int size = pool.getSize(); | ||
| 234 | for (int i = 0; i < size - 1; i++) { | ||
| 235 | editor.removeLastItem(); | ||
| 236 | } | ||
| 237 | |||
| 238 | // make sure the pool is actually empty | ||
| 239 | // although, in this case "empty" means one thing in it | ||
| 240 | // the JVM spec says index 0 should be reserved | ||
| 241 | assert (pool.getSize() == 1); | ||
| 242 | assert (editor.getItem(0) == null); | ||
| 243 | assert (editor.getItem(1) == null); | ||
| 244 | assert (editor.getItem(2) == null); | ||
| 245 | assert (editor.getItem(3) == null); | ||
| 246 | |||
| 247 | // also, clear the cache | ||
| 248 | editor.getCache().clear(); | ||
| 249 | |||
| 250 | return pool; | ||
| 251 | } | ||
| 252 | |||
| 253 | public String dump() { | ||
| 254 | StringBuilder buf = new StringBuilder(); | ||
| 255 | for (int i = 1; i < this.pool.getSize(); i++) { | ||
| 256 | buf.append(String.format("%4d", i)); | ||
| 257 | buf.append(" "); | ||
| 258 | buf.append(getItem(i).toString()); | ||
| 259 | buf.append("\n"); | ||
| 260 | } | ||
| 261 | return buf.toString(); | ||
| 262 | } | ||
| 263 | } | 167 | } |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java index 66f22839..316bb5e4 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/ClassInfoAccessor.java | |||
| @@ -39,10 +39,6 @@ public class ClassInfoAccessor { | |||
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 43 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 44 | } | ||
| 45 | |||
| 46 | static { | 42 | static { |
| 47 | try { | 43 | try { |
| 48 | clazz = Class.forName("javassist.bytecode.ClassInfo"); | 44 | clazz = Class.forName("javassist.bytecode.ClassInfo"); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java index ea775e9c..2ecda1d9 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/ConstInfoAccessor.java | |||
| @@ -80,29 +80,6 @@ public class ConstInfoAccessor { | |||
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | public ConstInfoAccessor copy() { | ||
| 84 | return new ConstInfoAccessor(copyItem()); | ||
| 85 | } | ||
| 86 | |||
| 87 | public Object copyItem() { | ||
| 88 | // I don't know of a simpler way to copy one of these silly things... | ||
| 89 | try { | ||
| 90 | // serialize the item | ||
| 91 | ByteArrayOutputStream buf = new ByteArrayOutputStream(); | ||
| 92 | DataOutputStream out = new DataOutputStream(buf); | ||
| 93 | write(out); | ||
| 94 | |||
| 95 | // deserialize the item | ||
| 96 | DataInputStream in = new DataInputStream(new ByteArrayInputStream(buf.toByteArray())); | ||
| 97 | Object item = new ConstInfoAccessor(in).getItem(); | ||
| 98 | in.close(); | ||
| 99 | |||
| 100 | return item; | ||
| 101 | } catch (Exception ex) { | ||
| 102 | throw new Error(ex); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | public void write(DataOutputStream out) throws IOException { | 83 | public void write(DataOutputStream out) throws IOException { |
| 107 | try { | 84 | try { |
| 108 | out.writeUTF(this.item.getClass().getName()); | 85 | out.writeUTF(this.item.getClass().getName()); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java index 69aee160..a1583945 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/InvokeDynamicInfoAccessor.java | |||
| @@ -57,10 +57,6 @@ public class InvokeDynamicInfoAccessor { | |||
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 61 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 62 | } | ||
| 63 | |||
| 64 | static { | 60 | static { |
| 65 | try { | 61 | try { |
| 66 | clazz = Class.forName("javassist.bytecode.InvokeDynamicInfo"); | 62 | clazz = Class.forName("javassist.bytecode.InvokeDynamicInfo"); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java index 0e0297be..2835508a 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MemberRefInfoAccessor.java | |||
| @@ -56,10 +56,6 @@ public class MemberRefInfoAccessor { | |||
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 60 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 61 | } | ||
| 62 | |||
| 63 | static { | 59 | static { |
| 64 | try { | 60 | try { |
| 65 | clazz = Class.forName("javassist.bytecode.MemberrefInfo"); | 61 | clazz = Class.forName("javassist.bytecode.MemberrefInfo"); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java index 9a7dd698..a203b43a 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodHandleInfoAccessor.java | |||
| @@ -56,10 +56,6 @@ public class MethodHandleInfoAccessor { | |||
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 60 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 61 | } | ||
| 62 | |||
| 63 | static { | 59 | static { |
| 64 | try { | 60 | try { |
| 65 | clazz = Class.forName("javassist.bytecode.MethodHandleInfo"); | 61 | clazz = Class.forName("javassist.bytecode.MethodHandleInfo"); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java index 5ec9c3b4..993c79bb 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/MethodTypeInfoAccessor.java | |||
| @@ -39,10 +39,6 @@ public class MethodTypeInfoAccessor { | |||
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 43 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 44 | } | ||
| 45 | |||
| 46 | static { | 42 | static { |
| 47 | try { | 43 | try { |
| 48 | clazz = Class.forName("javassist.bytecode.MethodTypeInfo"); | 44 | clazz = Class.forName("javassist.bytecode.MethodTypeInfo"); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java index 95df37c1..d6c2531f 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/NameAndTypeInfoAccessor.java | |||
| @@ -56,10 +56,6 @@ public class NameAndTypeInfoAccessor { | |||
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 60 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 61 | } | ||
| 62 | |||
| 63 | static { | 59 | static { |
| 64 | try { | 60 | try { |
| 65 | clazz = Class.forName("javassist.bytecode.NameAndTypeInfo"); | 61 | clazz = Class.forName("javassist.bytecode.NameAndTypeInfo"); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java index 1c55a443..e211381b 100644 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java +++ b/src/main/java/cuchaz/enigma/bytecode/accessors/StringInfoAccessor.java | |||
| @@ -39,10 +39,6 @@ public class StringInfoAccessor { | |||
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 43 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 44 | } | ||
| 45 | |||
| 46 | static { | 42 | static { |
| 47 | try { | 43 | try { |
| 48 | clazz = Class.forName("javassist.bytecode.StringInfo"); | 44 | clazz = Class.forName("javassist.bytecode.StringInfo"); |
diff --git a/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java b/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java deleted file mode 100644 index 7a2cb667..00000000 --- a/src/main/java/cuchaz/enigma/bytecode/accessors/Utf8InfoAccessor.java +++ /dev/null | |||
| @@ -1,28 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode.accessors; | ||
| 12 | |||
| 13 | public class Utf8InfoAccessor { | ||
| 14 | |||
| 15 | private static Class<?> clazz; | ||
| 16 | |||
| 17 | static { | ||
| 18 | try { | ||
| 19 | clazz = Class.forName("javassist.bytecode.Utf8Info"); | ||
| 20 | } catch (Exception ex) { | ||
| 21 | throw new Error(ex); | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | public static boolean isType(ConstInfoAccessor accessor) { | ||
| 26 | return clazz.isAssignableFrom(accessor.getItem().getClass()); | ||
| 27 | } | ||
| 28 | } | ||
diff --git a/src/main/java/cuchaz/enigma/convert/ClassForest.java b/src/main/java/cuchaz/enigma/convert/ClassForest.java index b08d48fb..c9b44b33 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassForest.java +++ b/src/main/java/cuchaz/enigma/convert/ClassForest.java | |||
| @@ -28,12 +28,6 @@ public class ClassForest { | |||
| 28 | this.forest = HashMultimap.create(); | 28 | this.forest = HashMultimap.create(); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | public void addAll(Iterable<ClassEntry> entries) { | ||
| 32 | for (ClassEntry entry : entries) { | ||
| 33 | add(entry); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | public void add(ClassEntry entry) { | 31 | public void add(ClassEntry entry) { |
| 38 | try { | 32 | try { |
| 39 | this.forest.put(this.identifier.identify(entry), entry); | 33 | this.forest.put(this.identifier.identify(entry), entry); |
diff --git a/src/main/java/cuchaz/enigma/convert/ClassMatches.java b/src/main/java/cuchaz/enigma/convert/ClassMatches.java index 0b7e8034..851c0829 100644 --- a/src/main/java/cuchaz/enigma/convert/ClassMatches.java +++ b/src/main/java/cuchaz/enigma/convert/ClassMatches.java | |||
| @@ -121,18 +121,10 @@ public class ClassMatches implements Iterable<ClassMatch> { | |||
| 121 | return m_ambiguousMatchesBySource.keySet(); | 121 | return m_ambiguousMatchesBySource.keySet(); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | public ClassMatch getAmbiguousMatchBySource(ClassEntry sourceClass) { | ||
| 125 | return m_ambiguousMatchesBySource.get(sourceClass); | ||
| 126 | } | ||
| 127 | |||
| 128 | public ClassMatch getMatchBySource(ClassEntry sourceClass) { | 124 | public ClassMatch getMatchBySource(ClassEntry sourceClass) { |
| 129 | return m_matchesBySource.get(sourceClass); | 125 | return m_matchesBySource.get(sourceClass); |
| 130 | } | 126 | } |
| 131 | 127 | ||
| 132 | public ClassMatch getMatchByDest(ClassEntry destClass) { | ||
| 133 | return m_matchesByDest.get(destClass); | ||
| 134 | } | ||
| 135 | |||
| 136 | public void removeSource(ClassEntry sourceClass) { | 128 | public void removeSource(ClassEntry sourceClass) { |
| 137 | ClassMatch match = m_matchesBySource.get(sourceClass); | 129 | ClassMatch match = m_matchesBySource.get(sourceClass); |
| 138 | if (match != null) { | 130 | if (match != null) { |
diff --git a/src/main/java/cuchaz/enigma/convert/MappingsConverter.java b/src/main/java/cuchaz/enigma/convert/MappingsConverter.java index d1daadb0..7739adf2 100644 --- a/src/main/java/cuchaz/enigma/convert/MappingsConverter.java +++ b/src/main/java/cuchaz/enigma/convert/MappingsConverter.java | |||
| @@ -236,41 +236,6 @@ public class MappingsConverter { | |||
| 236 | return classMatches.getUniqueMatches().containsKey(classEntry); | 236 | return classMatches.getUniqueMatches().containsKey(classEntry); |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | public static void convertMappings(Mappings mappings, BiMap<ClassEntry, ClassEntry> changes) { | ||
| 240 | |||
| 241 | // sort the changes so classes are renamed in the correct order | ||
| 242 | // ie. if we have the mappings a->b, b->c, we have to apply b->c before a->b | ||
| 243 | LinkedHashMap<ClassEntry, ClassEntry> sortedChanges = Maps.newLinkedHashMap(); | ||
| 244 | int numChangesLeft = changes.size(); | ||
| 245 | while (!changes.isEmpty()) { | ||
| 246 | Iterator<Map.Entry<ClassEntry, ClassEntry>> iter = changes.entrySet().iterator(); | ||
| 247 | while (iter.hasNext()) { | ||
| 248 | Map.Entry<ClassEntry, ClassEntry> change = iter.next(); | ||
| 249 | if (changes.containsKey(change.getValue())) { | ||
| 250 | sortedChanges.put(change.getKey(), change.getValue()); | ||
| 251 | iter.remove(); | ||
| 252 | } | ||
| 253 | } | ||
| 254 | |||
| 255 | // did we remove any changes? | ||
| 256 | if (numChangesLeft - changes.size() > 0) { | ||
| 257 | // keep going | ||
| 258 | numChangesLeft = changes.size(); | ||
| 259 | } else { | ||
| 260 | // can't sort anymore. There must be a loop | ||
| 261 | break; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | if (!changes.isEmpty()) { | ||
| 265 | throw new Error("Unable to sort class changes! There must be a cycle."); | ||
| 266 | } | ||
| 267 | |||
| 268 | // convert the mappings in the correct class order | ||
| 269 | for (Map.Entry<ClassEntry, ClassEntry> entry : sortedChanges.entrySet()) { | ||
| 270 | mappings.renameObfClass(entry.getKey().getName(), entry.getValue().getName()); | ||
| 271 | } | ||
| 272 | } | ||
| 273 | |||
| 274 | public interface Doer<T extends Entry> { | 239 | public interface Doer<T extends Entry> { |
| 275 | Collection<T> getDroppedEntries(MappingsChecker checker); | 240 | Collection<T> getDroppedEntries(MappingsChecker checker); |
| 276 | 241 | ||
diff --git a/src/main/java/cuchaz/enigma/convert/MemberMatches.java b/src/main/java/cuchaz/enigma/convert/MemberMatches.java index 32850cca..662c1db9 100644 --- a/src/main/java/cuchaz/enigma/convert/MemberMatches.java +++ b/src/main/java/cuchaz/enigma/convert/MemberMatches.java | |||
| @@ -47,23 +47,11 @@ public class MemberMatches<T extends Entry> { | |||
| 47 | assert (wasAdded); | 47 | assert (wasAdded); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | public void addUnmatchedSourceEntries(Iterable<T> sourceEntries) { | ||
| 51 | for (T sourceEntry : sourceEntries) { | ||
| 52 | addUnmatchedSourceEntry(sourceEntry); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | public void addUnmatchedDestEntry(T destEntry) { | 50 | public void addUnmatchedDestEntry(T destEntry) { |
| 57 | boolean wasAdded = m_unmatchedDestEntries.put(destEntry.getClassEntry(), destEntry); | 51 | boolean wasAdded = m_unmatchedDestEntries.put(destEntry.getClassEntry(), destEntry); |
| 58 | assert (wasAdded); | 52 | assert (wasAdded); |
| 59 | } | 53 | } |
| 60 | 54 | ||
| 61 | public void addUnmatchedDestEntries(Iterable<T> destEntriesntries) { | ||
| 62 | for (T entry : destEntriesntries) { | ||
| 63 | addUnmatchedDestEntry(entry); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | public void addUnmatchableSourceEntry(T sourceEntry) { | 55 | public void addUnmatchableSourceEntry(T sourceEntry) { |
| 68 | boolean wasAdded = m_unmatchableSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); | 56 | boolean wasAdded = m_unmatchableSourceEntries.put(sourceEntry.getClassEntry(), sourceEntry); |
| 69 | assert (wasAdded); | 57 | assert (wasAdded); |
diff --git a/src/main/java/cuchaz/enigma/gui/BrowserCaret.java b/src/main/java/cuchaz/enigma/gui/BrowserCaret.java index 094b69b2..a75db366 100644 --- a/src/main/java/cuchaz/enigma/gui/BrowserCaret.java +++ b/src/main/java/cuchaz/enigma/gui/BrowserCaret.java | |||
| @@ -32,6 +32,6 @@ public class BrowserCaret extends DefaultCaret { | |||
| 32 | 32 | ||
| 33 | @Override | 33 | @Override |
| 34 | public Highlighter.HighlightPainter getSelectionPainter() { | 34 | public Highlighter.HighlightPainter getSelectionPainter() { |
| 35 | return this.selectionPainter; | 35 | return selectionPainter; |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java b/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java index c89f7e33..83033bc5 100644 --- a/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/ArgumentEntry.java | |||
| @@ -33,7 +33,7 @@ public class ArgumentEntry implements Entry, Serializable { | |||
| 33 | throw new IllegalArgumentException("Argument name cannot be null!"); | 33 | throw new IllegalArgumentException("Argument name cannot be null!"); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | m_behaviorEntry = behaviorEntry; | 36 | m_behaviorEntry = behaviorEntry; |
| 37 | m_index = index; | 37 | m_index = index; |
| 38 | m_name = name; | 38 | m_name = name; |
| 39 | } | 39 | } |
| @@ -101,9 +101,7 @@ public class ArgumentEntry implements Entry, Serializable { | |||
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | public boolean equals(ArgumentEntry other) { | 103 | public boolean equals(ArgumentEntry other) { |
| 104 | return m_behaviorEntry.equals(other.m_behaviorEntry) | 104 | return m_behaviorEntry.equals(other.m_behaviorEntry) && m_index == other.m_index && m_name.equals(other.m_name); |
| 105 | && m_index == other.m_index | ||
| 106 | && m_name.equals(other.m_name); | ||
| 107 | } | 105 | } |
| 108 | 106 | ||
| 109 | @Override | 107 | @Override |
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index 99e463de..f831a3b8 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -117,15 +117,6 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 117 | return classMapping; | 117 | return classMapping; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | public String getDeobfInnerClassName(String obfSimpleName) { | ||
| 121 | assert (isSimpleClassName(obfSimpleName)); | ||
| 122 | ClassMapping classMapping = m_innerClassesByObfSimple.get(obfSimpleName); | ||
| 123 | if (classMapping != null) { | ||
| 124 | return classMapping.getDeobfName(); | ||
| 125 | } | ||
| 126 | return null; | ||
| 127 | } | ||
| 128 | |||
| 129 | public void setInnerClassName(ClassEntry obfInnerClass, String deobfName) { | 120 | public void setInnerClassName(ClassEntry obfInnerClass, String deobfName) { |
| 130 | ClassMapping classMapping = getOrCreateInnerClass(obfInnerClass); | 121 | ClassMapping classMapping = getOrCreateInnerClass(obfInnerClass); |
| 131 | if (classMapping.getDeobfName() != null) { | 122 | if (classMapping.getDeobfName() != null) { |
| @@ -156,10 +147,6 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 156 | return m_fieldsByObf.values(); | 147 | return m_fieldsByObf.values(); |
| 157 | } | 148 | } |
| 158 | 149 | ||
| 159 | public boolean containsObfField(String obfName, Type obfType) { | ||
| 160 | return m_fieldsByObf.containsKey(getFieldKey(obfName, obfType)); | ||
| 161 | } | ||
| 162 | |||
| 163 | public boolean containsDeobfField(String deobfName, Type deobfType) { | 150 | public boolean containsDeobfField(String deobfName, Type deobfType) { |
| 164 | return m_fieldsByDeobf.containsKey(getFieldKey(deobfName, deobfType)); | 151 | return m_fieldsByDeobf.containsKey(getFieldKey(deobfName, deobfType)); |
| 165 | } | 152 | } |
| @@ -193,10 +180,6 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 193 | return m_fieldsByObf.get(getFieldKey(obfName, obfType)); | 180 | return m_fieldsByObf.get(getFieldKey(obfName, obfType)); |
| 194 | } | 181 | } |
| 195 | 182 | ||
| 196 | public FieldMapping getFieldByDeobf(String deobfName, Type obfType) { | ||
| 197 | return m_fieldsByDeobf.get(getFieldKey(deobfName, obfType)); | ||
| 198 | } | ||
| 199 | |||
| 200 | public String getObfFieldName(String deobfName, Type obfType) { | 183 | public String getObfFieldName(String deobfName, Type obfType) { |
| 201 | FieldMapping fieldMapping = m_fieldsByDeobf.get(getFieldKey(deobfName, obfType)); | 184 | FieldMapping fieldMapping = m_fieldsByDeobf.get(getFieldKey(deobfName, obfType)); |
| 202 | if (fieldMapping != null) { | 185 | if (fieldMapping != null) { |
| @@ -260,10 +243,6 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 260 | return m_methodsByObf.values(); | 243 | return m_methodsByObf.values(); |
| 261 | } | 244 | } |
| 262 | 245 | ||
| 263 | public boolean containsObfMethod(String obfName, Signature obfSignature) { | ||
| 264 | return m_methodsByObf.containsKey(getMethodKey(obfName, obfSignature)); | ||
| 265 | } | ||
| 266 | |||
| 267 | public boolean containsDeobfMethod(String deobfName, Signature obfSignature) { | 246 | public boolean containsDeobfMethod(String deobfName, Signature obfSignature) { |
| 268 | return m_methodsByDeobf.containsKey(getMethodKey(deobfName, obfSignature)); | 247 | return m_methodsByDeobf.containsKey(getMethodKey(deobfName, obfSignature)); |
| 269 | } | 248 | } |
| @@ -400,48 +379,6 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> { | |||
| 400 | return m_obfFullName.compareTo(other.m_obfFullName); | 379 | return m_obfFullName.compareTo(other.m_obfFullName); |
| 401 | } | 380 | } |
| 402 | 381 | ||
| 403 | public boolean renameObfClass(String oldObfClassName, String newObfClassName) { | ||
| 404 | |||
| 405 | // rename inner classes | ||
| 406 | for (ClassMapping innerClassMapping : new ArrayList<>(m_innerClassesByObfSimple.values())) { | ||
| 407 | if (innerClassMapping.renameObfClass(oldObfClassName, newObfClassName)) { | ||
| 408 | boolean wasRemoved = m_innerClassesByObfSimple.remove(oldObfClassName) != null; | ||
| 409 | assert (wasRemoved); | ||
| 410 | boolean wasAdded = m_innerClassesByObfSimple.put(newObfClassName, innerClassMapping) == null; | ||
| 411 | assert (wasAdded); | ||
| 412 | } | ||
| 413 | } | ||
| 414 | |||
| 415 | // rename field types | ||
| 416 | for (FieldMapping fieldMapping : new ArrayList<>(m_fieldsByObf.values())) { | ||
| 417 | String oldFieldKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); | ||
| 418 | if (fieldMapping.renameObfClass(oldObfClassName, newObfClassName)) { | ||
| 419 | boolean wasRemoved = m_fieldsByObf.remove(oldFieldKey) != null; | ||
| 420 | assert (wasRemoved); | ||
| 421 | boolean wasAdded = m_fieldsByObf.put(getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()), fieldMapping) == null; | ||
| 422 | assert (wasAdded); | ||
| 423 | } | ||
| 424 | } | ||
| 425 | |||
| 426 | // rename method signatures | ||
| 427 | for (MethodMapping methodMapping : new ArrayList<>(m_methodsByObf.values())) { | ||
| 428 | String oldMethodKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); | ||
| 429 | if (methodMapping.renameObfClass(oldObfClassName, newObfClassName)) { | ||
| 430 | boolean wasRemoved = m_methodsByObf.remove(oldMethodKey) != null; | ||
| 431 | assert (wasRemoved); | ||
| 432 | boolean wasAdded = m_methodsByObf.put(getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()), methodMapping) == null; | ||
| 433 | assert (wasAdded); | ||
| 434 | } | ||
| 435 | } | ||
| 436 | |||
| 437 | if (m_obfFullName.equals(oldObfClassName)) { | ||
| 438 | // rename this class | ||
| 439 | m_obfFullName = newObfClassName; | ||
| 440 | return true; | ||
| 441 | } | ||
| 442 | return false; | ||
| 443 | } | ||
| 444 | |||
| 445 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { | 382 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { |
| 446 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfBehaviorEntry.getName(), obfBehaviorEntry.getSignature())); | 383 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfBehaviorEntry.getName(), obfBehaviorEntry.getSignature())); |
| 447 | return methodMapping != null && methodMapping.containsArgument(name); | 384 | return methodMapping != null && methodMapping.containsArgument(name); |
diff --git a/src/main/java/cuchaz/enigma/mapping/EntryFactory.java b/src/main/java/cuchaz/enigma/mapping/EntryFactory.java index bd6ce4ec..0ac739c1 100644 --- a/src/main/java/cuchaz/enigma/mapping/EntryFactory.java +++ b/src/main/java/cuchaz/enigma/mapping/EntryFactory.java | |||
| @@ -33,10 +33,6 @@ public class EntryFactory { | |||
| 33 | return new ClassEntry(classMapping.getObfFullName()); | 33 | return new ClassEntry(classMapping.getObfFullName()); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | public static ClassEntry getDeobfClassEntry(ClassMapping classMapping) { | ||
| 37 | return new ClassEntry(classMapping.getDeobfName()); | ||
| 38 | } | ||
| 39 | |||
| 40 | public static ClassEntry getSuperclassEntry(CtClass c) { | 36 | public static ClassEntry getSuperclassEntry(CtClass c) { |
| 41 | return new ClassEntry(Descriptor.toJvmName(c.getClassFile().getSuperclass())); | 37 | return new ClassEntry(Descriptor.toJvmName(c.getClassFile().getSuperclass())); |
| 42 | } | 38 | } |
| @@ -155,8 +151,4 @@ public class EntryFactory { | |||
| 155 | public static BehaviorEntry getObfBehaviorEntry(ClassEntry classEntry, MethodMapping methodMapping) { | 151 | public static BehaviorEntry getObfBehaviorEntry(ClassEntry classEntry, MethodMapping methodMapping) { |
| 156 | return getBehaviorEntry(classEntry, methodMapping.getObfName(), methodMapping.getObfSignature()); | 152 | return getBehaviorEntry(classEntry, methodMapping.getObfName(), methodMapping.getObfSignature()); |
| 157 | } | 153 | } |
| 158 | |||
| 159 | public static BehaviorEntry getObfBehaviorEntry(ClassMapping classMapping, MethodMapping methodMapping) { | ||
| 160 | return getObfBehaviorEntry(getObfClassEntry(classMapping), methodMapping); | ||
| 161 | } | ||
| 162 | } | 154 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/EntryPair.java b/src/main/java/cuchaz/enigma/mapping/EntryPair.java deleted file mode 100644 index 1c93d532..00000000 --- a/src/main/java/cuchaz/enigma/mapping/EntryPair.java +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | public class EntryPair<T extends Entry> { | ||
| 14 | |||
| 15 | public T obf; | ||
| 16 | public T deobf; | ||
| 17 | |||
| 18 | public EntryPair(T obf, T deobf) { | ||
| 19 | this.obf = obf; | ||
| 20 | this.deobf = deobf; | ||
| 21 | } | ||
| 22 | } | ||
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java index a48ec3ff..ee4c3023 100644 --- a/src/main/java/cuchaz/enigma/mapping/Mappings.java +++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -79,10 +79,6 @@ public class Mappings implements Serializable { | |||
| 79 | return m_classesByObf.get(obfName); | 79 | return m_classesByObf.get(obfName); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | public ClassMapping getClassByDeobf(ClassEntry entry) { | ||
| 83 | return getClassByDeobf(entry.getName()); | ||
| 84 | } | ||
| 85 | |||
| 86 | public ClassMapping getClassByDeobf(String deobfName) { | 82 | public ClassMapping getClassByDeobf(String deobfName) { |
| 87 | return m_classesByDeobf.get(deobfName); | 83 | return m_classesByDeobf.get(deobfName); |
| 88 | } | 84 | } |
| @@ -138,34 +134,6 @@ public class Mappings implements Serializable { | |||
| 138 | return buf.toString(); | 134 | return buf.toString(); |
| 139 | } | 135 | } |
| 140 | 136 | ||
| 141 | public void renameObfClass(String oldObfName, String newObfName) { | ||
| 142 | new ArrayList<>(classes()).stream().filter(classMapping -> classMapping.renameObfClass(oldObfName, newObfName)).forEach(classMapping -> { | ||
| 143 | boolean wasRemoved = m_classesByObf.remove(oldObfName) != null; | ||
| 144 | assert (wasRemoved); | ||
| 145 | boolean wasAdded = m_classesByObf.put(newObfName, classMapping) == null; | ||
| 146 | assert (wasAdded); | ||
| 147 | }); | ||
| 148 | } | ||
| 149 | |||
| 150 | public Set<String> getAllObfClassNames() { | ||
| 151 | final Set<String> classNames = Sets.newHashSet(); | ||
| 152 | for (ClassMapping classMapping : classes()) { | ||
| 153 | |||
| 154 | // add the class name | ||
| 155 | classNames.add(classMapping.getObfFullName()); | ||
| 156 | |||
| 157 | // add classes from method signatures | ||
| 158 | for (MethodMapping methodMapping : classMapping.methods()) { | ||
| 159 | for (Type type : methodMapping.getObfSignature().types()) { | ||
| 160 | if (type.hasClass()) { | ||
| 161 | classNames.add(type.getClassEntry().getClassName()); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | } | ||
| 165 | } | ||
| 166 | return classNames; | ||
| 167 | } | ||
| 168 | |||
| 169 | public boolean containsDeobfClass(String deobfName) { | 137 | public boolean containsDeobfClass(String deobfName) { |
| 170 | return m_classesByDeobf.containsKey(deobfName); | 138 | return m_classesByDeobf.containsKey(deobfName); |
| 171 | } | 139 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java b/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java index a23a33fa..ed36d423 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java | |||
| @@ -56,7 +56,7 @@ public class MappingsReaderOld { | |||
| 56 | ClassMapping classMapping; | 56 | ClassMapping classMapping; |
| 57 | if (indent <= 0) { | 57 | if (indent <= 0) { |
| 58 | // outer class | 58 | // outer class |
| 59 | classMapping = readClass(parts, false); | 59 | classMapping = readClass(parts); |
| 60 | mappings.addClassMapping(classMapping); | 60 | mappings.addClassMapping(classMapping); |
| 61 | } else { | 61 | } else { |
| 62 | 62 | ||
| @@ -65,7 +65,7 @@ public class MappingsReaderOld { | |||
| 65 | throw new MappingParseException(lineNumber, "Unexpected CLASS entry here!"); | 65 | throw new MappingParseException(lineNumber, "Unexpected CLASS entry here!"); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | classMapping = readClass(parts, true); | 68 | classMapping = readClass(parts); |
| 69 | ((ClassMapping) mappingStack.peek()).addInnerClassMapping(classMapping); | 69 | ((ClassMapping) mappingStack.peek()).addInnerClassMapping(classMapping); |
| 70 | } | 70 | } |
| 71 | mappingStack.push(classMapping); | 71 | mappingStack.push(classMapping); |
| @@ -99,7 +99,7 @@ public class MappingsReaderOld { | |||
| 99 | return new ArgumentMapping(Integer.parseInt(parts[1]), parts[2]); | 99 | return new ArgumentMapping(Integer.parseInt(parts[1]), parts[2]); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | private ClassMapping readClass(String[] parts, boolean makeSimple) { | 102 | private ClassMapping readClass(String[] parts) { |
| 103 | if (parts.length == 2) { | 103 | if (parts.length == 2) { |
| 104 | return new ClassMapping(parts[1]); | 104 | return new ClassMapping(parts[1]); |
| 105 | } else { | 105 | } else { |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java index 2b112a24..3050da6b 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java | |||
| @@ -167,34 +167,6 @@ public class MappingsRenamer { | |||
| 167 | classMapping.setArgumentName(obf.getMethodName(), obf.getMethodSignature(), obf.getIndex(), obf.getName()); | 167 | classMapping.setArgumentName(obf.getMethodName(), obf.getMethodSignature(), obf.getIndex(), obf.getName()); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | public boolean moveFieldToObfClass(ClassMapping classMapping, FieldMapping fieldMapping, ClassEntry obfClass) { | ||
| 171 | classMapping.removeFieldMapping(fieldMapping); | ||
| 172 | ClassMapping targetClassMapping = getOrCreateClassMapping(obfClass); | ||
| 173 | if (!targetClassMapping.containsObfField(fieldMapping.getObfName(), fieldMapping.getObfType())) { | ||
| 174 | if (!targetClassMapping.containsDeobfField(fieldMapping.getDeobfName(), fieldMapping.getObfType())) { | ||
| 175 | targetClassMapping.addFieldMapping(fieldMapping); | ||
| 176 | return true; | ||
| 177 | } else { | ||
| 178 | System.err.println("WARNING: deobf field was already there: " + obfClass + "." + fieldMapping.getDeobfName()); | ||
| 179 | } | ||
| 180 | } | ||
| 181 | return false; | ||
| 182 | } | ||
| 183 | |||
| 184 | public boolean moveMethodToObfClass(ClassMapping classMapping, MethodMapping methodMapping, ClassEntry obfClass) { | ||
| 185 | classMapping.removeMethodMapping(methodMapping); | ||
| 186 | ClassMapping targetClassMapping = getOrCreateClassMapping(obfClass); | ||
| 187 | if (!targetClassMapping.containsObfMethod(methodMapping.getObfName(), methodMapping.getObfSignature())) { | ||
| 188 | if (!targetClassMapping.containsDeobfMethod(methodMapping.getDeobfName(), methodMapping.getObfSignature())) { | ||
| 189 | targetClassMapping.addMethodMapping(methodMapping); | ||
| 190 | return true; | ||
| 191 | } else { | ||
| 192 | System.err.println("WARNING: deobf method was already there: " + obfClass + "." + methodMapping.getDeobfName() + methodMapping.getObfSignature()); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | return false; | ||
| 196 | } | ||
| 197 | |||
| 198 | public void write(OutputStream out) throws IOException { | 170 | public void write(OutputStream out) throws IOException { |
| 199 | // TEMP: just use the object output for now. We can find a more efficient storage format later | 171 | // TEMP: just use the object output for now. We can find a more efficient storage format later |
| 200 | GZIPOutputStream gzipout = new GZIPOutputStream(out); | 172 | GZIPOutputStream gzipout = new GZIPOutputStream(out); |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodEntry.java b/src/main/java/cuchaz/enigma/mapping/MethodEntry.java index 01a5c43d..7df4dd86 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodEntry.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodEntry.java | |||
| @@ -89,9 +89,7 @@ public class MethodEntry implements BehaviorEntry, Serializable { | |||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | public boolean equals(MethodEntry other) { | 91 | public boolean equals(MethodEntry other) { |
| 92 | return m_classEntry.equals(other.m_classEntry) | 92 | return m_classEntry.equals(other.m_classEntry) && m_name.equals(other.m_name) && m_signature.equals(other.m_signature); |
| 93 | && m_name.equals(other.m_name) | ||
| 94 | && m_signature.equals(other.m_signature); | ||
| 95 | } | 93 | } |
| 96 | 94 | ||
| 97 | @Override | 95 | @Override |
diff --git a/src/main/java/cuchaz/enigma/mapping/NameValidator.java b/src/main/java/cuchaz/enigma/mapping/NameValidator.java index a3b9a78a..f416322b 100644 --- a/src/main/java/cuchaz/enigma/mapping/NameValidator.java +++ b/src/main/java/cuchaz/enigma/mapping/NameValidator.java | |||
| @@ -31,17 +31,6 @@ public class NameValidator { | |||
| 31 | static { | 31 | static { |
| 32 | 32 | ||
| 33 | // java allows all kinds of weird characters... | 33 | // java allows all kinds of weird characters... |
| 34 | StringBuilder startChars = new StringBuilder(); | ||
| 35 | StringBuilder partChars = new StringBuilder(); | ||
| 36 | for (int i = Character.MIN_CODE_POINT; i <= Character.MAX_CODE_POINT; i++) { | ||
| 37 | if (Character.isJavaIdentifierStart(i)) { | ||
| 38 | startChars.appendCodePoint(i); | ||
| 39 | } | ||
| 40 | if (Character.isJavaIdentifierPart(i)) { | ||
| 41 | partChars.appendCodePoint(i); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | String identifierRegex = "[A-Za-z_<][A-Za-z0-9_>]*"; | 34 | String identifierRegex = "[A-Za-z_<][A-Za-z0-9_>]*"; |
| 46 | IdentifierPattern = Pattern.compile(identifierRegex); | 35 | IdentifierPattern = Pattern.compile(identifierRegex); |
| 47 | ClassPattern = Pattern.compile(String.format("^(%s(\\.|/))*(%s)$", identifierRegex, identifierRegex)); | 36 | ClassPattern = Pattern.compile(String.format("^(%s(\\.|/))*(%s)$", identifierRegex, identifierRegex)); |
diff --git a/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java b/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java index 98643330..ec300fed 100644 --- a/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java +++ b/src/main/java/cuchaz/enigma/mapping/SignatureUpdater.java | |||
| @@ -79,13 +79,4 @@ public class SignatureUpdater { | |||
| 79 | 79 | ||
| 80 | return null; | 80 | return null; |
| 81 | } | 81 | } |
| 82 | |||
| 83 | public static List<String> getClasses(String signature) { | ||
| 84 | final List<String> classNames = Lists.newArrayList(); | ||
| 85 | update(signature, className -> { | ||
| 86 | classNames.add(className); | ||
| 87 | return className; | ||
| 88 | }); | ||
| 89 | return classNames; | ||
| 90 | } | ||
| 91 | } | 82 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/Translator.java b/src/main/java/cuchaz/enigma/mapping/Translator.java index 1947d1c4..b0107ce8 100644 --- a/src/main/java/cuchaz/enigma/mapping/Translator.java +++ b/src/main/java/cuchaz/enigma/mapping/Translator.java | |||
| @@ -38,14 +38,6 @@ public class Translator { | |||
| 38 | m_index = index; | 38 | m_index = index; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | public TranslationDirection getDirection() { | ||
| 42 | return m_direction; | ||
| 43 | } | ||
| 44 | |||
| 45 | public TranslationIndex getTranslationIndex() { | ||
| 46 | return m_index; | ||
| 47 | } | ||
| 48 | |||
| 49 | @SuppressWarnings("unchecked") | 41 | @SuppressWarnings("unchecked") |
| 50 | public <T extends Entry> T translateEntry(T entry) { | 42 | public <T extends Entry> T translateEntry(T entry) { |
| 51 | if (entry instanceof ClassEntry) { | 43 | if (entry instanceof ClassEntry) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/Type.java b/src/main/java/cuchaz/enigma/mapping/Type.java index f2fd34d9..ec159415 100644 --- a/src/main/java/cuchaz/enigma/mapping/Type.java +++ b/src/main/java/cuchaz/enigma/mapping/Type.java | |||
| @@ -218,8 +218,7 @@ public class Type implements Serializable { | |||
| 218 | 218 | ||
| 219 | private static int countArrayDimension(String in) { | 219 | private static int countArrayDimension(String in) { |
| 220 | int i = 0; | 220 | int i = 0; |
| 221 | for (; i < in.length() && in.charAt(i) == '['; i++) { | 221 | for (; i < in.length() && in.charAt(i) == '['; i++) {} |
| 222 | } | ||
| 223 | return i; | 222 | return i; |
| 224 | } | 223 | } |
| 225 | 224 | ||