summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/Signature.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/Signature.java')
-rw-r--r--src/main/java/cuchaz/enigma/mapping/Signature.java154
1 files changed, 77 insertions, 77 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/Signature.java b/src/main/java/cuchaz/enigma/mapping/Signature.java
index f30b606..78130d6 100644
--- a/src/main/java/cuchaz/enigma/mapping/Signature.java
+++ b/src/main/java/cuchaz/enigma/mapping/Signature.java
@@ -8,99 +8,99 @@
8 * Contributors: 8 * Contributors:
9 * Jeff Martin - initial API and implementation 9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/ 10 ******************************************************************************/
11
11package cuchaz.enigma.mapping; 12package cuchaz.enigma.mapping;
12 13
13import com.google.common.collect.Lists; 14import com.google.common.collect.Lists;
15import cuchaz.enigma.utils.Utils;
14 16
15import java.util.List; 17import java.util.List;
16 18
17import cuchaz.enigma.utils.Utils;
18
19public class Signature { 19public class Signature {
20 20
21 private List<Type> argumentTypes; 21 private List<Type> argumentTypes;
22 private Type returnType; 22 private Type returnType;
23 23
24 public Signature(String signature) { 24 public Signature(String signature) {
25 try { 25 try {
26 this.argumentTypes = Lists.newArrayList(); 26 this.argumentTypes = Lists.newArrayList();
27 int i = 0; 27 int i = 0;
28 while (i < signature.length()) { 28 while (i < signature.length()) {
29 char c = signature.charAt(i); 29 char c = signature.charAt(i);
30 if (c == '(') { 30 if (c == '(') {
31 assert (this.argumentTypes.isEmpty()); 31 assert (this.argumentTypes.isEmpty());
32 assert (this.returnType == null); 32 assert (this.returnType == null);
33 i++; 33 i++;
34 } else if (c == ')') { 34 } else if (c == ')') {
35 i++; 35 i++;
36 break; 36 break;
37 } else { 37 } else {
38 String type = Type.parseFirst(signature.substring(i)); 38 String type = Type.parseFirst(signature.substring(i));
39 this.argumentTypes.add(new Type(type)); 39 this.argumentTypes.add(new Type(type));
40 i += type.length(); 40 i += type.length();
41 } 41 }
42 } 42 }
43 this.returnType = new Type(Type.parseFirst(signature.substring(i))); 43 this.returnType = new Type(Type.parseFirst(signature.substring(i)));
44 } catch (Exception ex) { 44 } catch (Exception ex) {
45 throw new IllegalArgumentException("Unable to parse signature: " + signature, ex); 45 throw new IllegalArgumentException("Unable to parse signature: " + signature, ex);
46 } 46 }
47 } 47 }
48 48
49 public Signature(Signature other, ClassNameReplacer replacer) { 49 public Signature(Signature other, ClassNameReplacer replacer) {
50 this.argumentTypes = Lists.newArrayList(other.argumentTypes); 50 this.argumentTypes = Lists.newArrayList(other.argumentTypes);
51 for (int i = 0; i < this.argumentTypes.size(); i++) { 51 for (int i = 0; i < this.argumentTypes.size(); i++) {
52 this.argumentTypes.set(i, new Type(this.argumentTypes.get(i), replacer)); 52 this.argumentTypes.set(i, new Type(this.argumentTypes.get(i), replacer));
53 } 53 }
54 this.returnType = new Type(other.returnType, replacer); 54 this.returnType = new Type(other.returnType, replacer);
55 } 55 }
56 56
57 public List<Type> getArgumentTypes() { 57 public List<Type> getArgumentTypes() {
58 return this.argumentTypes; 58 return this.argumentTypes;
59 } 59 }
60 60
61 public Type getReturnType() { 61 public Type getReturnType() {
62 return this.returnType; 62 return this.returnType;
63 } 63 }
64 64
65 @Override 65 @Override
66 public String toString() { 66 public String toString() {
67 StringBuilder buf = new StringBuilder(); 67 StringBuilder buf = new StringBuilder();
68 buf.append("("); 68 buf.append("(");
69 for (Type type : this.argumentTypes) { 69 for (Type type : this.argumentTypes) {
70 buf.append(type.toString()); 70 buf.append(type);
71 } 71 }
72 buf.append(")"); 72 buf.append(")");
73 buf.append(this.returnType.toString()); 73 buf.append(this.returnType);
74 return buf.toString(); 74 return buf.toString();
75 } 75 }
76 76
77 public Iterable<Type> types() { 77 public Iterable<Type> types() {
78 List<Type> types = Lists.newArrayList(); 78 List<Type> types = Lists.newArrayList();
79 types.addAll(this.argumentTypes); 79 types.addAll(this.argumentTypes);
80 types.add(this.returnType); 80 types.add(this.returnType);
81 return types; 81 return types;
82 } 82 }
83 83
84 @Override 84 @Override
85 public boolean equals(Object other) { 85 public boolean equals(Object other) {
86 return other instanceof Signature && equals((Signature) other); 86 return other instanceof Signature && equals((Signature) other);
87 } 87 }
88 88
89 public boolean equals(Signature other) { 89 public boolean equals(Signature other) {
90 return this.argumentTypes.equals(other.argumentTypes) && this.returnType.equals(other.returnType); 90 return this.argumentTypes.equals(other.argumentTypes) && this.returnType.equals(other.returnType);
91 } 91 }
92 92
93 @Override 93 @Override
94 public int hashCode() { 94 public int hashCode() {
95 return Utils.combineHashesOrdered(this.argumentTypes.hashCode(), this.returnType.hashCode()); 95 return Utils.combineHashesOrdered(this.argumentTypes.hashCode(), this.returnType.hashCode());
96 } 96 }
97 97
98 public boolean hasClass(ClassEntry classEntry) { 98 public boolean hasClass(ClassEntry classEntry) {
99 for (Type type : types()) { 99 for (Type type : types()) {
100 if (type.hasClass() && type.getClassEntry().equals(classEntry)) { 100 if (type.hasClass() && type.getClassEntry().equals(classEntry)) {
101 return true; 101 return true;
102 } 102 }
103 } 103 }
104 return false; 104 return false;
105 } 105 }
106} 106}