summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/mapping/MethodMapping.java
diff options
context:
space:
mode:
authorGravatar Thog2017-03-08 08:17:04 +0100
committerGravatar Thog2017-03-08 08:17:04 +0100
commit6e464ea251cab63c776ece0b2a356f1498ffa294 (patch)
tree5ed30c03f5ac4cd2d6877874f5ede576049954f7 /src/main/java/cuchaz/enigma/mapping/MethodMapping.java
parentDrop unix case style and implement hashCode when equals is overrided (diff)
downloadenigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.gz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.xz
enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.zip
Follow Fabric guidelines
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MethodMapping.java')
-rw-r--r--src/main/java/cuchaz/enigma/mapping/MethodMapping.java393
1 files changed, 194 insertions, 199 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java
index e0aeea2..1524ce6 100644
--- a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java
+++ b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java
@@ -8,211 +8,206 @@
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.Maps; 14import com.google.common.collect.Maps;
14
15import java.util.Map;
16
17import cuchaz.enigma.throwables.IllegalNameException; 15import cuchaz.enigma.throwables.IllegalNameException;
18import cuchaz.enigma.throwables.MappingConflict; 16import cuchaz.enigma.throwables.MappingConflict;
19 17
18import java.util.Map;
19
20public class MethodMapping implements Comparable<MethodMapping>, MemberMapping<BehaviorEntry> { 20public class MethodMapping implements Comparable<MethodMapping>, MemberMapping<BehaviorEntry> {
21 21
22 private String obfName; 22 private String obfName;
23 private String deobfName; 23 private String deobfName;
24 private Signature obfSignature; 24 private Signature obfSignature;
25 private Map<Integer, ArgumentMapping> arguments; 25 private Map<Integer, ArgumentMapping> arguments;
26 private Mappings.EntryModifier modifier; 26 private Mappings.EntryModifier modifier;
27 27
28 public MethodMapping(String obfName, Signature obfSignature) { 28 public MethodMapping(String obfName, Signature obfSignature) {
29 this(obfName, obfSignature, null,Mappings.EntryModifier.UNCHANGED); 29 this(obfName, obfSignature, null, Mappings.EntryModifier.UNCHANGED);
30 } 30 }
31 31
32 public MethodMapping(String obfName, Signature obfSignature, String deobfName) { 32 public MethodMapping(String obfName, Signature obfSignature, String deobfName) {
33 this(obfName, obfSignature, deobfName, Mappings.EntryModifier.UNCHANGED); 33 this(obfName, obfSignature, deobfName, Mappings.EntryModifier.UNCHANGED);
34 } 34 }
35 35
36 public MethodMapping(String obfName, Signature obfSignature, String deobfName, Mappings.EntryModifier modifier) { 36 public MethodMapping(String obfName, Signature obfSignature, String deobfName, Mappings.EntryModifier modifier) {
37 if (obfName == null) { 37 if (obfName == null) {
38 throw new IllegalArgumentException("obf name cannot be null!"); 38 throw new IllegalArgumentException("obf name cannot be null!");
39 } 39 }
40 if (obfSignature == null) { 40 if (obfSignature == null) {
41 throw new IllegalArgumentException("obf signature cannot be null!"); 41 throw new IllegalArgumentException("obf signature cannot be null!");
42 } 42 }
43 this.obfName = obfName; 43 this.obfName = obfName;
44 this.deobfName = NameValidator.validateMethodName(deobfName); 44 this.deobfName = NameValidator.validateMethodName(deobfName);
45 this.obfSignature = obfSignature; 45 this.obfSignature = obfSignature;
46 this.arguments = Maps.newTreeMap(); 46 this.arguments = Maps.newTreeMap();
47 this.modifier = modifier; 47 this.modifier = modifier;
48 } 48 }
49 49
50 public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) { 50 public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) {
51 this.obfName = other.obfName; 51 this.obfName = other.obfName;
52 this.deobfName = other.deobfName; 52 this.deobfName = other.deobfName;
53 this.modifier = other.modifier; 53 this.modifier = other.modifier;
54 this.obfSignature = new Signature(other.obfSignature, obfClassNameReplacer); 54 this.obfSignature = new Signature(other.obfSignature, obfClassNameReplacer);
55 this.arguments = Maps.newTreeMap(); 55 this.arguments = Maps.newTreeMap();
56 for (Map.Entry<Integer,ArgumentMapping> entry : other.arguments.entrySet()) { 56 for (Map.Entry<Integer, ArgumentMapping> entry : other.arguments.entrySet()) {
57 this.arguments.put(entry.getKey(), new ArgumentMapping(entry.getValue())); 57 this.arguments.put(entry.getKey(), new ArgumentMapping(entry.getValue()));
58 } 58 }
59 } 59 }
60 60
61 @Override 61 @Override
62 public String getObfName() { 62 public String getObfName() {
63 return this.obfName; 63 return this.obfName;
64 } 64 }
65 65
66 public String getDeobfName() { 66 public void setObfName(String name) {
67 return this.deobfName; 67 try {
68 } 68 NameValidator.validateMethodName(name);
69 69 } catch (IllegalNameException ex) {
70 public void setDeobfName(String val) { 70 // Invalid name, damn obfuscation! Map to a deob name with another name to avoid issues
71 this.deobfName = NameValidator.validateMethodName(val); 71 if (this.deobfName == null) {
72 } 72 System.err.println("WARNING: " + name + " is conflicting, auto deobfuscate to " + (name + "_auto_deob"));
73 73 setDeobfName(name + "_auto_deob");
74 public Signature getObfSignature() { 74 }
75 return this.obfSignature; 75 }
76 } 76 this.obfName = name;
77 77 }
78 public void setObfName(String name) { 78
79 try 79 public String getDeobfName() {
80 { 80 return this.deobfName;
81 NameValidator.validateMethodName(name); 81 }
82 } catch (IllegalNameException ex) 82
83 { 83 public void setDeobfName(String val) {
84 // Invalid name, damn obfuscation! Map to a deob name with another name to avoid issues 84 this.deobfName = NameValidator.validateMethodName(val);
85 if (this.deobfName == null) 85 }
86 { 86
87 System.err.println("WARNING: " + name + " is conflicting, auto deobfuscate to " + (name + "_auto_deob")); 87 public Signature getObfSignature() {
88 setDeobfName(name + "_auto_deob"); 88 return this.obfSignature;
89 } 89 }
90 } 90
91 this.obfName = name; 91 public void setObfSignature(Signature val) {
92 } 92 this.obfSignature = val;
93 93 }
94 public void setObfSignature(Signature val) { 94
95 this.obfSignature = val; 95 public Iterable<ArgumentMapping> arguments() {
96 } 96 return this.arguments.values();
97 97 }
98 public Iterable<ArgumentMapping> arguments() { 98
99 return this.arguments.values(); 99 public void addArgumentMapping(ArgumentMapping argumentMapping) throws MappingConflict {
100 } 100 if (this.arguments.containsKey(argumentMapping.getIndex())) {
101 101 throw new MappingConflict("argument", argumentMapping.getName(), this.arguments.get(argumentMapping.getIndex()).getName());
102 public void addArgumentMapping(ArgumentMapping argumentMapping) throws MappingConflict { 102 }
103 if (this.arguments.containsKey(argumentMapping.getIndex())) { 103 this.arguments.put(argumentMapping.getIndex(), argumentMapping);
104 throw new MappingConflict("argument", argumentMapping.getName(), this.arguments.get(argumentMapping.getIndex()).getName()); 104 }
105 } 105
106 this.arguments.put(argumentMapping.getIndex(), argumentMapping); 106 public String getObfArgumentName(int index) {
107 } 107 ArgumentMapping argumentMapping = this.arguments.get(index);
108 108 if (argumentMapping != null) {
109 public String getObfArgumentName(int index) { 109 return argumentMapping.getName();
110 ArgumentMapping argumentMapping = this.arguments.get(index); 110 }
111 if (argumentMapping != null) { 111
112 return argumentMapping.getName(); 112 return null;
113 } 113 }
114 114
115 return null; 115 public String getDeobfArgumentName(int index) {
116 } 116 ArgumentMapping argumentMapping = this.arguments.get(index);
117 117 if (argumentMapping != null) {
118 public String getDeobfArgumentName(int index) { 118 return argumentMapping.getName();
119 ArgumentMapping argumentMapping = this.arguments.get(index); 119 }
120 if (argumentMapping != null) { 120
121 return argumentMapping.getName(); 121 return null;
122 } 122 }
123 123
124 return null; 124 public void setArgumentName(int index, String name) {
125 } 125 ArgumentMapping argumentMapping = this.arguments.get(index);
126 126 if (argumentMapping == null) {
127 public void setArgumentName(int index, String name) { 127 argumentMapping = new ArgumentMapping(index, name);
128 ArgumentMapping argumentMapping = this.arguments.get(index); 128 boolean wasAdded = this.arguments.put(index, argumentMapping) == null;
129 if (argumentMapping == null) { 129 assert (wasAdded);
130 argumentMapping = new ArgumentMapping(index, name); 130 } else {
131 boolean wasAdded = this.arguments.put(index, argumentMapping) == null; 131 argumentMapping.setName(name);
132 assert (wasAdded); 132 }
133 } else { 133 }
134 argumentMapping.setName(name); 134
135 } 135 public void removeArgumentName(int index) {
136 } 136 boolean wasRemoved = this.arguments.remove(index) != null;
137 137 assert (wasRemoved);
138 public void removeArgumentName(int index) { 138 }
139 boolean wasRemoved = this.arguments.remove(index) != null; 139
140 assert (wasRemoved); 140 @Override
141 } 141 public String toString() {
142 142 StringBuilder buf = new StringBuilder();
143 @Override 143 buf.append("\t");
144 public String toString() { 144 buf.append(this.obfName);
145 StringBuilder buf = new StringBuilder(); 145 buf.append(" <-> ");
146 buf.append("\t"); 146 buf.append(this.deobfName);
147 buf.append(this.obfName); 147 buf.append("\n");
148 buf.append(" <-> "); 148 buf.append("\t");
149 buf.append(this.deobfName); 149 buf.append(this.obfSignature);
150 buf.append("\n"); 150 buf.append("\n");
151 buf.append("\t"); 151 buf.append("\tArguments:\n");
152 buf.append(this.obfSignature); 152 for (ArgumentMapping argumentMapping : this.arguments.values()) {
153 buf.append("\n"); 153 buf.append("\t\t");
154 buf.append("\tArguments:\n"); 154 buf.append(argumentMapping.getIndex());
155 for (ArgumentMapping argumentMapping : this.arguments.values()) { 155 buf.append(" -> ");
156 buf.append("\t\t"); 156 buf.append(argumentMapping.getName());
157 buf.append(argumentMapping.getIndex()); 157 buf.append("\n");
158 buf.append(" -> "); 158 }
159 buf.append(argumentMapping.getName()); 159 return buf.toString();
160 buf.append("\n"); 160 }
161 } 161
162 return buf.toString(); 162 @Override
163 } 163 public int compareTo(MethodMapping other) {
164 164 return (this.obfName + this.obfSignature).compareTo(other.obfName + other.obfSignature);
165 @Override 165 }
166 public int compareTo(MethodMapping other) { 166
167 return (this.obfName + this.obfSignature).compareTo(other.obfName + other.obfSignature); 167 public boolean containsArgument(String name) {
168 } 168 for (ArgumentMapping argumentMapping : this.arguments.values()) {
169 169 if (argumentMapping.getName().equals(name)) {
170 public boolean containsArgument(String name) { 170 return true;
171 for (ArgumentMapping argumentMapping : this.arguments.values()) { 171 }
172 if (argumentMapping.getName().equals(name)) { 172 }
173 return true; 173 return false;
174 } 174 }
175 } 175
176 return false; 176 public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) {
177 } 177 // rename obf classes in the signature
178 178 Signature newSignature = new Signature(this.obfSignature, className ->
179 public boolean renameObfClass(final String oldObfClassName, final String newObfClassName) { 179 {
180 // rename obf classes in the signature 180 if (className.equals(oldObfClassName)) {
181 Signature newSignature = new Signature(this.obfSignature, className -> 181 return newObfClassName;
182 { 182 }
183 if (className.equals(oldObfClassName)) { 183 return null;
184 return newObfClassName; 184 });
185 } 185
186 return null; 186 if (!newSignature.equals(this.obfSignature)) {
187 }); 187 this.obfSignature = newSignature;
188 188 return true;
189 if (!newSignature.equals(this.obfSignature)) { 189 }
190 this.obfSignature = newSignature; 190 return false;
191 return true; 191 }
192 } 192
193 return false; 193 public boolean isConstructor() {
194 } 194 return this.obfName.startsWith("<");
195 195 }
196 public boolean isConstructor() { 196
197 return this.obfName.startsWith("<"); 197 @Override
198 } 198 public BehaviorEntry getObfEntry(ClassEntry classEntry) {
199 199 if (isConstructor()) {
200 @Override 200 return new ConstructorEntry(classEntry, this.obfSignature);
201 public BehaviorEntry getObfEntry(ClassEntry classEntry) { 201 } else {
202 if (isConstructor()) { 202 return new MethodEntry(classEntry, this.obfName, this.obfSignature);
203 return new ConstructorEntry(classEntry, this.obfSignature); 203 }
204 } else { 204 }
205 return new MethodEntry(classEntry, this.obfName, this.obfSignature); 205
206 } 206 public Mappings.EntryModifier getModifier() {
207 } 207 return modifier;
208 208 }
209 public Mappings.EntryModifier getModifier() 209
210 { 210 public void setModifier(Mappings.EntryModifier modifier) {
211 return modifier; 211 this.modifier = modifier;
212 } 212 }
213
214 public void setModifier(Mappings.EntryModifier modifier)
215 {
216 this.modifier = modifier;
217 }
218} 213}