summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ftbsc/lll')
-rw-r--r--src/main/java/ftbsc/lll/mapper/AbstractMapper.java5
-rw-r--r--src/main/java/ftbsc/lll/mapper/IMapper.java6
-rw-r--r--src/main/java/ftbsc/lll/mapper/impl/MultiMapper.java73
-rw-r--r--src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java16
4 files changed, 54 insertions, 46 deletions
diff --git a/src/main/java/ftbsc/lll/mapper/AbstractMapper.java b/src/main/java/ftbsc/lll/mapper/AbstractMapper.java
index bd71f90..ced4983 100644
--- a/src/main/java/ftbsc/lll/mapper/AbstractMapper.java
+++ b/src/main/java/ftbsc/lll/mapper/AbstractMapper.java
@@ -58,4 +58,9 @@ public abstract class AbstractMapper implements IMapper {
public FieldData getFieldData(String parent, String name) throws MappingNotFoundException {
return this.getClassData(parent).mapField(name);
}
+
+ @Override
+ public Map<String, ClassData> getRawMappings() {
+ return this.mappings;
+ }
}
diff --git a/src/main/java/ftbsc/lll/mapper/IMapper.java b/src/main/java/ftbsc/lll/mapper/IMapper.java
index 1fe04ca..d3ba8b3 100644
--- a/src/main/java/ftbsc/lll/mapper/IMapper.java
+++ b/src/main/java/ftbsc/lll/mapper/IMapper.java
@@ -77,4 +77,10 @@ public interface IMapper {
* @throws MappingNotFoundException if no mapping is found
*/
FieldData getFieldData(String parent, String name) throws MappingNotFoundException;
+
+ /**
+ * Fetches the "raw mappings" from an {@link IMapper}.
+ * @return a map tying each {@link ClassData} to the class' plain name
+ */
+ Map<String, ClassData> getRawMappings();
}
diff --git a/src/main/java/ftbsc/lll/mapper/impl/MultiMapper.java b/src/main/java/ftbsc/lll/mapper/impl/MultiMapper.java
index db12235..f0af490 100644
--- a/src/main/java/ftbsc/lll/mapper/impl/MultiMapper.java
+++ b/src/main/java/ftbsc/lll/mapper/impl/MultiMapper.java
@@ -2,16 +2,13 @@ package ftbsc.lll.mapper.impl;
import com.google.auto.service.AutoService;
import ftbsc.lll.exceptions.MalformedMappingsException;
-import ftbsc.lll.exceptions.MappingNotFoundException;
+import ftbsc.lll.mapper.AbstractMapper;
import ftbsc.lll.mapper.IMapper;
import ftbsc.lll.mapper.MapperProvider;
import ftbsc.lll.mapper.tools.MappingUtils;
import ftbsc.lll.mapper.tools.data.ClassData;
-import ftbsc.lll.mapper.tools.data.FieldData;
-import ftbsc.lll.mapper.tools.data.MethodData;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
/**
@@ -19,13 +16,7 @@ import java.util.List;
* sequence of mappers applied one after the other.
*/
@AutoService(IMapper.class)
-public class MultiMapper implements IMapper {
-
- /**
- * The list of mappers.
- */
- private final List<IMapper> mapperList = new ArrayList<>();
-
+public class MultiMapper extends AbstractMapper {
@Override
public boolean claim(List<String> lines) {
return lines.get(0).equals("lll multimapper");
@@ -33,52 +24,42 @@ public class MultiMapper implements IMapper {
@Override
public void populate(List<String> lines, boolean ignoreErrors) throws MalformedMappingsException {
+ List<IMapper> mapperList = new ArrayList<>();
for(int i = 1; i < lines.size(); i++) {
List<String> data = MapperProvider.fetchFromLocalOrRemote(lines.get(i));
IMapper mapper = MapperProvider.getMapper(data);
mapper.populate(data, ignoreErrors);
- this.mapperList.add(mapper);
+ mapperList.add(mapper);
}
- }
- @Override
- public IMapper getInverted() {
- MultiMapper reverse = new MultiMapper();
- this.mapperList.forEach(m -> reverse.mapperList.add(m.getInverted()));
- Collections.reverse(reverse.mapperList);
- return reverse;
- }
+ mapperList.get(0).getRawMappings().forEach((name, data) -> {
+ ClassData finalData = data;
+ for(int i = 1; i < mapperList.size(); i++)
+ finalData = mapperList.get(i).getClassData(finalData.nameMapped);
- @Override
- public void reset() {
- this.mapperList.forEach(IMapper::reset);
- this.mapperList.clear();
- }
+ ClassData sumData = new ClassData(data.name, finalData.nameMapped);
- @Override
- public ClassData getClassData(String name) throws MappingNotFoundException {
- ClassData classData = this.mapperList.get(0).getClassData(name);
- for(int i = 1; i < this.mapperList.size(); i++)
- classData = this.mapperList.get(i).getClassData(classData.nameMapped);
- return classData;
- }
+ data.getMethods().forEach((signature, methodData) -> {
+ for(int i = 1; i < mapperList.size(); i++) {
+ IMapper mapper = mapperList.get(i);
+ methodData = mapper.getMethodData(methodData.parentClass.nameMapped, methodData.nameMapped,
+ MappingUtils.mapMethodDescriptor(methodData.signature.descriptor, mapper, false));
+ }
+ sumData.addMethod(signature.name, methodData.nameMapped, signature.descriptor);
+ });
- @Override
- public MethodData getMethodData(String parent, String name, String descriptor) throws MappingNotFoundException {
- MethodData methodData = this.mapperList.get(0).getMethodData(parent, name, descriptor);
- for(int i = 1; i < this.mapperList.size(); i++) {
- IMapper mapper = this.mapperList.get(i);
- methodData = mapper.getMethodData(methodData.parentClass.nameMapped, methodData.nameMapped,
- MappingUtils.mapMethodDescriptor(methodData.signature.descriptor, mapper, false));
- }
- return methodData;
+ data.getFields().forEach((fieldName, fieldData) -> {
+ for(int i = 1; i < mapperList.size(); i++)
+ fieldData = mapperList.get(i).getFieldData(fieldData.parentClass.nameMapped, fieldData.nameMapped);
+ sumData.addField(fieldName, fieldData.nameMapped);
+ });
+
+ this.mappings.put(sumData.name, sumData);
+ });
}
@Override
- public FieldData getFieldData(String parent, String name) throws MappingNotFoundException {
- FieldData fieldData = this.mapperList.get(0).getFieldData(parent, name);
- for(int i = 1; i < this.mapperList.size(); i++)
- fieldData = this.mapperList.get(i).getFieldData(fieldData.parentClass.nameMapped, fieldData.nameMapped);
- return fieldData;
+ protected AbstractMapper newInstance() {
+ return new MultiMapper();
}
}
diff --git a/src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java b/src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java
index 0f9f25e..cdcec4d 100644
--- a/src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java
+++ b/src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java
@@ -115,4 +115,20 @@ public class ClassData {
throw new MappingNotFoundException("field", String.format("%s.%s", this.name, fieldName));
else return data;
}
+
+ /**
+ * Gets the underlying {@link Map} for {@link MethodData}.
+ * @return a {@link Map} tying each {@link MethodSignature} to its {@link MethodData}
+ */
+ public Map<MethodSignature, MethodData> getMethods() {
+ return this.methods;
+ }
+
+ /**
+ * Gets the underlying {@link Map} for {@link FieldData}.
+ * @return a {@link Map} tying each field name to its {@link FieldData}
+ */
+ public Map<String, FieldData> getFields() {
+ return this.fields;
+ }
} \ No newline at end of file