From ba7a354efae7d49833c887cf147ac940c975a1fa Mon Sep 17 00:00:00 2001 From: Gegy Date: Wed, 30 Jan 2019 21:05:32 +0200 Subject: 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 --- .../representation/ProcyonEntryFactory.java | 18 +++---- .../representation/ReferencedEntryPool.java | 60 ---------------------- .../translation/representation/Signature.java | 9 +++- .../translation/representation/TypeDescriptor.java | 5 ++ .../representation/entry/ClassEntry.java | 11 ++++ .../translation/representation/entry/Entry.java | 4 ++ .../representation/entry/LocalVariableEntry.java | 7 +-- 7 files changed, 34 insertions(+), 80 deletions(-) delete mode 100644 src/main/java/cuchaz/enigma/translation/representation/ReferencedEntryPool.java (limited to 'src/main/java/cuchaz/enigma/translation/representation') 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; import cuchaz.enigma.translation.representation.entry.*; public class ProcyonEntryFactory { - private final ReferencedEntryPool entryPool; - - public ProcyonEntryFactory(ReferencedEntryPool entryPool) { - this.entryPool = entryPool; - } - public FieldEntry getFieldEntry(MemberReference def) { - ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); - return entryPool.getField(classEntry, def.getName(), def.getErasedSignature()); + ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); + return new FieldEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature())); } public FieldDefEntry getFieldDefEntry(FieldDefinition def) { - ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); + ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); return new FieldDefEntry(classEntry, def.getName(), new TypeDescriptor(def.getErasedSignature()), Signature.createTypedSignature(def.getSignature()), new AccessFlags(def.getModifiers())); } public MethodEntry getMethodEntry(MemberReference def) { - ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); - return entryPool.getMethod(classEntry, def.getName(), def.getErasedSignature()); + ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); + return new MethodEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature())); } public MethodDefEntry getMethodDefEntry(MethodDefinition def) { - ClassEntry classEntry = entryPool.getClass(def.getDeclaringType().getInternalName()); + ClassEntry classEntry = new ClassEntry(def.getDeclaringType().getInternalName()); return new MethodDefEntry(classEntry, def.getName(), new MethodDescriptor(def.getErasedSignature()), Signature.createSignature(def.getSignature()), new AccessFlags(def.getModifiers())); } } 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 @@ -/******************************************************************************* - * 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.translation.representation; - -import cuchaz.enigma.translation.representation.entry.ClassEntry; -import cuchaz.enigma.translation.representation.entry.FieldEntry; -import cuchaz.enigma.translation.representation.entry.MethodEntry; - -import java.util.HashMap; -import java.util.Map; - -public class ReferencedEntryPool { - private final Map classEntries = new HashMap<>(); - private final Map> methodEntries = new HashMap<>(); - private final Map> fieldEntries = new HashMap<>(); - - public ClassEntry getClass(String name) { - // TODO: FIXME - I'm a hack! - if ("[T".equals(name) || "[[T".equals(name) || "[[[T".equals(name)) { - name = name.replaceAll("T", "Ljava/lang/Object;"); - } - - final String computeName = name; - return this.classEntries.computeIfAbsent(name, s -> new ClassEntry(computeName)); - } - - public MethodEntry getMethod(ClassEntry ownerEntry, String name, String desc) { - return getMethod(ownerEntry, name, new MethodDescriptor(desc)); - } - - public MethodEntry getMethod(ClassEntry ownerEntry, String name, MethodDescriptor desc) { - String key = name + desc.toString(); - return getClassMethods(ownerEntry.getFullName()).computeIfAbsent(key, s -> new MethodEntry(ownerEntry, name, desc)); - } - - public FieldEntry getField(ClassEntry ownerEntry, String name, String desc) { - return getField(ownerEntry, name, new TypeDescriptor(desc)); - } - - public FieldEntry getField(ClassEntry ownerEntry, String name, TypeDescriptor desc) { - return getClassFields(ownerEntry.getFullName()).computeIfAbsent(name, s -> new FieldEntry(ownerEntry, name, desc)); - } - - private Map getClassMethods(String name) { - return methodEntries.computeIfAbsent(name, s -> new HashMap<>()); - } - - private Map getClassFields(String name) { - return fieldEntries.computeIfAbsent(name, s -> new HashMap<>()); - } -} 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; import cuchaz.enigma.bytecode.translators.TranslationSignatureVisitor; import cuchaz.enigma.translation.Translatable; import cuchaz.enigma.translation.Translator; +import cuchaz.enigma.translation.mapping.EntryMap; import cuchaz.enigma.translation.mapping.EntryMapping; import cuchaz.enigma.translation.mapping.EntryResolver; -import cuchaz.enigma.translation.mapping.EntryMap; import cuchaz.enigma.translation.representation.entry.ClassEntry; import org.objectweb.asm.signature.SignatureReader; import org.objectweb.asm.signature.SignatureVisitor; @@ -78,7 +78,12 @@ public class Signature implements Translatable { @Override public int hashCode() { - return signature.hashCode() | (isType ? 1 : 0) << 16; + int hash = (isType ? 1 : 0) << 16; + if (signature != null) { + hash |= signature.hashCode(); + } + + return hash; } @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; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; +import com.strobel.assembler.metadata.TypeReference; import cuchaz.enigma.translation.Translatable; import cuchaz.enigma.translation.Translator; import cuchaz.enigma.translation.mapping.EntryMapping; @@ -111,6 +112,10 @@ public class TypeDescriptor implements Translatable { return new TypeDescriptor("L" + name + ";"); } + public static TypeDescriptor parse(TypeReference type) { + return new TypeDescriptor(type.getErasedSignature()); + } + @Override public String toString() { 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; import cuchaz.enigma.translation.mapping.EntryMapping; import cuchaz.enigma.translation.mapping.NameValidator; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; import java.util.Objects; @@ -125,6 +126,7 @@ public class ClassEntry extends ParentedEntry implements Comparable< return parent; } + @Nonnull public ClassEntry getOutermostClass() { if (parent == null) { return this; @@ -180,6 +182,15 @@ public class ClassEntry extends ParentedEntry implements Comparable< return name; } + @Override + public String getSourceRemapName() { + ClassEntry outerClass = getOuterClass(); + if (outerClass != null) { + return outerClass.getSourceRemapName() + "." + name; + } + return getSimpleName(); + } + @Override public int compareTo(ClassEntry entry) { return name.compareTo(entry.name); 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; public interface Entry

> extends Translatable { String getName(); + default String getSourceRemapName() { + return getName(); + } + @Nullable P getParent(); 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 implements Co protected final int index; protected final boolean parameter; - @Deprecated - public LocalVariableEntry(MethodEntry parent, int index, String name) { - this(parent, index, name, true); - } - public LocalVariableEntry(MethodEntry parent, int index, String name, boolean parameter) { super(parent, name); @@ -37,7 +32,7 @@ public class LocalVariableEntry extends ParentedEntry implements Co return MethodEntry.class; } - public boolean isParameter() { + public boolean isArgument() { return this.parameter; } -- cgit v1.2.3