diff options
| author | 2016-08-17 18:35:12 +0200 | |
|---|---|---|
| committer | 2016-08-17 18:35:12 +0200 | |
| commit | 5540c815de36e316d0749ce2163f12c61895b327 (patch) | |
| tree | 2b30d5ae98735ee7cba7d1c0087c51d68ed3ebf9 /src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |
| parent | Revert "Removed util" (diff) | |
| download | enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.tar.gz enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.tar.xz enigma-fork-5540c815de36e316d0749ce2163f12c61895b327.zip | |
Revert "Removed unused methods"
This reverts commit 1742190f784d0d62e7cc869eebafdfe1927e448f.
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/ClassMapping.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/ClassMapping.java | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index b2c076a..36b35f7 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -12,6 +12,7 @@ package cuchaz.enigma.mapping; | |||
| 12 | 12 | ||
| 13 | import com.google.common.collect.Maps; | 13 | import com.google.common.collect.Maps; |
| 14 | 14 | ||
| 15 | import java.util.ArrayList; | ||
| 15 | import java.util.Map; | 16 | import java.util.Map; |
| 16 | 17 | ||
| 17 | import cuchaz.enigma.throwables.MappingConflict; | 18 | import cuchaz.enigma.throwables.MappingConflict; |
| @@ -119,6 +120,15 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 119 | return classMapping; | 120 | return classMapping; |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 123 | public String getDeobfInnerClassName(String obfSimpleName) { | ||
| 124 | assert (isSimpleClassName(obfSimpleName)); | ||
| 125 | ClassMapping classMapping = m_innerClassesByObfSimple.get(obfSimpleName); | ||
| 126 | if (classMapping != null) { | ||
| 127 | return classMapping.getDeobfName(); | ||
| 128 | } | ||
| 129 | return null; | ||
| 130 | } | ||
| 131 | |||
| 122 | public void setInnerClassName(ClassEntry obfInnerClass, String deobfName) { | 132 | public void setInnerClassName(ClassEntry obfInnerClass, String deobfName) { |
| 123 | ClassMapping classMapping = getOrCreateInnerClass(obfInnerClass); | 133 | ClassMapping classMapping = getOrCreateInnerClass(obfInnerClass); |
| 124 | if (classMapping.getDeobfName() != null) { | 134 | if (classMapping.getDeobfName() != null) { |
| @@ -149,6 +159,10 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 149 | return m_fieldsByObf.values(); | 159 | return m_fieldsByObf.values(); |
| 150 | } | 160 | } |
| 151 | 161 | ||
| 162 | public boolean containsObfField(String obfName, Type obfType) { | ||
| 163 | return m_fieldsByObf.containsKey(getFieldKey(obfName, obfType)); | ||
| 164 | } | ||
| 165 | |||
| 152 | public boolean containsDeobfField(String deobfName, Type deobfType) { | 166 | public boolean containsDeobfField(String deobfName, Type deobfType) { |
| 153 | return m_fieldsByDeobf.containsKey(getFieldKey(deobfName, deobfType)); | 167 | return m_fieldsByDeobf.containsKey(getFieldKey(deobfName, deobfType)); |
| 154 | } | 168 | } |
| @@ -182,6 +196,10 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 182 | return m_fieldsByObf.get(getFieldKey(obfName, obfType)); | 196 | return m_fieldsByObf.get(getFieldKey(obfName, obfType)); |
| 183 | } | 197 | } |
| 184 | 198 | ||
| 199 | public FieldMapping getFieldByDeobf(String deobfName, Type obfType) { | ||
| 200 | return m_fieldsByDeobf.get(getFieldKey(deobfName, obfType)); | ||
| 201 | } | ||
| 202 | |||
| 185 | public String getObfFieldName(String deobfName, Type obfType) { | 203 | public String getObfFieldName(String deobfName, Type obfType) { |
| 186 | FieldMapping fieldMapping = m_fieldsByDeobf.get(getFieldKey(deobfName, obfType)); | 204 | FieldMapping fieldMapping = m_fieldsByDeobf.get(getFieldKey(deobfName, obfType)); |
| 187 | if (fieldMapping != null) { | 205 | if (fieldMapping != null) { |
| @@ -227,6 +245,16 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 227 | } | 245 | } |
| 228 | } | 246 | } |
| 229 | 247 | ||
| 248 | public void setFieldObfNameAndType(String oldObfName, Type obfType, String newObfName, Type newObfType) { | ||
| 249 | assert(newObfName != null); | ||
| 250 | FieldMapping fieldMapping = m_fieldsByObf.remove(getFieldKey(oldObfName, obfType)); | ||
| 251 | assert(fieldMapping != null); | ||
| 252 | fieldMapping.setObfName(newObfName); | ||
| 253 | fieldMapping.setObfType(newObfType); | ||
| 254 | boolean obfWasAdded = m_fieldsByObf.put(getFieldKey(newObfName, newObfType), fieldMapping) == null; | ||
| 255 | assert(obfWasAdded); | ||
| 256 | } | ||
| 257 | |||
| 230 | //// METHODS //////// | 258 | //// METHODS //////// |
| 231 | 259 | ||
| 232 | public Iterable<MethodMapping> methods() { | 260 | public Iterable<MethodMapping> methods() { |
| @@ -234,6 +262,10 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 234 | return m_methodsByObf.values(); | 262 | return m_methodsByObf.values(); |
| 235 | } | 263 | } |
| 236 | 264 | ||
| 265 | public boolean containsObfMethod(String obfName, Signature obfSignature) { | ||
| 266 | return m_methodsByObf.containsKey(getMethodKey(obfName, obfSignature)); | ||
| 267 | } | ||
| 268 | |||
| 237 | public boolean containsDeobfMethod(String deobfName, Signature obfSignature) { | 269 | public boolean containsDeobfMethod(String deobfName, Signature obfSignature) { |
| 238 | return m_methodsByDeobf.containsKey(getMethodKey(deobfName, obfSignature)); | 270 | return m_methodsByDeobf.containsKey(getMethodKey(deobfName, obfSignature)); |
| 239 | } | 271 | } |
| @@ -298,6 +330,16 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 298 | } | 330 | } |
| 299 | } | 331 | } |
| 300 | 332 | ||
| 333 | public void setMethodObfNameAndSignature(String oldObfName, Signature obfSignature, String newObfName, Signature newObfSignature) { | ||
| 334 | assert(newObfName != null); | ||
| 335 | MethodMapping methodMapping = m_methodsByObf.remove(getMethodKey(oldObfName, obfSignature)); | ||
| 336 | assert(methodMapping != null); | ||
| 337 | methodMapping.setObfName(newObfName); | ||
| 338 | methodMapping.setObfSignature(newObfSignature); | ||
| 339 | boolean obfWasAdded = m_methodsByObf.put(getMethodKey(newObfName, newObfSignature), methodMapping) == null; | ||
| 340 | assert(obfWasAdded); | ||
| 341 | } | ||
| 342 | |||
| 301 | //// ARGUMENTS //////// | 343 | //// ARGUMENTS //////// |
| 302 | 344 | ||
| 303 | public void setArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex, String argumentName) { | 345 | public void setArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex, String argumentName) { |
| @@ -360,6 +402,48 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 360 | return m_obfFullName.compareTo(other.m_obfFullName); | 402 | return m_obfFullName.compareTo(other.m_obfFullName); |
| 361 | } | 403 | } |
| 362 | 404 | ||
| 405 | public boolean renameObfClass(String oldObfClassName, String newObfClassName) { | ||
| 406 | |||
| 407 | // rename inner classes | ||
| 408 | for (ClassMapping innerClassMapping : new ArrayList<>(m_innerClassesByObfSimple.values())) { | ||
| 409 | if (innerClassMapping.renameObfClass(oldObfClassName, newObfClassName)) { | ||
| 410 | boolean wasRemoved = m_innerClassesByObfSimple.remove(oldObfClassName) != null; | ||
| 411 | assert (wasRemoved); | ||
| 412 | boolean wasAdded = m_innerClassesByObfSimple.put(newObfClassName, innerClassMapping) == null; | ||
| 413 | assert (wasAdded); | ||
| 414 | } | ||
| 415 | } | ||
| 416 | |||
| 417 | // rename field types | ||
| 418 | for (FieldMapping fieldMapping : new ArrayList<>(m_fieldsByObf.values())) { | ||
| 419 | String oldFieldKey = getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()); | ||
| 420 | if (fieldMapping.renameObfClass(oldObfClassName, newObfClassName)) { | ||
| 421 | boolean wasRemoved = m_fieldsByObf.remove(oldFieldKey) != null; | ||
| 422 | assert (wasRemoved); | ||
| 423 | boolean wasAdded = m_fieldsByObf.put(getFieldKey(fieldMapping.getObfName(), fieldMapping.getObfType()), fieldMapping) == null; | ||
| 424 | assert (wasAdded); | ||
| 425 | } | ||
| 426 | } | ||
| 427 | |||
| 428 | // rename method signatures | ||
| 429 | for (MethodMapping methodMapping : new ArrayList<>(m_methodsByObf.values())) { | ||
| 430 | String oldMethodKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); | ||
| 431 | if (methodMapping.renameObfClass(oldObfClassName, newObfClassName)) { | ||
| 432 | boolean wasRemoved = m_methodsByObf.remove(oldMethodKey) != null; | ||
| 433 | assert (wasRemoved); | ||
| 434 | boolean wasAdded = m_methodsByObf.put(getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()), methodMapping) == null; | ||
| 435 | assert (wasAdded); | ||
| 436 | } | ||
| 437 | } | ||
| 438 | |||
| 439 | if (m_obfFullName.equals(oldObfClassName)) { | ||
| 440 | // rename this class | ||
| 441 | m_obfFullName = newObfClassName; | ||
| 442 | return true; | ||
| 443 | } | ||
| 444 | return false; | ||
| 445 | } | ||
| 446 | |||
| 363 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { | 447 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { |
| 364 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfBehaviorEntry.getName(), obfBehaviorEntry.getSignature())); | 448 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfBehaviorEntry.getName(), obfBehaviorEntry.getSignature())); |
| 365 | return methodMapping != null && methodMapping.containsArgument(name); | 449 | return methodMapping != null && methodMapping.containsArgument(name); |
| @@ -369,4 +453,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 369 | return name.indexOf('/') < 0 && name.indexOf('$') < 0; | 453 | return name.indexOf('/') < 0 && name.indexOf('$') < 0; |
| 370 | } | 454 | } |
| 371 | 455 | ||
| 456 | public ClassEntry getObfEntry() { | ||
| 457 | return new ClassEntry(m_obfFullName); | ||
| 458 | } | ||
| 372 | } | 459 | } |