diff options
Diffstat (limited to 'src/main/java/ftbsc/lll/mapper/impl/MultiMapper.java')
-rw-r--r-- | src/main/java/ftbsc/lll/mapper/impl/MultiMapper.java | 73 |
1 files changed, 27 insertions, 46 deletions
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(); } } |