aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/mapper/impl
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-08-26 18:25:31 +0200
committer zaaarf <zaaarf@proton.me>2023-08-26 18:25:31 +0200
commitf03bb3c932b035a94222cdd57b60ba1c77130585 (patch)
tree5e1a0e32a30a89b68a5c3156aef104d3d59dee43 /src/main/java/ftbsc/lll/mapper/impl
parent7898882bc5811e5f06e70bc2bb6925e114869a56 (diff)
feat: added error handling and generally tweaked tsrg parsing
Diffstat (limited to 'src/main/java/ftbsc/lll/mapper/impl')
-rw-r--r--src/main/java/ftbsc/lll/mapper/impl/TSRGMapper.java32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/main/java/ftbsc/lll/mapper/impl/TSRGMapper.java b/src/main/java/ftbsc/lll/mapper/impl/TSRGMapper.java
index 2bd4d28..ad4c65e 100644
--- a/src/main/java/ftbsc/lll/mapper/impl/TSRGMapper.java
+++ b/src/main/java/ftbsc/lll/mapper/impl/TSRGMapper.java
@@ -6,7 +6,6 @@ import ftbsc.lll.mapper.AbstractMapper;
import ftbsc.lll.mapper.IMapper;
import ftbsc.lll.mapper.tools.data.ClassData;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -36,24 +35,23 @@ public class TSRGMapper extends AbstractMapper {
*/
@Override
protected void processLines(List<String> lines, boolean ignoreErrors) throws MalformedMappingsException {
- //skip the first line ("tsrg2 left right")
- lines = new ArrayList<>(lines);
- lines.remove(0);
-
String currentClass = "";
- for(String l : lines) {
- if(l == null) continue;
- if(l.startsWith("\t") || l.startsWith(" ")) {
- String[] split = l.trim().split(" ");
- if(split.length == 2) //field
- this.mappings.get(currentClass).addField(split[0], split[1]);
- else if (split.length == 3)//method
- this.mappings.get(currentClass).addMethod(split[0], split[2], split[1]); //add child
+ for(int i = 1; i < lines.size(); i++) { //start from 1 to skip header
+ String currentLine = lines.get(i);
+ boolean isMember = currentLine.startsWith("\t") || currentLine.startsWith(" ");
+ String[] tokens = currentLine.trim().split(" ");
+ if(isMember) {
+ if(tokens.length == 2) //field
+ this.mappings.get(currentClass).addField(tokens[0], tokens[1]);
+ else if(tokens.length == 3)//method
+ this.mappings.get(currentClass).addMethod(tokens[0], tokens[2], tokens[1]); //add child
+ else if(!ignoreErrors) throw new MalformedMappingsException(i, "wrong number of space-separated tokens");
} else {
- String[] sp = l.split(" ");
- ClassData s = new ClassData(sp[0], sp[1]);
- currentClass = s.name;
- this.mappings.put(s.name, s);
+ if(tokens.length == 2) {
+ ClassData s = new ClassData(tokens[0], tokens[1]);
+ currentClass = s.name;
+ this.mappings.put(s.name, s);
+ } else if(!ignoreErrors) throw new MalformedMappingsException(i, "wrong number of space-separated tokens");
}
}
}