diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/ClassMapping.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/ClassMapping.java | 71 |
1 files changed, 60 insertions, 11 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index 923c8ec..017a5b9 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -30,12 +30,20 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 30 | private Map<String, MethodMapping> m_methodsByObf; | 30 | private Map<String, MethodMapping> m_methodsByObf; |
| 31 | private Map<String, MethodMapping> m_methodsByDeobf; | 31 | private Map<String, MethodMapping> m_methodsByDeobf; |
| 32 | private boolean isDirty; | 32 | private boolean isDirty; |
| 33 | private Mappings.EntryModifier modifier; | ||
| 33 | 34 | ||
| 34 | public ClassMapping(String obfFullName) { | 35 | public ClassMapping(String obfFullName) |
| 35 | this(obfFullName, null); | 36 | { |
| 37 | this(obfFullName, null, Mappings.EntryModifier.UNCHANGED); | ||
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | public ClassMapping(String obfFullName, String deobfName) { | 40 | public ClassMapping(String obfFullName, String deobfName) |
| 41 | { | ||
| 42 | this(obfFullName, deobfName, Mappings.EntryModifier.UNCHANGED); | ||
| 43 | } | ||
| 44 | |||
| 45 | public ClassMapping(String obfFullName, String deobfName, Mappings.EntryModifier modifier) | ||
| 46 | { | ||
| 39 | m_obfFullName = obfFullName; | 47 | m_obfFullName = obfFullName; |
| 40 | ClassEntry classEntry = new ClassEntry(obfFullName); | 48 | ClassEntry classEntry = new ClassEntry(obfFullName); |
| 41 | m_obfSimpleName = classEntry.isInnerClass() ? classEntry.getInnermostClassName() : classEntry.getSimpleName(); | 49 | m_obfSimpleName = classEntry.isInnerClass() ? classEntry.getInnermostClassName() : classEntry.getSimpleName(); |
| @@ -48,6 +56,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 48 | m_methodsByObf = Maps.newHashMap(); | 56 | m_methodsByObf = Maps.newHashMap(); |
| 49 | m_methodsByDeobf = Maps.newHashMap(); | 57 | m_methodsByDeobf = Maps.newHashMap(); |
| 50 | isDirty = true; | 58 | isDirty = true; |
| 59 | this.modifier = modifier; | ||
| 51 | } | 60 | } |
| 52 | 61 | ||
| 53 | public String getObfFullName() { | 62 | public String getObfFullName() { |
| @@ -186,15 +195,16 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 186 | if (m_fieldsByObf.containsKey(obfKey)) { | 195 | if (m_fieldsByObf.containsKey(obfKey)) { |
| 187 | throw new Error("Already have mapping for " + m_obfFullName + "." + obfKey); | 196 | throw new Error("Already have mapping for " + m_obfFullName + "." + obfKey); |
| 188 | } | 197 | } |
| 189 | String deobfKey = getFieldKey(fieldMapping.getDeobfName(), fieldMapping.getObfType()); | 198 | if (fieldMapping.getDeobfName() != null) { |
| 190 | if (m_fieldsByDeobf.containsKey(deobfKey)) { | 199 | String deobfKey = getFieldKey(fieldMapping.getDeobfName(), fieldMapping.getObfType()); |
| 191 | throw new Error("Already have mapping for " + m_deobfName + "." + deobfKey); | 200 | if (m_fieldsByDeobf.containsKey(deobfKey)) { |
| 201 | throw new Error("Already have mapping for " + m_deobfName + "." + deobfKey); | ||
| 202 | } | ||
| 203 | boolean deobfWasAdded = m_fieldsByDeobf.put(deobfKey, fieldMapping) == null; | ||
| 204 | assert (deobfWasAdded); | ||
| 192 | } | 205 | } |
| 193 | boolean obfWasAdded = m_fieldsByObf.put(obfKey, fieldMapping) == null; | 206 | boolean obfWasAdded = m_fieldsByObf.put(obfKey, fieldMapping) == null; |
| 194 | assert (obfWasAdded); | 207 | assert (obfWasAdded); |
| 195 | boolean deobfWasAdded = m_fieldsByDeobf.put(deobfKey, fieldMapping) == null; | ||
| 196 | assert (deobfWasAdded); | ||
| 197 | assert (m_fieldsByObf.size() == m_fieldsByDeobf.size()); | ||
| 198 | this.isDirty = true; | 208 | this.isDirty = true; |
| 199 | } | 209 | } |
| 200 | 210 | ||
| @@ -242,12 +252,11 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 242 | return name + ":" + type; | 252 | return name + ":" + type; |
| 243 | } | 253 | } |
| 244 | 254 | ||
| 245 | |||
| 246 | public void setFieldName(String obfName, Type obfType, String deobfName) { | 255 | public void setFieldName(String obfName, Type obfType, String deobfName) { |
| 247 | assert (deobfName != null); | 256 | assert (deobfName != null); |
| 248 | FieldMapping fieldMapping = m_fieldsByObf.get(getFieldKey(obfName, obfType)); | 257 | FieldMapping fieldMapping = m_fieldsByObf.get(getFieldKey(obfName, obfType)); |
| 249 | if (fieldMapping == null) { | 258 | if (fieldMapping == null) { |
| 250 | fieldMapping = new FieldMapping(obfName, obfType, deobfName); | 259 | fieldMapping = new FieldMapping(obfName, obfType, deobfName, Mappings.EntryModifier.UNCHANGED); |
| 251 | boolean obfWasAdded = m_fieldsByObf.put(getFieldKey(obfName, obfType), fieldMapping) == null; | 260 | boolean obfWasAdded = m_fieldsByObf.put(getFieldKey(obfName, obfType), fieldMapping) == null; |
| 252 | assert (obfWasAdded); | 261 | assert (obfWasAdded); |
| 253 | } else { | 262 | } else { |
| @@ -492,4 +501,44 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 492 | { | 501 | { |
| 493 | this.isDirty = false; | 502 | this.isDirty = false; |
| 494 | } | 503 | } |
| 504 | |||
| 505 | public void setModifier(Mappings.EntryModifier modifier) | ||
| 506 | { | ||
| 507 | if (this.modifier != modifier) | ||
| 508 | this.isDirty = true; | ||
| 509 | this.modifier = modifier; | ||
| 510 | } | ||
| 511 | |||
| 512 | public Mappings.EntryModifier getModifier() | ||
| 513 | { | ||
| 514 | return modifier; | ||
| 515 | } | ||
| 516 | |||
| 517 | public void setFieldModifier(String obfName, Type obfType, Mappings.EntryModifier modifier) { | ||
| 518 | FieldMapping fieldMapping = m_fieldsByObf.get(getFieldKey(obfName, obfType)); | ||
| 519 | if (fieldMapping == null) { | ||
| 520 | fieldMapping = new FieldMapping(obfName, obfType, null, Mappings.EntryModifier.UNCHANGED); | ||
| 521 | m_fieldsByObf.put(getFieldKey(obfName, obfType), fieldMapping); | ||
| 522 | } | ||
| 523 | |||
| 524 | if (fieldMapping.getModifier() != modifier) | ||
| 525 | { | ||
| 526 | fieldMapping.setModifier(modifier); | ||
| 527 | this.isDirty = true; | ||
| 528 | } | ||
| 529 | } | ||
| 530 | |||
| 531 | public void setMethodModifier(String obfName, Signature sig, Mappings.EntryModifier modifier) { | ||
| 532 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfName, sig)); | ||
| 533 | if (methodMapping == null) { | ||
| 534 | methodMapping = new MethodMapping(obfName, sig, null, Mappings.EntryModifier.UNCHANGED); | ||
| 535 | m_methodsByObf.put(getMethodKey(obfName, sig), methodMapping); | ||
| 536 | } | ||
| 537 | |||
| 538 | if (methodMapping.getModifier() != modifier) | ||
| 539 | { | ||
| 540 | methodMapping.setModifier(modifier); | ||
| 541 | this.isDirty = true; | ||
| 542 | } | ||
| 543 | } | ||
| 495 | } | 544 | } |