diff options
| author | 2018-05-19 18:02:29 +0200 | |
|---|---|---|
| committer | 2018-05-19 18:02:29 +0200 | |
| commit | 8e7453727ff059c8f1db7f89f6793d22cbd5e6fc (patch) | |
| tree | d15e55f61705fd9cd0a1d54816c09d0b6cc0ec36 /src/main/java/cuchaz/enigma/mapping | |
| parent | Package updates (diff) | |
| download | enigma-fork-8e7453727ff059c8f1db7f89f6793d22cbd5e6fc.tar.gz enigma-fork-8e7453727ff059c8f1db7f89f6793d22cbd5e6fc.tar.xz enigma-fork-8e7453727ff059c8f1db7f89f6793d22cbd5e6fc.zip | |
Annotation + inner class translation
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping')
5 files changed, 22 insertions, 6 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/DirectionalTranslator.java b/src/main/java/cuchaz/enigma/mapping/DirectionalTranslator.java index c9e2ab4..196bbd6 100644 --- a/src/main/java/cuchaz/enigma/mapping/DirectionalTranslator.java +++ b/src/main/java/cuchaz/enigma/mapping/DirectionalTranslator.java | |||
| @@ -185,7 +185,7 @@ public class DirectionalTranslator implements Translator { | |||
| 185 | } | 185 | } |
| 186 | // TODO: Translating arguments calls method translation.. Can we refactor the code in such a way that we don't need this? | 186 | // TODO: Translating arguments calls method translation.. Can we refactor the code in such a way that we don't need this? |
| 187 | MethodEntry translatedOwner = getTranslatedMethod(entry.getOwnerEntry()); | 187 | MethodEntry translatedOwner = getTranslatedMethod(entry.getOwnerEntry()); |
| 188 | return new LocalVariableEntry(translatedOwner, entry.getIndex(), translatedArgumentName); | 188 | return new LocalVariableEntry(translatedOwner != null ? translatedOwner : entry.getOwnerEntry(), entry.getIndex(), translatedArgumentName); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | @Override | 191 | @Override |
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java index 9b907a9..79d9f10 100644 --- a/src/main/java/cuchaz/enigma/mapping/Mappings.java +++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -156,7 +156,7 @@ public class Mappings { | |||
| 156 | for (MethodMapping methodMapping : classMapping.methods()) { | 156 | for (MethodMapping methodMapping : classMapping.methods()) { |
| 157 | for (TypeDescriptor desc : methodMapping.getObfDesc().types()) { | 157 | for (TypeDescriptor desc : methodMapping.getObfDesc().types()) { |
| 158 | if (desc.containsType()) { | 158 | if (desc.containsType()) { |
| 159 | classNames.add(desc.getOwnerEntry().getClassName()); | 159 | classNames.add(desc.getTypeEntry().getClassName()); |
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | } | 162 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodDescriptor.java b/src/main/java/cuchaz/enigma/mapping/MethodDescriptor.java index b56d1d4..0fc0351 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodDescriptor.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodDescriptor.java | |||
| @@ -97,7 +97,7 @@ public class MethodDescriptor { | |||
| 97 | 97 | ||
| 98 | public boolean hasClass(ClassEntry classEntry) { | 98 | public boolean hasClass(ClassEntry classEntry) { |
| 99 | for (TypeDescriptor desc : types()) { | 99 | for (TypeDescriptor desc : types()) { |
| 100 | if (desc.containsType() && desc.getOwnerEntry().equals(classEntry)) { | 100 | if (desc.containsType() && desc.getTypeEntry().equals(classEntry)) { |
| 101 | return true; | 101 | return true; |
| 102 | } | 102 | } |
| 103 | } | 103 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/Translator.java b/src/main/java/cuchaz/enigma/mapping/Translator.java index ab55a02..6373da7 100644 --- a/src/main/java/cuchaz/enigma/mapping/Translator.java +++ b/src/main/java/cuchaz/enigma/mapping/Translator.java | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | package cuchaz.enigma.mapping; | 12 | package cuchaz.enigma.mapping; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.mapping.entry.*; | 14 | import cuchaz.enigma.mapping.entry.*; |
| 15 | import org.objectweb.asm.Type; | ||
| 15 | 16 | ||
| 16 | public interface Translator { | 17 | public interface Translator { |
| 17 | ClassEntry getTranslatedClass(ClassEntry entry); | 18 | ClassEntry getTranslatedClass(ClassEntry entry); |
| @@ -34,6 +35,18 @@ public interface Translator { | |||
| 34 | 35 | ||
| 35 | MethodDescriptor getTranslatedMethodDesc(MethodDescriptor descriptor); | 36 | MethodDescriptor getTranslatedMethodDesc(MethodDescriptor descriptor); |
| 36 | 37 | ||
| 38 | default Type getTranslatedType(Type type) { | ||
| 39 | String descString = type.getDescriptor(); | ||
| 40 | // If this is a method | ||
| 41 | if (descString.contains("(")) { | ||
| 42 | MethodDescriptor descriptor = new MethodDescriptor(descString); | ||
| 43 | return Type.getMethodType(getTranslatedMethodDesc(descriptor).toString()); | ||
| 44 | } else { | ||
| 45 | TypeDescriptor descriptor = new TypeDescriptor(descString); | ||
| 46 | return Type.getType(getTranslatedTypeDesc(descriptor).toString()); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 37 | @SuppressWarnings("unchecked") | 50 | @SuppressWarnings("unchecked") |
| 38 | default <T extends Entry> T getTranslatedEntry(T entry) { | 51 | default <T extends Entry> T getTranslatedEntry(T entry) { |
| 39 | if (entry instanceof ClassDefEntry) { | 52 | if (entry instanceof ClassDefEntry) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/TypeDescriptor.java b/src/main/java/cuchaz/enigma/mapping/TypeDescriptor.java index 58fa651..b7b1255 100644 --- a/src/main/java/cuchaz/enigma/mapping/TypeDescriptor.java +++ b/src/main/java/cuchaz/enigma/mapping/TypeDescriptor.java | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma.mapping; | 12 | package cuchaz.enigma.mapping; |
| 13 | 13 | ||
| 14 | import com.google.common.base.Preconditions; | ||
| 14 | import com.google.common.collect.Maps; | 15 | import com.google.common.collect.Maps; |
| 15 | import cuchaz.enigma.mapping.entry.ClassEntry; | 16 | import cuchaz.enigma.mapping.entry.ClassEntry; |
| 16 | 17 | ||
| @@ -22,6 +23,8 @@ public class TypeDescriptor { | |||
| 22 | protected final String desc; | 23 | protected final String desc; |
| 23 | 24 | ||
| 24 | public TypeDescriptor(String desc) { | 25 | public TypeDescriptor(String desc) { |
| 26 | Preconditions.checkNotNull(desc, "Desc cannot be null"); | ||
| 27 | |||
| 25 | // don't deal with generics | 28 | // don't deal with generics |
| 26 | // this is just for raw jvm types | 29 | // this is just for raw jvm types |
| 27 | if (desc.charAt(0) == 'T' || desc.indexOf('<') >= 0 || desc.indexOf('>') >= 0) { | 30 | if (desc.charAt(0) == 'T' || desc.indexOf('<') >= 0 || desc.indexOf('>') >= 0) { |
| @@ -127,7 +130,7 @@ public class TypeDescriptor { | |||
| 127 | return this.desc.charAt(0) == 'L' && this.desc.charAt(this.desc.length() - 1) == ';'; | 130 | return this.desc.charAt(0) == 'L' && this.desc.charAt(this.desc.length() - 1) == ';'; |
| 128 | } | 131 | } |
| 129 | 132 | ||
| 130 | public ClassEntry getOwnerEntry() { | 133 | public ClassEntry getTypeEntry() { |
| 131 | if (isType()) { | 134 | if (isType()) { |
| 132 | String name = this.desc.substring(1, this.desc.length() - 1); | 135 | String name = this.desc.substring(1, this.desc.length() - 1); |
| 133 | 136 | ||
| @@ -140,7 +143,7 @@ public class TypeDescriptor { | |||
| 140 | return new ClassEntry(name); | 143 | return new ClassEntry(name); |
| 141 | 144 | ||
| 142 | } else if (isArray() && getArrayType().isType()) { | 145 | } else if (isArray() && getArrayType().isType()) { |
| 143 | return getArrayType().getOwnerEntry(); | 146 | return getArrayType().getTypeEntry(); |
| 144 | } else { | 147 | } else { |
| 145 | throw new IllegalStateException("desc doesn't have a class"); | 148 | throw new IllegalStateException("desc doesn't have a class"); |
| 146 | } | 149 | } |
| @@ -185,7 +188,7 @@ public class TypeDescriptor { | |||
| 185 | public TypeDescriptor remap(Function<String, String> remapper) { | 188 | public TypeDescriptor remap(Function<String, String> remapper) { |
| 186 | String desc = this.desc; | 189 | String desc = this.desc; |
| 187 | if (isType() || (isArray() && containsType())) { | 190 | if (isType() || (isArray() && containsType())) { |
| 188 | String replacedName = remapper.apply(this.getOwnerEntry().getName()); | 191 | String replacedName = remapper.apply(this.getTypeEntry().getName()); |
| 189 | if (replacedName != null) { | 192 | if (replacedName != null) { |
| 190 | if (this.isType()) { | 193 | if (this.isType()) { |
| 191 | desc = "L" + replacedName + ";"; | 194 | desc = "L" + replacedName + ";"; |