diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping')
8 files changed, 189 insertions, 26 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 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/FieldMapping.java b/src/main/java/cuchaz/enigma/mapping/FieldMapping.java index 1b59660..e75485c 100644 --- a/src/main/java/cuchaz/enigma/mapping/FieldMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/FieldMapping.java | |||
| @@ -15,16 +15,19 @@ public class FieldMapping implements Comparable<FieldMapping>, MemberMapping<Fie | |||
| 15 | private String obfName; | 15 | private String obfName; |
| 16 | private String deobfName; | 16 | private String deobfName; |
| 17 | private Type obfType; | 17 | private Type obfType; |
| 18 | private Mappings.EntryModifier modifier; | ||
| 18 | 19 | ||
| 19 | public FieldMapping(String obfName, Type obfType, String deobfName) { | 20 | public FieldMapping(String obfName, Type obfType, String deobfName, Mappings.EntryModifier modifier) { |
| 20 | this.obfName = obfName; | 21 | this.obfName = obfName; |
| 21 | this.deobfName = NameValidator.validateFieldName(deobfName); | 22 | this.deobfName = NameValidator.validateFieldName(deobfName); |
| 22 | this.obfType = obfType; | 23 | this.obfType = obfType; |
| 24 | this.modifier = modifier; | ||
| 23 | } | 25 | } |
| 24 | 26 | ||
| 25 | public FieldMapping(FieldMapping other, ClassNameReplacer obfClassNameReplacer) { | 27 | public FieldMapping(FieldMapping other, ClassNameReplacer obfClassNameReplacer) { |
| 26 | this.obfName = other.obfName; | 28 | this.obfName = other.obfName; |
| 27 | this.deobfName = other.deobfName; | 29 | this.deobfName = other.deobfName; |
| 30 | this.modifier = other.modifier; | ||
| 28 | this.obfType = new Type(other.obfType, obfClassNameReplacer); | 31 | this.obfType = new Type(other.obfType, obfClassNameReplacer); |
| 29 | } | 32 | } |
| 30 | 33 | ||
| @@ -58,6 +61,16 @@ public class FieldMapping implements Comparable<FieldMapping>, MemberMapping<Fie | |||
| 58 | this.obfType = val; | 61 | this.obfType = val; |
| 59 | } | 62 | } |
| 60 | 63 | ||
| 64 | public void setModifier(Mappings.EntryModifier modifier) | ||
| 65 | { | ||
| 66 | this.modifier = modifier; | ||
| 67 | } | ||
| 68 | |||
| 69 | public Mappings.EntryModifier getModifier() | ||
| 70 | { | ||
| 71 | return modifier; | ||
| 72 | } | ||
| 73 | |||
| 61 | @Override | 74 | @Override |
| 62 | public int compareTo(FieldMapping other) { | 75 | public int compareTo(FieldMapping other) { |
| 63 | return (this.obfName + this.obfType).compareTo(other.obfName + other.obfType); | 76 | return (this.obfName + this.obfType).compareTo(other.obfName + other.obfType); |
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java index 2166bb9..d493dcf 100644 --- a/src/main/java/cuchaz/enigma/mapping/Mappings.java +++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -240,4 +240,14 @@ public class Mappings { | |||
| 240 | { | 240 | { |
| 241 | ENIGMA_FILE, ENIGMA_DIRECTORY, SRG_FILE | 241 | ENIGMA_FILE, ENIGMA_DIRECTORY, SRG_FILE |
| 242 | } | 242 | } |
| 243 | |||
| 244 | public enum EntryModifier | ||
| 245 | { | ||
| 246 | UNCHANGED, PUBLIC, PROTECTED, PRIVATE; | ||
| 247 | |||
| 248 | public String getFormattedName() | ||
| 249 | { | ||
| 250 | return " ACC:" + super.toString(); | ||
| 251 | } | ||
| 252 | } | ||
| 243 | } | 253 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java index 93276a6..cdfed72 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java | |||
| @@ -135,21 +135,51 @@ public class MappingsEnigmaReader | |||
| 135 | private ClassMapping readClass(String[] parts, boolean makeSimple) { | 135 | private ClassMapping readClass(String[] parts, boolean makeSimple) { |
| 136 | if (parts.length == 2) { | 136 | if (parts.length == 2) { |
| 137 | return new ClassMapping(parts[1]); | 137 | return new ClassMapping(parts[1]); |
| 138 | } else { | 138 | } else if (parts.length == 3) { |
| 139 | return new ClassMapping(parts[1], parts[2]); | 139 | boolean access = parts[2].startsWith("ACC:"); |
| 140 | } | 140 | ClassMapping mapping; |
| 141 | if (access) | ||
| 142 | mapping = new ClassMapping(parts[1], null, Mappings.EntryModifier.valueOf(parts[2].substring(4))); | ||
| 143 | else | ||
| 144 | mapping = new ClassMapping(parts[1], parts[2]); | ||
| 145 | |||
| 146 | return mapping; | ||
| 147 | } else if (parts.length == 4) | ||
| 148 | return new ClassMapping(parts[1], parts[2], Mappings.EntryModifier.valueOf(parts[3].substring(4))); | ||
| 149 | return null; | ||
| 141 | } | 150 | } |
| 142 | 151 | ||
| 143 | /* TEMP */ | 152 | /* TEMP */ |
| 144 | protected FieldMapping readField(String[] parts) { | 153 | protected FieldMapping readField(String[] parts) { |
| 145 | return new FieldMapping(parts[1], new Type(parts[3]), parts[2]); | 154 | FieldMapping mapping = null; |
| 155 | if (parts.length == 4) | ||
| 156 | { | ||
| 157 | boolean access = parts[3].startsWith("ACC:"); | ||
| 158 | if (access) | ||
| 159 | mapping = new FieldMapping(parts[1], new Type(parts[2]), null, | ||
| 160 | Mappings.EntryModifier.valueOf(parts[3].substring(4))); | ||
| 161 | else | ||
| 162 | mapping = new FieldMapping(parts[1], new Type(parts[3]), parts[2], Mappings.EntryModifier.UNCHANGED); | ||
| 163 | } | ||
| 164 | else if (parts.length == 5) | ||
| 165 | mapping = new FieldMapping(parts[1], new Type(parts[3]), parts[2], Mappings.EntryModifier.valueOf(parts[4].substring(4))); | ||
| 166 | return mapping; | ||
| 146 | } | 167 | } |
| 147 | 168 | ||
| 148 | private MethodMapping readMethod(String[] parts) { | 169 | private MethodMapping readMethod(String[] parts) { |
| 149 | if (parts.length == 3) { | 170 | MethodMapping mapping = null; |
| 150 | return new MethodMapping(parts[1], new Signature(parts[2])); | 171 | if (parts.length == 3) |
| 151 | } else { | 172 | mapping = new MethodMapping(parts[1], new Signature(parts[2])); |
| 152 | return new MethodMapping(parts[1], new Signature(parts[3]), parts[2]); | 173 | else if (parts.length == 4){ |
| 174 | boolean access = parts[3].startsWith("ACC:"); | ||
| 175 | if (access) | ||
| 176 | mapping = new MethodMapping(parts[1], new Signature(parts[2]), null, Mappings.EntryModifier.valueOf(parts[3].substring(4))); | ||
| 177 | else | ||
| 178 | mapping = new MethodMapping(parts[1], new Signature(parts[3]), parts[2]); | ||
| 153 | } | 179 | } |
| 180 | else if (parts.length == 5) | ||
| 181 | mapping = new MethodMapping(parts[1], new Signature(parts[3]), parts[2], | ||
| 182 | Mappings.EntryModifier.valueOf(parts[4].substring(4))); | ||
| 183 | return mapping; | ||
| 154 | } | 184 | } |
| 155 | } | 185 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java index e1763d0..9589689 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java | |||
| @@ -110,9 +110,9 @@ public class MappingsEnigmaWriter { | |||
| 110 | 110 | ||
| 111 | private void write(PrintWriter out, ClassMapping classMapping, int depth) throws IOException { | 111 | private void write(PrintWriter out, ClassMapping classMapping, int depth) throws IOException { |
| 112 | if (classMapping.getDeobfName() == null) { | 112 | if (classMapping.getDeobfName() == null) { |
| 113 | out.format("%sCLASS %s\n", getIndent(depth), classMapping.getObfFullName()); | 113 | out.format("%sCLASS %s%s\n", getIndent(depth), classMapping.getObfFullName(), classMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : classMapping.getModifier().getFormattedName()); |
| 114 | } else { | 114 | } else { |
| 115 | out.format("%sCLASS %s %s\n", getIndent(depth), classMapping.getObfFullName(), classMapping.getDeobfName()); | 115 | out.format("%sCLASS %s %s%s\n", getIndent(depth), classMapping.getObfFullName(), classMapping.getDeobfName(), classMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : classMapping.getModifier().getFormattedName()); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { | 118 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { |
| @@ -129,14 +129,17 @@ public class MappingsEnigmaWriter { | |||
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | private void write(PrintWriter out, FieldMapping fieldMapping, int depth) throws IOException { | 131 | private void write(PrintWriter out, FieldMapping fieldMapping, int depth) throws IOException { |
| 132 | out.format("%sFIELD %s %s %s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getDeobfName(), fieldMapping.getObfType().toString()); | 132 | if (fieldMapping.getDeobfName() == null) |
| 133 | out.format("%sFIELD %s %s%s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getObfType().toString(), fieldMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : fieldMapping.getModifier().getFormattedName()); | ||
| 134 | else | ||
| 135 | out.format("%sFIELD %s %s %s%s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getDeobfName(), fieldMapping.getObfType().toString(), fieldMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : fieldMapping.getModifier().getFormattedName()); | ||
| 133 | } | 136 | } |
| 134 | 137 | ||
| 135 | private void write(PrintWriter out, MethodMapping methodMapping, int depth) throws IOException { | 138 | private void write(PrintWriter out, MethodMapping methodMapping, int depth) throws IOException { |
| 136 | if (methodMapping.getDeobfName() == null) { | 139 | if (methodMapping.getDeobfName() == null) { |
| 137 | out.format("%sMETHOD %s %s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getObfSignature()); | 140 | out.format("%sMETHOD %s %s%s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getObfSignature(), methodMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" :methodMapping.getModifier().getFormattedName()); |
| 138 | } else { | 141 | } else { |
| 139 | out.format("%sMETHOD %s %s %s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getDeobfName(), methodMapping.getObfSignature()); | 142 | out.format("%sMETHOD %s %s %s%s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getDeobfName(), methodMapping.getObfSignature(), methodMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : methodMapping.getModifier().getFormattedName()); |
| 140 | } | 143 | } |
| 141 | 144 | ||
| 142 | for (ArgumentMapping argumentMapping : sorted(methodMapping.arguments())) { | 145 | for (ArgumentMapping argumentMapping : sorted(methodMapping.arguments())) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java index 4e812b1..bac6250 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java | |||
| @@ -321,4 +321,22 @@ public class MappingsRenamer { | |||
| 321 | } | 321 | } |
| 322 | return mappingChain; | 322 | return mappingChain; |
| 323 | } | 323 | } |
| 324 | |||
| 325 | public void setClassModifier(ClassEntry obEntry, Mappings.EntryModifier modifier) | ||
| 326 | { | ||
| 327 | ClassMapping classMapping = getOrCreateClassMapping(obEntry); | ||
| 328 | classMapping.setModifier(modifier); | ||
| 329 | } | ||
| 330 | |||
| 331 | public void setFieldModifier(FieldEntry obEntry, Mappings.EntryModifier modifier) | ||
| 332 | { | ||
| 333 | ClassMapping classMapping = getOrCreateClassMapping(obEntry.getClassEntry()); | ||
| 334 | classMapping.setFieldModifier(obEntry.getName(), obEntry.getType(), modifier); | ||
| 335 | } | ||
| 336 | |||
| 337 | public void setMethodModifier(BehaviorEntry obEntry, Mappings.EntryModifier modifier) | ||
| 338 | { | ||
| 339 | ClassMapping classMapping = getOrCreateClassMapping(obEntry.getClassEntry()); | ||
| 340 | classMapping.setMethodModifier(obEntry.getName(), obEntry.getSignature(), modifier); | ||
| 341 | } | ||
| 324 | } | 342 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java index 99b9c88..455ff6b 100644 --- a/src/main/java/cuchaz/enigma/mapping/MethodMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/MethodMapping.java | |||
| @@ -22,12 +22,17 @@ public class MethodMapping implements Comparable<MethodMapping>, MemberMapping<B | |||
| 22 | private String deobfName; | 22 | private String deobfName; |
| 23 | private Signature obfSignature; | 23 | private Signature obfSignature; |
| 24 | private Map<Integer, ArgumentMapping> arguments; | 24 | private Map<Integer, ArgumentMapping> arguments; |
| 25 | private Mappings.EntryModifier modifier; | ||
| 25 | 26 | ||
| 26 | public MethodMapping(String obfName, Signature obfSignature) { | 27 | public MethodMapping(String obfName, Signature obfSignature) { |
| 27 | this(obfName, obfSignature, null); | 28 | this(obfName, obfSignature, null,Mappings.EntryModifier.UNCHANGED); |
| 28 | } | 29 | } |
| 29 | 30 | ||
| 30 | public MethodMapping(String obfName, Signature obfSignature, String deobfName) { | 31 | public MethodMapping(String obfName, Signature obfSignature, String deobfName) { |
| 32 | this(obfName, obfSignature, deobfName, Mappings.EntryModifier.UNCHANGED); | ||
| 33 | } | ||
| 34 | |||
| 35 | public MethodMapping(String obfName, Signature obfSignature, String deobfName, Mappings.EntryModifier modifier) { | ||
| 31 | if (obfName == null) { | 36 | if (obfName == null) { |
| 32 | throw new IllegalArgumentException("obf name cannot be null!"); | 37 | throw new IllegalArgumentException("obf name cannot be null!"); |
| 33 | } | 38 | } |
| @@ -38,11 +43,13 @@ public class MethodMapping implements Comparable<MethodMapping>, MemberMapping<B | |||
| 38 | this.deobfName = NameValidator.validateMethodName(deobfName); | 43 | this.deobfName = NameValidator.validateMethodName(deobfName); |
| 39 | this.obfSignature = obfSignature; | 44 | this.obfSignature = obfSignature; |
| 40 | this.arguments = Maps.newTreeMap(); | 45 | this.arguments = Maps.newTreeMap(); |
| 46 | this.modifier = modifier; | ||
| 41 | } | 47 | } |
| 42 | 48 | ||
| 43 | public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) { | 49 | public MethodMapping(MethodMapping other, ClassNameReplacer obfClassNameReplacer) { |
| 44 | this.obfName = other.obfName; | 50 | this.obfName = other.obfName; |
| 45 | this.deobfName = other.deobfName; | 51 | this.deobfName = other.deobfName; |
| 52 | this.modifier = other.modifier; | ||
| 46 | this.obfSignature = new Signature(other.obfSignature, obfClassNameReplacer); | 53 | this.obfSignature = new Signature(other.obfSignature, obfClassNameReplacer); |
| 47 | this.arguments = Maps.newTreeMap(); | 54 | this.arguments = Maps.newTreeMap(); |
| 48 | for (Map.Entry<Integer,ArgumentMapping> entry : other.arguments.entrySet()) { | 55 | for (Map.Entry<Integer,ArgumentMapping> entry : other.arguments.entrySet()) { |
| @@ -187,4 +194,14 @@ public class MethodMapping implements Comparable<MethodMapping>, MemberMapping<B | |||
| 187 | return new MethodEntry(classEntry, this.obfName, this.obfSignature); | 194 | return new MethodEntry(classEntry, this.obfName, this.obfSignature); |
| 188 | } | 195 | } |
| 189 | } | 196 | } |
| 197 | |||
| 198 | public Mappings.EntryModifier getModifier() | ||
| 199 | { | ||
| 200 | return modifier; | ||
| 201 | } | ||
| 202 | |||
| 203 | public void setModifier(Mappings.EntryModifier modifier) | ||
| 204 | { | ||
| 205 | this.modifier = modifier; | ||
| 206 | } | ||
| 190 | } | 207 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/Translator.java b/src/main/java/cuchaz/enigma/mapping/Translator.java index 6b636f2..e94009e 100644 --- a/src/main/java/cuchaz/enigma/mapping/Translator.java +++ b/src/main/java/cuchaz/enigma/mapping/Translator.java | |||
| @@ -329,4 +329,27 @@ public class Translator { | |||
| 329 | assert (mappingsChain.size() == parts.length); | 329 | assert (mappingsChain.size() == parts.length); |
| 330 | return mappingsChain; | 330 | return mappingsChain; |
| 331 | } | 331 | } |
| 332 | |||
| 333 | public Mappings.EntryModifier getModifier(Entry entry) | ||
| 334 | { | ||
| 335 | ClassMapping classMapping = findClassMapping(entry.getClassEntry()); | ||
| 336 | if (classMapping != null && !entry.getName().equals("<clinit>")) | ||
| 337 | { | ||
| 338 | if (entry instanceof ClassEntry) | ||
| 339 | return classMapping.getModifier(); | ||
| 340 | else if (entry instanceof FieldEntry) | ||
| 341 | { | ||
| 342 | FieldMapping fieldMapping = classMapping.getFieldByObf(entry.getName(), ((FieldEntry) entry).getType()); | ||
| 343 | return fieldMapping != null ? fieldMapping.getModifier() : Mappings.EntryModifier.UNCHANGED; | ||
| 344 | } | ||
| 345 | else if (entry instanceof BehaviorEntry) | ||
| 346 | { | ||
| 347 | MethodMapping methodMapping = classMapping.getMethodByObf(entry.getName(), ((BehaviorEntry) entry).getSignature()); | ||
| 348 | return methodMapping != null ? methodMapping.getModifier() : Mappings.EntryModifier.UNCHANGED; | ||
| 349 | } | ||
| 350 | else | ||
| 351 | throw new Error("Unknown entry type: " + entry.getClass().getName()); | ||
| 352 | } | ||
| 353 | return Mappings.EntryModifier.UNCHANGED; | ||
| 354 | } | ||
| 332 | } | 355 | } |