summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/translation/representation
diff options
context:
space:
mode:
authorGravatar Gegy2019-01-30 21:05:32 +0200
committerGravatar GitHub2019-01-30 21:05:32 +0200
commitba7a354efae7d49833c887cf147ac940c975a1fa (patch)
tree02e14fda81dd5984e24f2df392c57c6e829fc875 /src/main/java/cuchaz/enigma/translation/representation
parentRewrite the Jenkinsfile to use the new declarative pipeline syntax, lets hope... (diff)
downloadenigma-fork-ba7a354efae7d49833c887cf147ac940c975a1fa.tar.gz
enigma-fork-ba7a354efae7d49833c887cf147ac940c975a1fa.tar.xz
enigma-fork-ba7a354efae7d49833c887cf147ac940c975a1fa.zip
Remap sources (#106)
* Source remapping beginnings * Fix navigation to remapped classes * Translate identifier info reference * Remap local variables with default names in source * Caching translator * Fix lack of highlighting for first opened class * Fix unicode variable names * Unicode checker shouldn't be checking just alphanumeric * Fix package tree being built from obf names * Don't index `this` as method call for method::reference * Apply proposed names * Fix source export issues * Replace unicode var names at bytecode level uniquely * Drop imports from editor source * Class selector fixes * Delta keep track of base mappings to enable lookup of old names * Optimize source remapping by remapping source with a StringBuffer instead of copying * Bump version
Diffstat (limited to 'src/main/java/cuchaz/enigma/translation/representation')
-rw-r--r--src/main/java/cuchaz/enigma/translation/representation/ProcyonEntryFactory.java18
-rw-r--r--src/main/java/cuchaz/enigma/translation/representation/ReferencedEntryPool.java60
-rw-r--r--src/main/java/cuchaz/enigma/translation/representation/Signature.java9
-rw-r--r--src/main/java/cuchaz/enigma/translation/representation/TypeDescriptor.java5
-rw-r--r--src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java11
-rw-r--r--src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java4
-rw-r--r--src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java7
7 files changed, 34 insertions, 80 deletions
diff --git a/src/main/java/cuchaz/enigma/translation/representation/ProcyonEntryFactory.java b/src/main/java/cuchaz/enigma/translation/representation/ProcyonEntryFactory.java
index 9c9fa3d..a9ec5fa 100644
--- a/src/main/java/cuchaz/enigma/translation/representation/ProcyonEntryFactory.java
+++ b/src/main/java/cuchaz/enigma/translation/representation/ProcyonEntryFactory.java
@@ -17,29 +17,23 @@ import com.strobel.assembler.metadata.MethodDefinition;
17import cuchaz.enigma.translation.representation.entry.*; 17import cuchaz.enigma.translation.representation.entry.*;
18 18
19public class ProcyonEntryFactory { 19public class ProcyonEntryFactory {
20 private final ReferencedEntryPool entryPool;
21
22 public ProcyonEntryFactory(ReferencedEntryPool entryPool) {
23 this.entryPool = entryPool;
24 }
25
26 public FieldEntry getFieldEntry(MemberReference def) { 20 public FieldEntry getFieldEntry(MemberReference def) {
27 ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); 21 ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName());
28 return entryPool.getField(classEntry, def.getName(), def.getErasedSignature()); 22 return new FieldEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature()));
29 } 23 }
30 24
31 public FieldDefEntry getFieldDefEntry(FieldDefinition def) { 25 public FieldDefEntry getFieldDefEntry(FieldDefinition def) {
32 ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); 26 ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName());
33 return new FieldDefEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature()), Signature.createTypedSignature(def.getSignature()), new AccessFlags(def.getModifiers())); 27 return new FieldDefEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature()), Signature.createTypedSignature(def.getSignature()), new AccessFlags(def.getModifiers()));
34 } 28 }
35 29
36 public MethodEntry getMethodEntry(MemberReference def) { 30 public MethodEntry getMethodEntry(MemberReference def) {
37 ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); 31 ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName());
38 return entryPool.getMethod(classEntry, def.getName(), def.getErasedSignature()); 32 return new MethodEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature()));
39 } 33 }
40 34
41 public MethodDefEntry getMethodDefEntry(MethodDefinition def) { 35 public MethodDefEntry getMethodDefEntry(MethodDefinition def) {
42 ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); 36 ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName());
43 return new MethodDefEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature()), Signature.createSignature(def.getSignature()), new AccessFlags(def.getModifiers())); 37 return new MethodDefEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature()), Signature.createSignature(def.getSignature()), new AccessFlags(def.getModifiers()));
44 } 38 }
45} 39}
diff --git a/src/main/java/cuchaz/enigma/translation/representation/ReferencedEntryPool.java b/src/main/java/cuchaz/enigma/translation/representation/ReferencedEntryPool.java
deleted file mode 100644
index 631b375..0000000
--- a/src/main/java/cuchaz/enigma/translation/representation/ReferencedEntryPool.java
+++ /dev/null
@@ -1,60 +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
12package cuchaz.enigma.translation.representation;
13
14import cuchaz.enigma.translation.representation.entry.ClassEntry;
15import cuchaz.enigma.translation.representation.entry.FieldEntry;
16import cuchaz.enigma.translation.representation.entry.MethodEntry;
17
18import java.util.HashMap;
19import java.util.Map;
20
21public class ReferencedEntryPool {
22 private final Map<String, ClassEntry> classEntries = new HashMap<>();
23 private final Map<String, Map<String, MethodEntry>> methodEntries = new HashMap<>();
24 private final Map<String, Map<String, FieldEntry>> fieldEntries = new HashMap<>();
25
26 public ClassEntry getClass(String name) {
27 // TODO: FIXME - I'm a hack!
28 if ("[T".equals(name) || "[[T".equals(name) || "[[[T".equals(name)) {
29 name = name.replaceAll("T", "Ljava/lang/Object;");
30 }
31
32 final String computeName = name;
33 return this.classEntries.computeIfAbsent(name, s -> new ClassEntry(computeName));
34 }
35
36 public MethodEntry getMethod(ClassEntry ownerEntry, String name, String desc) {
37 return getMethod(ownerEntry, name, new MethodDescriptor(desc));
38 }
39
40 public MethodEntry getMethod(ClassEntry ownerEntry, String name, MethodDescriptor desc) {
41 String key = name + desc.toString();
42 return getClassMethods(ownerEntry.getFullName()).computeIfAbsent(key, s -> new MethodEntry(ownerEntry, name, desc));
43 }
44
45 public FieldEntry getField(ClassEntry ownerEntry, String name, String desc) {
46 return getField(ownerEntry, name, new TypeDescriptor(desc));
47 }
48
49 public FieldEntry getField(ClassEntry ownerEntry, String name, TypeDescriptor desc) {
50 return getClassFields(ownerEntry.getFullName()).computeIfAbsent(name, s -> new FieldEntry(ownerEntry, name, desc));
51 }
52
53 private Map<String, MethodEntry> getClassMethods(String name) {
54 return methodEntries.computeIfAbsent(name, s -> new HashMap<>());
55 }
56
57 private Map<String, FieldEntry> getClassFields(String name) {
58 return fieldEntries.computeIfAbsent(name, s -> new HashMap<>());
59 }
60}
diff --git a/src/main/java/cuchaz/enigma/translation/representation/Signature.java b/src/main/java/cuchaz/enigma/translation/representation/Signature.java
index dc241b7..424088a 100644
--- a/src/main/java/cuchaz/enigma/translation/representation/Signature.java
+++ b/src/main/java/cuchaz/enigma/translation/representation/Signature.java
@@ -3,9 +3,9 @@ package cuchaz.enigma.translation.representation;
3import cuchaz.enigma.bytecode.translators.TranslationSignatureVisitor; 3import cuchaz.enigma.bytecode.translators.TranslationSignatureVisitor;
4import cuchaz.enigma.translation.Translatable; 4import cuchaz.enigma.translation.Translatable;
5import cuchaz.enigma.translation.Translator; 5import cuchaz.enigma.translation.Translator;
6import cuchaz.enigma.translation.mapping.EntryMap;
6import cuchaz.enigma.translation.mapping.EntryMapping; 7import cuchaz.enigma.translation.mapping.EntryMapping;
7import cuchaz.enigma.translation.mapping.EntryResolver; 8import cuchaz.enigma.translation.mapping.EntryResolver;
8import cuchaz.enigma.translation.mapping.EntryMap;
9import cuchaz.enigma.translation.representation.entry.ClassEntry; 9import cuchaz.enigma.translation.representation.entry.ClassEntry;
10import org.objectweb.asm.signature.SignatureReader; 10import org.objectweb.asm.signature.SignatureReader;
11import org.objectweb.asm.signature.SignatureVisitor; 11import org.objectweb.asm.signature.SignatureVisitor;
@@ -78,7 +78,12 @@ public class Signature implements Translatable {
78 78
79 @Override 79 @Override
80 public int hashCode() { 80 public int hashCode() {
81 return signature.hashCode() | (isType ? 1 : 0) << 16; 81 int hash = (isType ? 1 : 0) << 16;
82 if (signature != null) {
83 hash |= signature.hashCode();
84 }
85
86 return hash;
82 } 87 }
83 88
84 @Override 89 @Override
diff --git a/src/main/java/cuchaz/enigma/translation/representation/TypeDescriptor.java b/src/main/java/cuchaz/enigma/translation/representation/TypeDescriptor.java
index f7ba849..719d693 100644
--- a/src/main/java/cuchaz/enigma/translation/representation/TypeDescriptor.java
+++ b/src/main/java/cuchaz/enigma/translation/representation/TypeDescriptor.java
@@ -13,6 +13,7 @@ package cuchaz.enigma.translation.representation;
13 13
14import com.google.common.base.Preconditions; 14import com.google.common.base.Preconditions;
15import com.google.common.collect.Maps; 15import com.google.common.collect.Maps;
16import com.strobel.assembler.metadata.TypeReference;
16import cuchaz.enigma.translation.Translatable; 17import cuchaz.enigma.translation.Translatable;
17import cuchaz.enigma.translation.Translator; 18import cuchaz.enigma.translation.Translator;
18import cuchaz.enigma.translation.mapping.EntryMapping; 19import cuchaz.enigma.translation.mapping.EntryMapping;
@@ -111,6 +112,10 @@ public class TypeDescriptor implements Translatable {
111 return new TypeDescriptor("L" + name + ";"); 112 return new TypeDescriptor("L" + name + ";");
112 } 113 }
113 114
115 public static TypeDescriptor parse(TypeReference type) {
116 return new TypeDescriptor(type.getErasedSignature());
117 }
118
114 @Override 119 @Override
115 public String toString() { 120 public String toString() {
116 return this.desc; 121 return this.desc;
diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java
index 5904efe..644658f 100644
--- a/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java
+++ b/src/main/java/cuchaz/enigma/translation/representation/entry/ClassEntry.java
@@ -17,6 +17,7 @@ import cuchaz.enigma.translation.Translator;
17import cuchaz.enigma.translation.mapping.EntryMapping; 17import cuchaz.enigma.translation.mapping.EntryMapping;
18import cuchaz.enigma.translation.mapping.NameValidator; 18import cuchaz.enigma.translation.mapping.NameValidator;
19 19
20import javax.annotation.Nonnull;
20import javax.annotation.Nullable; 21import javax.annotation.Nullable;
21import java.util.List; 22import java.util.List;
22import java.util.Objects; 23import java.util.Objects;
@@ -125,6 +126,7 @@ public class ClassEntry extends ParentedEntry<ClassEntry> implements Comparable<
125 return parent; 126 return parent;
126 } 127 }
127 128
129 @Nonnull
128 public ClassEntry getOutermostClass() { 130 public ClassEntry getOutermostClass() {
129 if (parent == null) { 131 if (parent == null) {
130 return this; 132 return this;
@@ -181,6 +183,15 @@ public class ClassEntry extends ParentedEntry<ClassEntry> implements Comparable<
181 } 183 }
182 184
183 @Override 185 @Override
186 public String getSourceRemapName() {
187 ClassEntry outerClass = getOuterClass();
188 if (outerClass != null) {
189 return outerClass.getSourceRemapName() + "." + name;
190 }
191 return getSimpleName();
192 }
193
194 @Override
184 public int compareTo(ClassEntry entry) { 195 public int compareTo(ClassEntry entry) {
185 return name.compareTo(entry.name); 196 return name.compareTo(entry.name);
186 } 197 }
diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java
index 1a2ca78..227400e 100644
--- a/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java
+++ b/src/main/java/cuchaz/enigma/translation/representation/entry/Entry.java
@@ -22,6 +22,10 @@ import java.util.List;
22public interface Entry<P extends Entry<?>> extends Translatable { 22public interface Entry<P extends Entry<?>> extends Translatable {
23 String getName(); 23 String getName();
24 24
25 default String getSourceRemapName() {
26 return getName();
27 }
28
25 @Nullable 29 @Nullable
26 P getParent(); 30 P getParent();
27 31
diff --git a/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java b/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java
index df96b59..0c12f1c 100644
--- a/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java
+++ b/src/main/java/cuchaz/enigma/translation/representation/entry/LocalVariableEntry.java
@@ -17,11 +17,6 @@ public class LocalVariableEntry extends ParentedEntry<MethodEntry> implements Co
17 protected final int index; 17 protected final int index;
18 protected final boolean parameter; 18 protected final boolean parameter;
19 19
20 @Deprecated
21 public LocalVariableEntry(MethodEntry parent, int index, String name) {
22 this(parent, index, name, true);
23 }
24
25 public LocalVariableEntry(MethodEntry parent, int index, String name, boolean parameter) { 20 public LocalVariableEntry(MethodEntry parent, int index, String name, boolean parameter) {
26 super(parent, name); 21 super(parent, name);
27 22
@@ -37,7 +32,7 @@ public class LocalVariableEntry extends ParentedEntry<MethodEntry> implements Co
37 return MethodEntry.class; 32 return MethodEntry.class;
38 } 33 }
39 34
40 public boolean isParameter() { 35 public boolean isArgument() {
41 return this.parameter; 36 return this.parameter;
42 } 37 }
43 38