diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsChecker.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsChecker.java | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java deleted file mode 100644 index a42f255..0000000 --- a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java +++ /dev/null | |||
| @@ -1,101 +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 | |||
| 12 | package cuchaz.enigma.mapping; | ||
| 13 | |||
| 14 | import com.google.common.collect.Lists; | ||
| 15 | import com.google.common.collect.Maps; | ||
| 16 | import cuchaz.enigma.analysis.JarIndex; | ||
| 17 | import cuchaz.enigma.mapping.entry.ClassEntry; | ||
| 18 | import cuchaz.enigma.mapping.entry.EntryFactory; | ||
| 19 | import cuchaz.enigma.mapping.entry.FieldEntry; | ||
| 20 | import cuchaz.enigma.mapping.entry.MethodEntry; | ||
| 21 | |||
| 22 | import java.util.Map; | ||
| 23 | |||
| 24 | public class MappingsChecker { | ||
| 25 | |||
| 26 | private JarIndex index; | ||
| 27 | private Map<ClassEntry, ClassMapping> droppedClassMappings; | ||
| 28 | private Map<ClassEntry, ClassMapping> droppedInnerClassMappings; | ||
| 29 | private Map<FieldEntry, FieldMapping> droppedFieldMappings; | ||
| 30 | private Map<MethodEntry, MethodMapping> droppedMethodMappings; | ||
| 31 | |||
| 32 | public MappingsChecker(JarIndex index) { | ||
| 33 | this.index = index; | ||
| 34 | this.droppedClassMappings = Maps.newHashMap(); | ||
| 35 | this.droppedInnerClassMappings = Maps.newHashMap(); | ||
| 36 | this.droppedFieldMappings = Maps.newHashMap(); | ||
| 37 | this.droppedMethodMappings = Maps.newHashMap(); | ||
| 38 | } | ||
| 39 | |||
| 40 | public Map<ClassEntry, ClassMapping> getDroppedClassMappings() { | ||
| 41 | return this.droppedClassMappings; | ||
| 42 | } | ||
| 43 | |||
| 44 | public Map<ClassEntry, ClassMapping> getDroppedInnerClassMappings() { | ||
| 45 | return this.droppedInnerClassMappings; | ||
| 46 | } | ||
| 47 | |||
| 48 | public Map<FieldEntry, FieldMapping> getDroppedFieldMappings() { | ||
| 49 | return this.droppedFieldMappings; | ||
| 50 | } | ||
| 51 | |||
| 52 | public Map<MethodEntry, MethodMapping> getDroppedMethodMappings() { | ||
| 53 | return this.droppedMethodMappings; | ||
| 54 | } | ||
| 55 | |||
| 56 | public void dropBrokenMappings(Mappings mappings) { | ||
| 57 | for (ClassMapping classMapping : Lists.newArrayList(mappings.classes())) { | ||
| 58 | if (!checkClassMapping(classMapping)) { | ||
| 59 | mappings.removeClassMapping(classMapping); | ||
| 60 | this.droppedClassMappings.put(EntryFactory.getObfClassEntry(this.index, classMapping), classMapping); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | private boolean checkClassMapping(ClassMapping classMapping) { | ||
| 66 | |||
| 67 | // check the class | ||
| 68 | ClassEntry classEntry = EntryFactory.getObfClassEntry(this.index, classMapping); | ||
| 69 | if (!this.index.getObfClassEntries().contains(classEntry)) { | ||
| 70 | return false; | ||
| 71 | } | ||
| 72 | |||
| 73 | // check the fields | ||
| 74 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { | ||
| 75 | FieldEntry obfFieldEntry = EntryFactory.getObfFieldEntry(classMapping, fieldMapping); | ||
| 76 | if (!this.index.containsObfField(obfFieldEntry)) { | ||
| 77 | classMapping.removeFieldMapping(fieldMapping); | ||
| 78 | this.droppedFieldMappings.put(obfFieldEntry, fieldMapping); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | // check methods | ||
| 83 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { | ||
| 84 | MethodEntry obfMethodEntry = EntryFactory.getObfMethodEntry(classEntry, methodMapping); | ||
| 85 | if (!this.index.containsObfMethod(obfMethodEntry)) { | ||
| 86 | classMapping.removeMethodMapping(methodMapping); | ||
| 87 | this.droppedMethodMappings.put(obfMethodEntry, methodMapping); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | // check inner classes | ||
| 92 | for (ClassMapping innerClassMapping : Lists.newArrayList(classMapping.innerClasses())) { | ||
| 93 | if (!checkClassMapping(innerClassMapping)) { | ||
| 94 | classMapping.removeInnerClassMapping(innerClassMapping); | ||
| 95 | this.droppedInnerClassMappings.put(EntryFactory.getObfClassEntry(this.index, innerClassMapping), innerClassMapping); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | return true; | ||
| 100 | } | ||
| 101 | } | ||