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.java106
1 files changed, 0 insertions, 106 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/Signature.java b/src/main/java/cuchaz/enigma/mapping/Signature.java
deleted file mode 100644
index 78130d6..0000000
--- a/src/main/java/cuchaz/enigma/mapping/Signature.java
+++ /dev/null
@@ -1,106 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma.mapping;
13
14import com.google.common.collect.Lists;
15import cuchaz.enigma.utils.Utils;
16
17import java.util.List;
18
19public class Signature {
20
21 private List<Type> argumentTypes;
22 private Type returnType;
23
24 public Signature(String signature) {
25 try {
26 this.argumentTypes = Lists.newArrayList();
27 int i = 0;
28 while (i < signature.length()) {
29 char c = signature.charAt(i);
30 if (c == '(') {
31 assert (this.argumentTypes.isEmpty());
32 assert (this.returnType == null);
33 i++;
34 } else if (c == ')') {
35 i++;
36 break;
37 } else {
38 String type = Type.parseFirst(signature.substring(i));
39 this.argumentTypes.add(new Type(type));
40 i += type.length();
41 }
42 }
43 this.returnType = new Type(Type.parseFirst(signature.substring(i)));
44 } catch (Exception ex) {
45 throw new IllegalArgumentException("Unable to parse signature: " + signature, ex);
46 }
47 }
48
49 public Signature(Signature other, ClassNameReplacer replacer) {
50 this.argumentTypes = Lists.newArrayList(other.argumentTypes);
51 for (int i = 0; i < this.argumentTypes.size(); i++) {
52 this.argumentTypes.set(i, new Type(this.argumentTypes.get(i), replacer));
53 }
54 this.returnType = new Type(other.returnType, replacer);
55 }
56
57 public List<Type> getArgumentTypes() {
58 return this.argumentTypes;
59 }
60
61 public Type getReturnType() {
62 return this.returnType;
63 }
64
65 @Override
66 public String toString() {
67 StringBuilder buf = new StringBuilder();
68 buf.append("(");
69 for (Type type : this.argumentTypes) {
70 buf.append(type);
71 }
72 buf.append(")");
73 buf.append(this.returnType);
74 return buf.toString();
75 }
76
77 public Iterable<Type> types() {
78 List<Type> types = Lists.newArrayList();
79 types.addAll(this.argumentTypes);
80 types.add(this.returnType);
81 return types;
82 }
83
84 @Override
85 public boolean equals(Object other) {
86 return other instanceof Signature && equals((Signature) other);
87 }
88
89 public boolean equals(Signature other) {
90 return this.argumentTypes.equals(other.argumentTypes) && this.returnType.equals(other.returnType);
91 }
92
93 @Override
94 public int hashCode() {
95 return Utils.combineHashesOrdered(this.argumentTypes.hashCode(), this.returnType.hashCode());
96 }
97
98 public boolean hasClass(ClassEntry classEntry) {
99 for (Type type : types()) {
100 if (type.hasClass() && type.getClassEntry().equals(classEntry)) {
101 return true;
102 }
103 }
104 return false;
105 }
106}