aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/mapper/AbstractMapper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ftbsc/lll/mapper/AbstractMapper.java')
-rw-r--r--src/main/java/ftbsc/lll/mapper/AbstractMapper.java123
1 files changed, 21 insertions, 102 deletions
diff --git a/src/main/java/ftbsc/lll/mapper/AbstractMapper.java b/src/main/java/ftbsc/lll/mapper/AbstractMapper.java
index 037e7c9..62585c4 100644
--- a/src/main/java/ftbsc/lll/mapper/AbstractMapper.java
+++ b/src/main/java/ftbsc/lll/mapper/AbstractMapper.java
@@ -1,11 +1,11 @@
package ftbsc.lll.mapper;
-import ftbsc.lll.exceptions.MalformedMappingsException;
import ftbsc.lll.exceptions.MappingNotFoundException;
import ftbsc.lll.mapper.tools.data.ClassData;
+import ftbsc.lll.mapper.tools.data.FieldData;
+import ftbsc.lll.mapper.tools.data.MethodData;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
/**
@@ -19,124 +19,43 @@ public abstract class AbstractMapper implements IMapper {
*/
protected final Map<String, ClassData> mappings = new HashMap<>();
- /**
- * A {@link Map} tying each obfuscated name to its class data.
- */
- protected final Map<String, ClassData> mappingsInverted = new HashMap<>();
+ @Override
+ public void reset() {
+ this.mappings.clear();
+ }
- /**
- * Populates the {@link IMapper} given the lines, ignoring errors depending on the
- * given ignoreErrors flag.
- * @param lines the lines to read
- * @param ignoreErrors try to ignore errors and keep going
- * @throws MalformedMappingsException if an error is encountered and ignoreErrors is false
- */
@Override
- public void populate(List<String> lines, boolean ignoreErrors) throws MalformedMappingsException {
- this.processLines(lines, ignoreErrors);
+ public IMapper getInverted() {
+ AbstractMapper inverted = newInstance();
this.mappings.forEach((name, data) -> {
ClassData reverse = data.generateReverseMappings(this);
- this.mappingsInverted.put(data.nameMapped, reverse);
+ inverted.mappings.put(data.nameMapped, reverse);
});
+ return inverted;
}
/**
- * Reads the given lines of text and attempts to interpret them as
- * mappings of the given type.
- * @param lines the lines to read
- * @param ignoreErrors try to ignore errors and keep going
- * @throws MalformedMappingsException if an error is encountered and ignoreErrors is false
+ * Creates a new instance of this type of mapper.
+ * @return the new, empty instance
*/
- protected abstract void processLines(List<String> lines, boolean ignoreErrors) throws MalformedMappingsException;
+ protected abstract AbstractMapper newInstance();
- /**
- * Completely resets the mapper, clearing it of all existing mappings.
- */
- @Override
- public void reset() {
- this.mappings.clear();
- this.mappingsInverted.clear();
- }
- /**
- * Gets a name of a class from the given {@link Map}.
- * @param name the name
- * @param mappings the {@link Map} to pull data from
- * @return the mapped name
- * @throws MappingNotFoundException if no mapping is found
- */
- private static String mapClass(String name, Map<String, ClassData> mappings) {
- ClassData data = mappings.get(name.replace('.', '/'));
- if(data == null)
- throw new MappingNotFoundException("class", name);
- else return data.nameMapped;
- }
-
- /**
- * Gets the obfuscated name of the class.
- * @param name the plain internal name of the desired class
- * @return the obfuscated name of the class
- * @throws MappingNotFoundException if no mapping is found
- */
@Override
- public String obfuscateClass(String name) {
- return mapClass(name, this.mappings);
- }
-
- /**
- * Gets the plain name of the class.
- * @param nameObf the obfuscated internal name of the desired class
- * @return the plain name of the class
- * @throws MappingNotFoundException if no mapping is found
- */
- @Override
- public String deobfuscateClass(String nameObf) throws MappingNotFoundException {
- return mapClass(nameObf, this.mappingsInverted);
- }
-
- /**
- * Gets the name of a member from the given {@link Map}.
- * @param parentName the parent class
- * @param mappings the {@link Map} to pull data from
- * @param memberName the field or method name
- * @param methodDescriptor the method descriptor, may be null or partial
- * @return the mapped member name
- * @throws MappingNotFoundException if no mapping is found
- */
- private static String mapMember(String parentName, Map<String, ClassData> mappings,
- String memberName, String methodDescriptor) {
- ClassData data = mappings.get(parentName.replace('.', '/'));
+ public ClassData getClassData(String name) {
+ ClassData data = this.mappings.get(name.replace('.', '/'));
if(data == null)
- throw new MappingNotFoundException("class", parentName);
-
- if(methodDescriptor == null)
- return data.mapField(memberName).name;
- else return data.mapMethod(memberName, methodDescriptor).signature.name;
+ throw new MappingNotFoundException("class", name);
+ else return data;
}
- /**
- * Gets the obfuscated name of a class member (field or method).
- * @param parentName the unobfuscated internal name of the parent class
- * @param memberName the field or method name
- * @param methodDescriptor the optional descriptor of the member, may be null or partial
- * @return the obfuscated name of the given member
- * @throws MappingNotFoundException if no mapping is found
- */
@Override
- public String obfuscateMember(String parentName, String memberName, String methodDescriptor) {
- return mapMember(parentName, this.mappings, memberName, methodDescriptor);
+ public MethodData getMethodData(String parent, String name, String descriptor) {
+ return this.getClassData(parent).mapMethod(name, descriptor);
}
- /**
- * Gets the plain name of a class member (field or method).
- * @param parentName the obfuscated internal name of the parent class
- * @param memberName the obfuscated field name or method signature
- * @param methodDescriptor the obfuscated descriptor of the member (only for methods)
- * @return the plain name of the given member
- * @throws MappingNotFoundException if no mapping is found
- */
@Override
- public String deobfuscateMember(String parentName, String memberName, String methodDescriptor) throws MappingNotFoundException {
- return mapMember(parentName, this.mappingsInverted, memberName, methodDescriptor);
+ public FieldData getFieldData(String parent, String name) throws MappingNotFoundException {
+ return this.getClassData(parent).mapField(name);
}
}