diff options
| author | 2015-03-17 20:01:55 -0400 | |
|---|---|---|
| committer | 2015-03-17 20:01:55 -0400 | |
| commit | ecfda21f3db9e62e3acf074e9842e92ace4cb3ab (patch) | |
| tree | 1186068f246be4f2da197ce006ccaea79945dfa6 | |
| parent | slightly better support for generics (diff) | |
| download | enigma-fork-ecfda21f3db9e62e3acf074e9842e92ace4cb3ab.tar.gz enigma-fork-ecfda21f3db9e62e3acf074e9842e92ace4cb3ab.tar.xz enigma-fork-ecfda21f3db9e62e3acf074e9842e92ace4cb3ab.zip | |
parsing generic signatures is tricky. don't write custom code to do it. switching to library instead
| -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 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestType.java | 167 |
4 files changed, 22 insertions, 269 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) { |
diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java index 544a10c..71aaaee 100644 --- a/test/cuchaz/enigma/TestType.java +++ b/test/cuchaz/enigma/TestType.java | |||
| @@ -6,7 +6,6 @@ import static org.hamcrest.Matchers.*; | |||
| 6 | 6 | ||
| 7 | import org.junit.Test; | 7 | import org.junit.Test; |
| 8 | 8 | ||
| 9 | import cuchaz.enigma.mapping.ParameterizedType; | ||
| 10 | import cuchaz.enigma.mapping.Type; | 9 | import cuchaz.enigma.mapping.Type; |
| 11 | 10 | ||
| 12 | 11 | ||
| @@ -24,7 +23,6 @@ public class TestType { | |||
| 24 | assertThat(new Type("D").isVoid(), is(false)); | 23 | assertThat(new Type("D").isVoid(), is(false)); |
| 25 | assertThat(new Type("LFoo;").isVoid(), is(false)); | 24 | assertThat(new Type("LFoo;").isVoid(), is(false)); |
| 26 | assertThat(new Type("[I").isVoid(), is(false)); | 25 | assertThat(new Type("[I").isVoid(), is(false)); |
| 27 | assertThat(new Type("TFoo;").isVoid(), is(false)); | ||
| 28 | } | 26 | } |
| 29 | 27 | ||
| 30 | @Test | 28 | @Test |
| @@ -39,7 +37,6 @@ public class TestType { | |||
| 39 | assertThat(new Type("D").isPrimitive(), is(true)); | 37 | assertThat(new Type("D").isPrimitive(), is(true)); |
| 40 | assertThat(new Type("LFoo;").isPrimitive(), is(false)); | 38 | assertThat(new Type("LFoo;").isPrimitive(), is(false)); |
| 41 | assertThat(new Type("[I").isPrimitive(), is(false)); | 39 | assertThat(new Type("[I").isPrimitive(), is(false)); |
| 42 | assertThat(new Type("TFoo;").isPrimitive(), is(false)); | ||
| 43 | } | 40 | } |
| 44 | 41 | ||
| 45 | @Test | 42 | @Test |
| @@ -64,26 +61,19 @@ public class TestType { | |||
| 64 | assertThat(new Type("F").isClass(), is(false)); | 61 | assertThat(new Type("F").isClass(), is(false)); |
| 65 | assertThat(new Type("D").isClass(), is(false)); | 62 | assertThat(new Type("D").isClass(), is(false)); |
| 66 | assertThat(new Type("LFoo;").isClass(), is(true)); | 63 | assertThat(new Type("LFoo;").isClass(), is(true)); |
| 67 | assertThat(new Type("LFoo<LCow;>;").isClass(), is(true)); | ||
| 68 | assertThat(new Type("LFoo<LCow;LBeer;>;").isClass(), is(true)); | ||
| 69 | assertThat(new Type("LFoo<LPair<LCow;LBeer;>;>;").isClass(), is(true)); | ||
| 70 | assertThat(new Type("[I").isClass(), is(false)); | 64 | assertThat(new Type("[I").isClass(), is(false)); |
| 71 | assertThat(new Type("TFoo;").isClass(), is(false)); | ||
| 72 | } | 65 | } |
| 73 | 66 | ||
| 74 | @Test | 67 | @Test |
| 75 | public void getClassEntry() { | 68 | public void getClassEntry() { |
| 76 | assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); | 69 | assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); |
| 77 | assertThat(new Type("LFoo<Ljava/lang/String;>;").getClassEntry(), is(newClass("Foo"))); | 70 | assertThat(new Type("Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String"))); |
| 78 | assertThat(new Type("LFoo<LCow;>;").getClassEntry(), is(newClass("Foo"))); | ||
| 79 | assertThat(new Type("LFoo<LCow;LBeer;>;").getClassEntry(), is(newClass("Foo"))); | ||
| 80 | assertThat(new Type("LFoo<LPair<LCow;LBeer;>;>;").getClassEntry(), is(newClass("Foo"))); | ||
| 81 | } | 71 | } |
| 82 | 72 | ||
| 83 | @Test | 73 | @Test |
| 84 | public void getArrayClassEntry() { | 74 | public void getArrayClassEntry() { |
| 85 | assertThat(new Type("[LFoo;").getClassEntry(), is(newClass("Foo"))); | 75 | assertThat(new Type("[LFoo;").getClassEntry(), is(newClass("Foo"))); |
| 86 | assertThat(new Type("[[[LFoo<Ljava/lang/String;>;").getClassEntry(), is(newClass("Foo"))); | 76 | assertThat(new Type("[[[Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String"))); |
| 87 | } | 77 | } |
| 88 | 78 | ||
| 89 | @Test | 79 | @Test |
| @@ -98,7 +88,6 @@ public class TestType { | |||
| 98 | assertThat(new Type("D").isArray(), is(false)); | 88 | assertThat(new Type("D").isArray(), is(false)); |
| 99 | assertThat(new Type("LFoo;").isArray(), is(false)); | 89 | assertThat(new Type("LFoo;").isArray(), is(false)); |
| 100 | assertThat(new Type("[I").isArray(), is(true)); | 90 | assertThat(new Type("[I").isArray(), is(true)); |
| 101 | assertThat(new Type("TFoo;").isArray(), is(false)); | ||
| 102 | } | 91 | } |
| 103 | 92 | ||
| 104 | @Test | 93 | @Test |
| @@ -117,33 +106,9 @@ public class TestType { | |||
| 117 | } | 106 | } |
| 118 | 107 | ||
| 119 | @Test | 108 | @Test |
| 120 | public void isTemplate() { | ||
| 121 | assertThat(new Type("V").isTemplate(), is(false)); | ||
| 122 | assertThat(new Type("Z").isTemplate(), is(false)); | ||
| 123 | assertThat(new Type("B").isTemplate(), is(false)); | ||
| 124 | assertThat(new Type("C").isTemplate(), is(false)); | ||
| 125 | assertThat(new Type("I").isTemplate(), is(false)); | ||
| 126 | assertThat(new Type("J").isTemplate(), is(false)); | ||
| 127 | assertThat(new Type("F").isTemplate(), is(false)); | ||
| 128 | assertThat(new Type("D").isTemplate(), is(false)); | ||
| 129 | assertThat(new Type("LFoo;").isTemplate(), is(false)); | ||
| 130 | assertThat(new Type("LFoo<LCow;>;").isTemplate(), is(false)); | ||
| 131 | assertThat(new Type("LFoo<LCow;LBeer;>;").isTemplate(), is(false)); | ||
| 132 | assertThat(new Type("LFoo<LPair<LCow;LBeer;>;>;").isTemplate(), is(false)); | ||
| 133 | assertThat(new Type("[I").isTemplate(), is(false)); | ||
| 134 | assertThat(new Type("TFoo;").isTemplate(), is(true)); | ||
| 135 | } | ||
| 136 | |||
| 137 | @Test | ||
| 138 | public void getTemplate() { | ||
| 139 | assertThat(new Type("TT;").getTemplate(), is("T")); | ||
| 140 | assertThat(new Type("TFoo;").getTemplate(), is("Foo")); | ||
| 141 | } | ||
| 142 | |||
| 143 | @Test | ||
| 144 | public void hasClass() { | 109 | public void hasClass() { |
| 145 | assertThat(new Type("LFoo;").hasClass(), is(true)); | 110 | assertThat(new Type("LFoo;").hasClass(), is(true)); |
| 146 | assertThat(new Type("LCow<LCheese;>;").hasClass(), is(true)); | 111 | assertThat(new Type("Ljava/lang/String;").hasClass(), is(true)); |
| 147 | assertThat(new Type("[LBar;").hasClass(), is(true)); | 112 | assertThat(new Type("[LBar;").hasClass(), is(true)); |
| 148 | assertThat(new Type("[[[LCat;").hasClass(), is(true)); | 113 | assertThat(new Type("[[[LCat;").hasClass(), is(true)); |
| 149 | 114 | ||
| @@ -151,37 +116,6 @@ public class TestType { | |||
| 151 | assertThat(new Type("[I").hasClass(), is(false)); | 116 | assertThat(new Type("[I").hasClass(), is(false)); |
| 152 | assertThat(new Type("[[[I").hasClass(), is(false)); | 117 | assertThat(new Type("[[[I").hasClass(), is(false)); |
| 153 | assertThat(new Type("Z").hasClass(), is(false)); | 118 | assertThat(new Type("Z").hasClass(), is(false)); |
| 154 | assertThat(new Type("TFoo;").hasClass(), is(false)); | ||
| 155 | } | ||
| 156 | |||
| 157 | @Test | ||
| 158 | public void parameters() { | ||
| 159 | assertThat(new Type("LFoo<I>;").parameters(), contains( | ||
| 160 | new Type("I") | ||
| 161 | )); | ||
| 162 | assertThat(new Type("LFoo<IIII>;").parameters(), contains( | ||
| 163 | new Type("I"), | ||
| 164 | new Type("I"), | ||
| 165 | new Type("I"), | ||
| 166 | new Type("I") | ||
| 167 | )); | ||
| 168 | assertThat(new Type("LFoo<LBar;>;").parameters(), contains( | ||
| 169 | new Type("LBar;") | ||
| 170 | )); | ||
| 171 | assertThat(new Type("LFoo<LBar;LCow;LCheese;>;").parameters(), contains( | ||
| 172 | new Type("LBar;"), | ||
| 173 | new Type("LCow;"), | ||
| 174 | new Type("LCheese;") | ||
| 175 | )); | ||
| 176 | |||
| 177 | assertThat(new Type("LFoo<LBar<LCow;LCheese;>;>;").parameters(), contains( | ||
| 178 | new Type("LBar<LCow;LCheese;>;") | ||
| 179 | )); | ||
| 180 | |||
| 181 | assertThat(new Type("LFoo<LBar<LCow;LCheese;>;>;").parameters().iterator().next().parameters(), contains( | ||
| 182 | new Type("LCow;"), | ||
| 183 | new Type("LCheese;") | ||
| 184 | )); | ||
| 185 | } | 119 | } |
| 186 | 120 | ||
| 187 | @Test | 121 | @Test |
| @@ -218,37 +152,17 @@ public class TestType { | |||
| 218 | assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); | 152 | assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); |
| 219 | } | 153 | } |
| 220 | { | 154 | { |
| 221 | final String answer = "LFoo<LFoo;>;"; | 155 | final String answer = "Ljava/lang/String;"; |
| 222 | assertThat(Type.parseFirst("LFoo<LFoo;>;"), is(answer)); | 156 | assertThat(Type.parseFirst("Ljava/lang/String;"), is(answer)); |
| 223 | assertThat(Type.parseFirst("LFoo<LFoo;>;I"), is(answer)); | 157 | assertThat(Type.parseFirst("Ljava/lang/String;I"), is(answer)); |
| 224 | assertThat(Type.parseFirst("LFoo<LFoo;>;JZ"), is(answer)); | 158 | assertThat(Type.parseFirst("Ljava/lang/String;JZ"), is(answer)); |
| 225 | assertThat(Type.parseFirst("LFoo<LFoo;>;[I"), is(answer)); | 159 | assertThat(Type.parseFirst("Ljava/lang/String;[I"), is(answer)); |
| 226 | assertThat(Type.parseFirst("LFoo<LFoo;>;LFoo;"), is(answer)); | 160 | assertThat(Type.parseFirst("Ljava/lang/String;LFoo;"), is(answer)); |
| 227 | assertThat(Type.parseFirst("LFoo<LFoo;>;[LFoo;"), is(answer)); | 161 | assertThat(Type.parseFirst("Ljava/lang/String;[LFoo;"), is(answer)); |
| 228 | } | ||
| 229 | { | ||
| 230 | final String answer = "LFoo<LFoo;,LBar;>;"; | ||
| 231 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;"), is(answer)); | ||
| 232 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;I"), is(answer)); | ||
| 233 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;JZ"), is(answer)); | ||
| 234 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;[I"), is(answer)); | ||
| 235 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;LFoo;"), is(answer)); | ||
| 236 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;[LFoo;"), is(answer)); | ||
| 237 | } | 162 | } |
| 238 | } | 163 | } |
| 239 | 164 | ||
| 240 | @Test | 165 | @Test |
| 241 | public void parseTemplate() { | ||
| 242 | final String answer = "TFoo;"; | ||
| 243 | assertThat(Type.parseFirst("TFoo;"), is(answer)); | ||
| 244 | assertThat(Type.parseFirst("TFoo;I"), is(answer)); | ||
| 245 | assertThat(Type.parseFirst("TFoo;JZ"), is(answer)); | ||
| 246 | assertThat(Type.parseFirst("TFoo;[I"), is(answer)); | ||
| 247 | assertThat(Type.parseFirst("TFoo;LFoo;"), is(answer)); | ||
| 248 | assertThat(Type.parseFirst("TFoo;[LFoo;"), is(answer)); | ||
| 249 | } | ||
| 250 | |||
| 251 | @Test | ||
| 252 | public void parseArray() { | 166 | public void parseArray() { |
| 253 | { | 167 | { |
| 254 | final String answer = "[I"; | 168 | final String answer = "[I"; |
| @@ -290,9 +204,6 @@ public class TestType { | |||
| 290 | assertThat(new Type("[I"), is(new Type("[I"))); | 204 | assertThat(new Type("[I"), is(new Type("[I"))); |
| 291 | assertThat(new Type("[[[I"), is(new Type("[[[I"))); | 205 | assertThat(new Type("[[[I"), is(new Type("[[[I"))); |
| 292 | assertThat(new Type("[LFoo;"), is(new Type("[LFoo;"))); | 206 | assertThat(new Type("[LFoo;"), is(new Type("[LFoo;"))); |
| 293 | assertThat(new Type("LFoo<LBar;>;"), is(new Type("LFoo<LBar;>;"))); | ||
| 294 | assertThat(new Type("LFoo<LBar;>;"), is(new Type("LFoo<LCow;>;"))); | ||
| 295 | assertThat(new Type("TFoo;"), is(new Type("TFoo;"))); | ||
| 296 | 207 | ||
| 297 | assertThat(new Type("V"), is(not(new Type("I")))); | 208 | assertThat(new Type("V"), is(not(new Type("I")))); |
| 298 | assertThat(new Type("I"), is(not(new Type("J")))); | 209 | assertThat(new Type("I"), is(not(new Type("J")))); |
| @@ -302,7 +213,6 @@ public class TestType { | |||
| 302 | assertThat(new Type("[I"), is(not(new Type("[Z")))); | 213 | assertThat(new Type("[I"), is(not(new Type("[Z")))); |
| 303 | assertThat(new Type("[[[I"), is(not(new Type("[I")))); | 214 | assertThat(new Type("[[[I"), is(not(new Type("[I")))); |
| 304 | assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); | 215 | assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); |
| 305 | assertThat(new Type("TFoo;"), is(not(new Type("TBar;")))); | ||
| 306 | } | 216 | } |
| 307 | 217 | ||
| 308 | @Test | 218 | @Test |
| @@ -319,62 +229,5 @@ public class TestType { | |||
| 319 | assertThat(new Type("[I").toString(), is("[I")); | 229 | assertThat(new Type("[I").toString(), is("[I")); |
| 320 | assertThat(new Type("[[[I").toString(), is("[[[I")); | 230 | assertThat(new Type("[[[I").toString(), is("[[[I")); |
| 321 | assertThat(new Type("[LFoo;").toString(), is("[LFoo;")); | 231 | assertThat(new Type("[LFoo;").toString(), is("[LFoo;")); |
| 322 | assertThat(new Type("LFoo<LBar;>;").toString(), is("LFoo;")); | ||
| 323 | assertThat(new Type("LFoo<LCow;LCheese;>;").toString(), is("LFoo;")); | ||
| 324 | assertThat(new Type("LFoo<LPair<LCow;LCheese;>;>;").toString(), is("LFoo;")); | ||
| 325 | assertThat(new Type("TFoo;").toString(), is("TFoo;")); | ||
| 326 | } | ||
| 327 | |||
| 328 | private ParameterizedType ptype(String name) { | ||
| 329 | return new ParameterizedType(new Type(name)); | ||
| 330 | } | ||
| 331 | |||
| 332 | @Test | ||
| 333 | public void equalsWithParameters() { | ||
| 334 | assertThat(ptype("V"), is(ptype("V"))); | ||
| 335 | assertThat(ptype("Z"), is(ptype("Z"))); | ||
| 336 | assertThat(ptype("B"), is(ptype("B"))); | ||
| 337 | assertThat(ptype("C"), is(ptype("C"))); | ||
| 338 | assertThat(ptype("I"), is(ptype("I"))); | ||
| 339 | assertThat(ptype("J"), is(ptype("J"))); | ||
| 340 | assertThat(ptype("F"), is(ptype("F"))); | ||
| 341 | assertThat(ptype("D"), is(ptype("D"))); | ||
| 342 | assertThat(ptype("LFoo;"), is(ptype("LFoo;"))); | ||
| 343 | assertThat(ptype("[I"), is(ptype("[I"))); | ||
| 344 | assertThat(ptype("[[[I"), is(ptype("[[[I"))); | ||
| 345 | assertThat(ptype("[LFoo;"), is(ptype("[LFoo;"))); | ||
| 346 | assertThat(ptype("LFoo<LBar;>;"), is(ptype("LFoo<LBar;>;"))); | ||
| 347 | assertThat(ptype("TFoo;"), is(ptype("TFoo;"))); | ||
| 348 | |||
| 349 | assertThat(ptype("V"), is(not(ptype("I")))); | ||
| 350 | assertThat(ptype("I"), is(not(ptype("J")))); | ||
| 351 | assertThat(ptype("I"), is(not(ptype("LBar;")))); | ||
| 352 | assertThat(ptype("I"), is(not(ptype("[I")))); | ||
| 353 | assertThat(ptype("LFoo;"), is(not(ptype("LBar;")))); | ||
| 354 | assertThat(ptype("[I"), is(not(ptype("[Z")))); | ||
| 355 | assertThat(ptype("[[[I"), is(not(ptype("[I")))); | ||
| 356 | assertThat(ptype("[LFoo;"), is(not(ptype("[LBar;")))); | ||
| 357 | assertThat(ptype("LFoo<LBar;>;"), is(not(ptype("LFoo<LCow;>;")))); | ||
| 358 | assertThat(ptype("TFoo;"), is(not(ptype("TBar;")))); | ||
| 359 | } | ||
| 360 | |||
| 361 | @Test | ||
| 362 | public void testToStringWithParams() { | ||
| 363 | assertThat(ptype("V").toString(), is("V")); | ||
| 364 | assertThat(ptype("Z").toString(), is("Z")); | ||
| 365 | assertThat(ptype("B").toString(), is("B")); | ||
| 366 | assertThat(ptype("C").toString(), is("C")); | ||
| 367 | assertThat(ptype("I").toString(), is("I")); | ||
| 368 | assertThat(ptype("J").toString(), is("J")); | ||
| 369 | assertThat(ptype("F").toString(), is("F")); | ||
| 370 | assertThat(ptype("D").toString(), is("D")); | ||
| 371 | assertThat(ptype("LFoo;").toString(), is("LFoo;")); | ||
| 372 | assertThat(ptype("[I").toString(), is("[I")); | ||
| 373 | assertThat(ptype("[[[I").toString(), is("[[[I")); | ||
| 374 | assertThat(ptype("[LFoo;").toString(), is("[LFoo;")); | ||
| 375 | assertThat(ptype("LFoo<LBar;>;").toString(), is("LFoo<LBar;>;")); | ||
| 376 | assertThat(ptype("LFoo<LCow;LCheese;>;").toString(), is("LFoo<LCow;LCheese;>;")); | ||
| 377 | assertThat(ptype("LFoo<LPair<LCow;LCheese;>;>;").toString(), is("LFoo<LPair<LCow;LCheese;>;>;")); | ||
| 378 | assertThat(ptype("TFoo;").toString(), is("TFoo;")); | ||
| 379 | } | 232 | } |
| 380 | } | 233 | } |