diff options
Diffstat (limited to 'src/cuchaz/enigma')
| -rw-r--r-- | src/cuchaz/enigma/bytecode/ClassRenamer.java | 9 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/ParameterizedType.java | 54 | ||||
| -rw-r--r-- | src/cuchaz/enigma/mapping/Type.java | 61 |
3 files changed, 12 insertions, 112 deletions
diff --git a/src/cuchaz/enigma/bytecode/ClassRenamer.java b/src/cuchaz/enigma/bytecode/ClassRenamer.java index d88daa5..d7acd30 100644 --- a/src/cuchaz/enigma/bytecode/ClassRenamer.java +++ b/src/cuchaz/enigma/bytecode/ClassRenamer.java | |||
| @@ -34,7 +34,6 @@ import javassist.bytecode.SignatureAttribute.MethodSignature; | |||
| 34 | import javassist.bytecode.SignatureAttribute.ObjectType; | 34 | import javassist.bytecode.SignatureAttribute.ObjectType; |
| 35 | import cuchaz.enigma.mapping.ClassEntry; | 35 | import cuchaz.enigma.mapping.ClassEntry; |
| 36 | import cuchaz.enigma.mapping.ClassNameReplacer; | 36 | import cuchaz.enigma.mapping.ClassNameReplacer; |
| 37 | import cuchaz.enigma.mapping.ParameterizedType; | ||
| 38 | import cuchaz.enigma.mapping.Translator; | 37 | import cuchaz.enigma.mapping.Translator; |
| 39 | import cuchaz.enigma.mapping.Type; | 38 | import cuchaz.enigma.mapping.Type; |
| 40 | 39 | ||
| @@ -103,8 +102,8 @@ public class ClassRenamer { | |||
| 103 | } | 102 | } |
| 104 | 103 | ||
| 105 | public String getFramed(String typeName) { | 104 | public String getFramed(String typeName) { |
| 106 | ParameterizedType type = new ParameterizedType(new Type(typeName)); | 105 | Type type = new Type(typeName); |
| 107 | ParameterizedType renamedType = new ParameterizedType(type, m_replacer); | 106 | Type renamedType = new Type(type, m_replacer); |
| 108 | if (!type.equals(renamedType)) { | 107 | if (!type.equals(renamedType)) { |
| 109 | return renamedType.toString(); | 108 | return renamedType.toString(); |
| 110 | } | 109 | } |
| @@ -115,6 +114,7 @@ public class ClassRenamer { | |||
| 115 | 114 | ||
| 116 | // we can deal with the ones that start with a class | 115 | // we can deal with the ones that start with a class |
| 117 | String signature = type.encode(); | 116 | String signature = type.encode(); |
| 117 | /* | ||
| 118 | if (signature.startsWith("L") || signature.startsWith("[")) { | 118 | if (signature.startsWith("L") || signature.startsWith("[")) { |
| 119 | 119 | ||
| 120 | // TEMP: skip special characters for now | 120 | // TEMP: skip special characters for now |
| @@ -134,10 +134,11 @@ public class ClassRenamer { | |||
| 134 | // don't need to care about template names | 134 | // don't need to care about template names |
| 135 | return null; | 135 | return null; |
| 136 | } else { | 136 | } else { |
| 137 | */ | ||
| 137 | // TEMP | 138 | // TEMP |
| 138 | System.out.println("Skipping translating: " + signature); | 139 | System.out.println("Skipping translating: " + signature); |
| 139 | return null; | 140 | return null; |
| 140 | } | 141 | //} |
| 141 | } | 142 | } |
| 142 | } | 143 | } |
| 143 | 144 | ||
diff --git a/src/cuchaz/enigma/mapping/ParameterizedType.java b/src/cuchaz/enigma/mapping/ParameterizedType.java deleted file mode 100644 index af24ef4..0000000 --- a/src/cuchaz/enigma/mapping/ParameterizedType.java +++ /dev/null | |||
| @@ -1,54 +0,0 @@ | |||
| 1 | package cuchaz.enigma.mapping; | ||
| 2 | |||
| 3 | import cuchaz.enigma.Util; | ||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | public class ParameterizedType extends Type { | ||
| 8 | |||
| 9 | private static final long serialVersionUID = 1758975507937309011L; | ||
| 10 | |||
| 11 | public ParameterizedType(Type other) { | ||
| 12 | super(other); | ||
| 13 | for (int i=0; i<m_parameters.size(); i++) { | ||
| 14 | m_parameters.set(i, new ParameterizedType(m_parameters.get(i))); | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | public ParameterizedType(ParameterizedType type, ClassNameReplacer replacer) { | ||
| 19 | this(new Type(type, replacer)); | ||
| 20 | } | ||
| 21 | |||
| 22 | @Override | ||
| 23 | public String toString() { | ||
| 24 | if (hasParameters()) { | ||
| 25 | StringBuilder buf = new StringBuilder(); | ||
| 26 | buf.append(m_name.substring(0, m_name.length() - 1)); | ||
| 27 | buf.append("<"); | ||
| 28 | for (Type parameter : parameters()) { | ||
| 29 | buf.append(parameter.toString()); | ||
| 30 | } | ||
| 31 | buf.append(">;"); | ||
| 32 | return buf.toString(); | ||
| 33 | } else { | ||
| 34 | return m_name; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | @Override | ||
| 39 | public boolean equals(Object other) { | ||
| 40 | if (other instanceof ParameterizedType) { | ||
| 41 | return equals((ParameterizedType)other); | ||
| 42 | } | ||
| 43 | return false; | ||
| 44 | } | ||
| 45 | |||
| 46 | public boolean equals(ParameterizedType other) { | ||
| 47 | return m_name.equals(other.m_name) && m_parameters.equals(other.m_parameters); | ||
| 48 | } | ||
| 49 | |||
| 50 | public int hashCode() { | ||
| 51 | return Util.combineHashesOrdered(m_name.hashCode(), m_parameters.hashCode()); | ||
| 52 | } | ||
| 53 | |||
| 54 | } | ||
diff --git a/src/cuchaz/enigma/mapping/Type.java b/src/cuchaz/enigma/mapping/Type.java index d530083..3f441e2 100644 --- a/src/cuchaz/enigma/mapping/Type.java +++ b/src/cuchaz/enigma/mapping/Type.java | |||
| @@ -1,10 +1,8 @@ | |||
| 1 | package cuchaz.enigma.mapping; | 1 | package cuchaz.enigma.mapping; |
| 2 | 2 | ||
| 3 | import java.io.Serializable; | 3 | import java.io.Serializable; |
| 4 | import java.util.List; | ||
| 5 | import java.util.Map; | 4 | import java.util.Map; |
| 6 | 5 | ||
| 7 | import com.beust.jcommander.internal.Lists; | ||
| 8 | import com.google.common.collect.Maps; | 6 | import com.google.common.collect.Maps; |
| 9 | 7 | ||
| 10 | public class Type implements Serializable { | 8 | public class Type implements Serializable { |
| @@ -85,43 +83,22 @@ public class Type implements Serializable { | |||
| 85 | 83 | ||
| 86 | throw new IllegalArgumentException("don't know how to parse: " + in); | 84 | throw new IllegalArgumentException("don't know how to parse: " + in); |
| 87 | } | 85 | } |
| 88 | 86 | ||
| 89 | protected String m_name; | 87 | protected String m_name; |
| 90 | protected List<Type> m_parameters; | ||
| 91 | 88 | ||
| 92 | public Type(String name) { | 89 | public Type(String name) { |
| 93 | m_name = null; | ||
| 94 | m_parameters = Lists.newArrayList(); | ||
| 95 | 90 | ||
| 96 | int start = name.indexOf('<'); | 91 | // don't deal with generics |
| 97 | int stop = name.lastIndexOf('>'); | 92 | // this is just for raw jvm types |
| 98 | if (start > 0 && stop > start) { | 93 | if (name.charAt(0) == 'T' || name.indexOf('<') >= 0 || name.indexOf('>') >= 0) { |
| 99 | 94 | throw new IllegalArgumentException("don't use with generic types or templates: " + name); | |
| 100 | // deal with generic parameters | ||
| 101 | m_name = name.substring(0, start) + name.substring(stop + 1); | ||
| 102 | |||
| 103 | String parameters = name.substring(start + 1, stop); | ||
| 104 | int i=0; | ||
| 105 | while (i<parameters.length()) { | ||
| 106 | String typeName = Type.parseFirst(parameters.substring(i)); | ||
| 107 | if (typeName == null) { | ||
| 108 | throw new Error("Don't know how to parse parameters: " + name); | ||
| 109 | } | ||
| 110 | m_parameters.add(new Type(typeName)); | ||
| 111 | i += typeName.length(); | ||
| 112 | } | ||
| 113 | |||
| 114 | } else { | ||
| 115 | m_name = name; | ||
| 116 | } | 95 | } |
| 96 | |||
| 97 | m_name = name; | ||
| 117 | } | 98 | } |
| 118 | 99 | ||
| 119 | public Type(Type other) { | 100 | public Type(Type other) { |
| 120 | m_name = other.m_name; | 101 | m_name = other.m_name; |
| 121 | m_parameters = Lists.newArrayList(); | ||
| 122 | for (Type parameter : other.m_parameters) { | ||
| 123 | m_parameters.add(new Type(parameter)); | ||
| 124 | } | ||
| 125 | } | 102 | } |
| 126 | 103 | ||
| 127 | public Type(ClassEntry classEntry) { | 104 | public Type(ClassEntry classEntry) { |
| @@ -141,11 +118,6 @@ public class Type implements Serializable { | |||
| 141 | m_name = Type.getArrayPrefix(other.getArrayDimension()) + "L" + replacedName + ";"; | 118 | m_name = Type.getArrayPrefix(other.getArrayDimension()) + "L" + replacedName + ";"; |
| 142 | } | 119 | } |
| 143 | } | 120 | } |
| 144 | |||
| 145 | m_parameters = Lists.newArrayList(); | ||
| 146 | for (Type parameter : other.m_parameters) { | ||
| 147 | m_parameters.add(new Type(parameter, replacer)); | ||
| 148 | } | ||
| 149 | } | 121 | } |
| 150 | 122 | ||
| 151 | @Override | 123 | @Override |
| @@ -191,17 +163,6 @@ public class Type implements Serializable { | |||
| 191 | } | 163 | } |
| 192 | } | 164 | } |
| 193 | 165 | ||
| 194 | public boolean isTemplate() { | ||
| 195 | return m_name.charAt(0) == 'T' && m_name.charAt(m_name.length() - 1) == ';'; | ||
| 196 | } | ||
| 197 | |||
| 198 | public String getTemplate() { | ||
| 199 | if (!isTemplate()) { | ||
| 200 | throw new IllegalStateException("not an template"); | ||
| 201 | } | ||
| 202 | return m_name.substring(1, m_name.length() - 1); | ||
| 203 | } | ||
| 204 | |||
| 205 | public boolean isArray() { | 166 | public boolean isArray() { |
| 206 | return m_name.charAt(0) == '['; | 167 | return m_name.charAt(0) == '['; |
| 207 | } | 168 | } |
| @@ -232,14 +193,6 @@ public class Type implements Serializable { | |||
| 232 | return isClass() || (isArray() && getArrayType().hasClass()); | 193 | return isClass() || (isArray() && getArrayType().hasClass()); |
| 233 | } | 194 | } |
| 234 | 195 | ||
| 235 | public boolean hasParameters() { | ||
| 236 | return !m_parameters.isEmpty(); | ||
| 237 | } | ||
| 238 | |||
| 239 | public Iterable<Type> parameters() { | ||
| 240 | return m_parameters; | ||
| 241 | } | ||
| 242 | |||
| 243 | @Override | 196 | @Override |
| 244 | public boolean equals(Object other) { | 197 | public boolean equals(Object other) { |
| 245 | if (other instanceof Type) { | 198 | if (other instanceof Type) { |