diff options
| author | 2015-02-09 12:17:26 -0500 | |
|---|---|---|
| committer | 2015-02-09 12:17:26 -0500 | |
| commit | 71ec7b53a1b4ecce0623dded1e445818a757b695 (patch) | |
| tree | 335c2c4bb5535d5b4bd51c2d448655297a4e2efd /src/cuchaz/enigma/mapping/MappingsReader.java | |
| parent | added types to fields (diff) | |
| download | enigma-fork-71ec7b53a1b4ecce0623dded1e445818a757b695.tar.gz enigma-fork-71ec7b53a1b4ecce0623dded1e445818a757b695.tar.xz enigma-fork-71ec7b53a1b4ecce0623dded1e445818a757b695.zip | |
add converter to update old mappings format
fix a few decompiler issues too
Diffstat (limited to 'src/cuchaz/enigma/mapping/MappingsReader.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/MappingsReader.java | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/cuchaz/enigma/mapping/MappingsReader.java b/src/cuchaz/enigma/mapping/MappingsReader.java index 1e7b6e3..bfb2731 100644 --- a/src/cuchaz/enigma/mapping/MappingsReader.java +++ b/src/cuchaz/enigma/mapping/MappingsReader.java | |||
| @@ -19,11 +19,13 @@ import com.google.common.collect.Queues; | |||
| 19 | 19 | ||
| 20 | public class MappingsReader { | 20 | public class MappingsReader { |
| 21 | 21 | ||
| 22 | public Mappings read(Reader in) throws IOException, MappingParseException { | 22 | public Mappings read(Reader in) |
| 23 | throws IOException, MappingParseException { | ||
| 23 | return read(new BufferedReader(in)); | 24 | return read(new BufferedReader(in)); |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | public Mappings read(BufferedReader in) throws IOException, MappingParseException { | 27 | public Mappings read(BufferedReader in) |
| 28 | throws IOException, MappingParseException { | ||
| 27 | Mappings mappings = new Mappings(); | 29 | Mappings mappings = new Mappings(); |
| 28 | Deque<Object> mappingStack = Queues.newArrayDeque(); | 30 | Deque<Object> mappingStack = Queues.newArrayDeque(); |
| 29 | 31 | ||
| @@ -64,42 +66,41 @@ public class MappingsReader { | |||
| 64 | 66 | ||
| 65 | if (token.equalsIgnoreCase("CLASS")) { | 67 | if (token.equalsIgnoreCase("CLASS")) { |
| 66 | ClassMapping classMapping; | 68 | ClassMapping classMapping; |
| 67 | if (indent == 0) { | 69 | if (indent <= 0) { |
| 68 | // outer class | 70 | // outer class |
| 69 | classMapping = readClass(parts, false); | 71 | classMapping = readClass(parts, false); |
| 70 | mappings.addClassMapping(classMapping); | 72 | mappings.addClassMapping(classMapping); |
| 71 | } else if (indent == 1) { | 73 | } else { |
| 74 | |||
| 72 | // inner class | 75 | // inner class |
| 73 | if (! (mappingStack.getFirst() instanceof ClassMapping)) { | 76 | if (!(mappingStack.peek() instanceof ClassMapping)) { |
| 74 | throw new MappingParseException(lineNumber, "Unexpected CLASS entry here!"); | 77 | throw new MappingParseException(lineNumber, "Unexpected CLASS entry here!"); |
| 75 | } | 78 | } |
| 76 | 79 | ||
| 77 | classMapping = readClass(parts, true); | 80 | classMapping = readClass(parts, true); |
| 78 | ((ClassMapping)mappingStack.getFirst()).addInnerClassMapping(classMapping); | 81 | ((ClassMapping)mappingStack.peek()).addInnerClassMapping(classMapping); |
| 79 | } else { | ||
| 80 | throw new MappingParseException(lineNumber, "Unexpected CLASS entry nesting!"); | ||
| 81 | } | 82 | } |
| 82 | mappingStack.push(classMapping); | 83 | mappingStack.push(classMapping); |
| 83 | } else if (token.equalsIgnoreCase("FIELD")) { | 84 | } else if (token.equalsIgnoreCase("FIELD")) { |
| 84 | if (mappingStack.isEmpty() || ! (mappingStack.getFirst() instanceof ClassMapping)) { | 85 | if (mappingStack.isEmpty() || ! (mappingStack.peek() instanceof ClassMapping)) { |
| 85 | throw new MappingParseException(lineNumber, "Unexpected FIELD entry here!"); | 86 | throw new MappingParseException(lineNumber, "Unexpected FIELD entry here!"); |
| 86 | } | 87 | } |
| 87 | ((ClassMapping)mappingStack.getFirst()).addFieldMapping(readField(parts)); | 88 | ((ClassMapping)mappingStack.peek()).addFieldMapping(readField(parts)); |
| 88 | } else if (token.equalsIgnoreCase("METHOD")) { | 89 | } else if (token.equalsIgnoreCase("METHOD")) { |
| 89 | if (mappingStack.isEmpty() || ! (mappingStack.getFirst() instanceof ClassMapping)) { | 90 | if (mappingStack.isEmpty() || ! (mappingStack.peek() instanceof ClassMapping)) { |
| 90 | throw new MappingParseException(lineNumber, "Unexpected METHOD entry here!"); | 91 | throw new MappingParseException(lineNumber, "Unexpected METHOD entry here!"); |
| 91 | } | 92 | } |
| 92 | MethodMapping methodMapping = readMethod(parts); | 93 | MethodMapping methodMapping = readMethod(parts); |
| 93 | ((ClassMapping)mappingStack.getFirst()).addMethodMapping(methodMapping); | 94 | ((ClassMapping)mappingStack.peek()).addMethodMapping(methodMapping); |
| 94 | mappingStack.push(methodMapping); | 95 | mappingStack.push(methodMapping); |
| 95 | } else if (token.equalsIgnoreCase("ARG")) { | 96 | } else if (token.equalsIgnoreCase("ARG")) { |
| 96 | if (mappingStack.isEmpty() || ! (mappingStack.getFirst() instanceof MethodMapping)) { | 97 | if (mappingStack.isEmpty() || ! (mappingStack.peek() instanceof MethodMapping)) { |
| 97 | throw new MappingParseException(lineNumber, "Unexpected ARG entry here!"); | 98 | throw new MappingParseException(lineNumber, "Unexpected ARG entry here!"); |
| 98 | } | 99 | } |
| 99 | ((MethodMapping)mappingStack.getFirst()).addArgumentMapping(readArgument(parts)); | 100 | ((MethodMapping)mappingStack.peek()).addArgumentMapping(readArgument(parts)); |
| 100 | } | 101 | } |
| 101 | } catch (ArrayIndexOutOfBoundsException | NumberFormatException ex) { | 102 | } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) { |
| 102 | throw new MappingParseException(lineNumber, "Malformed line!"); | 103 | throw new MappingParseException(lineNumber, "Malformed line:\n" + line); |
| 103 | } | 104 | } |
| 104 | } | 105 | } |
| 105 | 106 | ||
| @@ -118,7 +119,8 @@ public class MappingsReader { | |||
| 118 | } | 119 | } |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 121 | private FieldMapping readField(String[] parts) { | 122 | /* TEMP */ |
| 123 | protected FieldMapping readField(String[] parts) { | ||
| 122 | return new FieldMapping(parts[1], new Type(parts[3]), parts[2]); | 124 | return new FieldMapping(parts[1], new Type(parts[3]), parts[2]); |
| 123 | } | 125 | } |
| 124 | 126 | ||