diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java b/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java deleted file mode 100644 index 776d908..0000000 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReaderOld.java +++ /dev/null | |||
| @@ -1,127 +0,0 @@ | |||
| 1 | package cuchaz.enigma.mapping; | ||
| 2 | |||
| 3 | import com.google.common.collect.Queues; | ||
| 4 | |||
| 5 | import java.io.BufferedReader; | ||
| 6 | import java.io.IOException; | ||
| 7 | import java.io.Reader; | ||
| 8 | import java.util.Deque; | ||
| 9 | |||
| 10 | import cuchaz.enigma.throwables.MappingConflict; | ||
| 11 | import cuchaz.enigma.throwables.MappingParseException; | ||
| 12 | |||
| 13 | public class MappingsReaderOld { | ||
| 14 | |||
| 15 | public Mappings read(Reader in) throws IOException, MappingParseException { | ||
| 16 | return read(new BufferedReader(in)); | ||
| 17 | } | ||
| 18 | |||
| 19 | public Mappings read(BufferedReader in) throws IOException, MappingParseException { | ||
| 20 | Mappings mappings = new Mappings(); | ||
| 21 | Deque<Object> mappingStack = Queues.newArrayDeque(); | ||
| 22 | |||
| 23 | int lineNumber = 0; | ||
| 24 | String line; | ||
| 25 | while ((line = in.readLine()) != null) { | ||
| 26 | lineNumber++; | ||
| 27 | |||
| 28 | // strip comments | ||
| 29 | int commentPos = line.indexOf('#'); | ||
| 30 | if (commentPos >= 0) { | ||
| 31 | line = line.substring(0, commentPos); | ||
| 32 | } | ||
| 33 | |||
| 34 | // skip blank lines | ||
| 35 | if (line.trim().length() <= 0) { | ||
| 36 | continue; | ||
| 37 | } | ||
| 38 | |||
| 39 | // get the indent of this line | ||
| 40 | int indent = 0; | ||
| 41 | for (int i = 0; i < line.length(); i++) { | ||
| 42 | if (line.charAt(i) != '\t') { | ||
| 43 | break; | ||
| 44 | } | ||
| 45 | indent++; | ||
| 46 | } | ||
| 47 | |||
| 48 | // handle stack pops | ||
| 49 | while (indent < mappingStack.size()) { | ||
| 50 | mappingStack.pop(); | ||
| 51 | } | ||
| 52 | |||
| 53 | String[] parts = line.trim().split("\\s"); | ||
| 54 | try { | ||
| 55 | // read the first token | ||
| 56 | String token = parts[0]; | ||
| 57 | |||
| 58 | if (token.equalsIgnoreCase("CLASS")) { | ||
| 59 | ClassMapping classMapping; | ||
| 60 | if (indent <= 0) { | ||
| 61 | // outer class | ||
| 62 | classMapping = readClass(parts); | ||
| 63 | mappings.addClassMapping(classMapping); | ||
| 64 | } else { | ||
| 65 | |||
| 66 | // inner class | ||
| 67 | if (!(mappingStack.peek() instanceof ClassMapping)) { | ||
| 68 | throw new MappingParseException(lineNumber, "Unexpected CLASS entry here!"); | ||
| 69 | } | ||
| 70 | |||
| 71 | classMapping = readClass(parts); | ||
| 72 | ((ClassMapping) mappingStack.peek()).addInnerClassMapping(classMapping); | ||
| 73 | } | ||
| 74 | mappingStack.push(classMapping); | ||
| 75 | } else if (token.equalsIgnoreCase("FIELD")) { | ||
| 76 | if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { | ||
| 77 | throw new MappingParseException(lineNumber, "Unexpected FIELD entry here!"); | ||
| 78 | } | ||
| 79 | ((ClassMapping) mappingStack.peek()).addFieldMapping(readField(parts)); | ||
| 80 | } else if (token.equalsIgnoreCase("METHOD")) { | ||
| 81 | if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { | ||
| 82 | throw new MappingParseException(lineNumber, "Unexpected METHOD entry here!"); | ||
| 83 | } | ||
| 84 | MethodMapping methodMapping = readMethod(parts); | ||
| 85 | ((ClassMapping) mappingStack.peek()).addMethodMapping(methodMapping); | ||
| 86 | mappingStack.push(methodMapping); | ||
| 87 | } else if (token.equalsIgnoreCase("ARG")) { | ||
| 88 | if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof MethodMapping)) { | ||
| 89 | throw new MappingParseException(lineNumber, "Unexpected ARG entry here!"); | ||
| 90 | } | ||
| 91 | ((MethodMapping) mappingStack.peek()).addArgumentMapping(readArgument(parts)); | ||
| 92 | } | ||
| 93 | } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) { | ||
| 94 | throw new MappingParseException(lineNumber, "Malformed line:\n" + line); | ||
| 95 | } catch (MappingConflict e) { | ||
| 96 | e.printStackTrace(); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | return mappings; | ||
| 101 | } | ||
| 102 | |||
| 103 | private ArgumentMapping readArgument(String[] parts) { | ||
| 104 | return new ArgumentMapping(Integer.parseInt(parts[1]), parts[2]); | ||
| 105 | } | ||
| 106 | |||
| 107 | private ClassMapping readClass(String[] parts) { | ||
| 108 | if (parts.length == 2) { | ||
| 109 | return new ClassMapping(parts[1]); | ||
| 110 | } else { | ||
| 111 | return new ClassMapping(parts[1], parts[2]); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | /* TEMP */ | ||
| 116 | protected FieldMapping readField(String[] parts) { | ||
| 117 | return new FieldMapping(parts[1], new Type(parts[3]), parts[2]); | ||
| 118 | } | ||
| 119 | |||
| 120 | private MethodMapping readMethod(String[] parts) { | ||
| 121 | if (parts.length == 3) { | ||
| 122 | return new MethodMapping(parts[1], new Signature(parts[2])); | ||
| 123 | } else { | ||
| 124 | return new MethodMapping(parts[1], new Signature(parts[3]), parts[2]); | ||
| 125 | } | ||
| 126 | } | ||
| 127 | } | ||