diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsReader.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsReader.java | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java index 7aedc5b..b2b6d09 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java | |||
| @@ -20,17 +20,17 @@ import java.io.FileReader; | |||
| 20 | import java.io.IOException; | 20 | import java.io.IOException; |
| 21 | 21 | ||
| 22 | import cuchaz.enigma.json.JsonClass; | 22 | import cuchaz.enigma.json.JsonClass; |
| 23 | import cuchaz.enigma.throwables.MappingConflict; | ||
| 23 | 24 | ||
| 24 | public class MappingsReader { | 25 | public class MappingsReader { |
| 25 | 26 | ||
| 26 | public Mappings read(File in) throws IOException, MappingParseException { | 27 | public Mappings read(File in) throws IOException { |
| 27 | Mappings mappings = new Mappings(); | 28 | Mappings mappings = new Mappings(); |
| 28 | readDirectory(mappings, in); | 29 | readDirectory(mappings, in); |
| 29 | return mappings; | 30 | return mappings; |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | public void readDirectory(Mappings mappings, File in) throws IOException, MappingParseException { | 33 | public void readDirectory(Mappings mappings, File in) throws IOException { |
| 33 | |||
| 34 | File[] fList = in.listFiles(); | 34 | File[] fList = in.listFiles(); |
| 35 | if (fList != null) { | 35 | if (fList != null) { |
| 36 | for (File file : fList) { | 36 | for (File file : fList) { |
| @@ -43,8 +43,7 @@ public class MappingsReader { | |||
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | public void readFile(Mappings mappings, BufferedReader in) throws IOException, MappingParseException { | 46 | public void readFile(Mappings mappings, BufferedReader in) throws IOException { |
| 47 | |||
| 48 | StringBuilder buf = new StringBuilder(); | 47 | StringBuilder buf = new StringBuilder(); |
| 49 | String line; | 48 | String line; |
| 50 | while ((line = in.readLine()) != null) { | 49 | while ((line = in.readLine()) != null) { |
| @@ -53,11 +52,15 @@ public class MappingsReader { | |||
| 53 | 52 | ||
| 54 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); | 53 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); |
| 55 | JsonClass jsonClass = gson.fromJson(buf.toString(), JsonClass.class); | 54 | JsonClass jsonClass = gson.fromJson(buf.toString(), JsonClass.class); |
| 56 | load(null, jsonClass, mappings); | 55 | try { |
| 56 | load(null, jsonClass, mappings); | ||
| 57 | } catch (MappingConflict e) { | ||
| 58 | e.printStackTrace(); | ||
| 59 | } | ||
| 57 | in.close(); | 60 | in.close(); |
| 58 | } | 61 | } |
| 59 | 62 | ||
| 60 | public void load(ClassMapping parent, JsonClass jsonClass, Mappings mappings) { | 63 | public void load(ClassMapping parent, JsonClass jsonClass, Mappings mappings) throws MappingConflict { |
| 61 | ClassMapping classMapping = readClass(jsonClass.getObf(), jsonClass.getName()); | 64 | ClassMapping classMapping = readClass(jsonClass.getObf(), jsonClass.getName()); |
| 62 | if (parent != null) { | 65 | if (parent != null) { |
| 63 | parent.addInnerClassMapping(classMapping); | 66 | parent.addInnerClassMapping(classMapping); |
| @@ -68,17 +71,35 @@ public class MappingsReader { | |||
| 68 | 71 | ||
| 69 | jsonClass.getConstructors().forEach(jsonConstructor -> { | 72 | jsonClass.getConstructors().forEach(jsonConstructor -> { |
| 70 | MethodMapping methodMapping = readMethod(jsonConstructor.isStatics() ? "<clinit>" : "<init>", null, jsonConstructor.getSignature()); | 73 | MethodMapping methodMapping = readMethod(jsonConstructor.isStatics() ? "<clinit>" : "<init>", null, jsonConstructor.getSignature()); |
| 71 | jsonConstructor.getArgs().forEach(jsonArgument -> methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName()))); | 74 | jsonConstructor.getArgs().forEach(jsonArgument -> { |
| 75 | try { | ||
| 76 | methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName())); | ||
| 77 | } catch (MappingConflict e) { | ||
| 78 | e.printStackTrace(); | ||
| 79 | } | ||
| 80 | }); | ||
| 72 | classMapping.addMethodMapping(methodMapping); | 81 | classMapping.addMethodMapping(methodMapping); |
| 73 | }); | 82 | }); |
| 74 | 83 | ||
| 75 | jsonClass.getMethod().forEach(jsonMethod -> { | 84 | jsonClass.getMethod().forEach(jsonMethod -> { |
| 76 | MethodMapping methodMapping = readMethod(jsonMethod.getObf(), jsonMethod.getName(), jsonMethod.getSignature()); | 85 | MethodMapping methodMapping = readMethod(jsonMethod.getObf(), jsonMethod.getName(), jsonMethod.getSignature()); |
| 77 | jsonMethod.getArgs().forEach(jsonArgument -> methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName()))); | 86 | jsonMethod.getArgs().forEach(jsonArgument -> { |
| 87 | try { | ||
| 88 | methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName())); | ||
| 89 | } catch (MappingConflict e) { | ||
| 90 | e.printStackTrace(); | ||
| 91 | } | ||
| 92 | }); | ||
| 78 | classMapping.addMethodMapping(methodMapping); | 93 | classMapping.addMethodMapping(methodMapping); |
| 79 | }); | 94 | }); |
| 80 | 95 | ||
| 81 | jsonClass.getInnerClass().forEach(jsonInnerClasses -> load(classMapping, jsonInnerClasses, mappings)); | 96 | jsonClass.getInnerClass().forEach(jsonInnerClasses -> { |
| 97 | try { | ||
| 98 | load(classMapping, jsonInnerClasses, mappings); | ||
| 99 | } catch (MappingConflict e) { | ||
| 100 | e.printStackTrace(); | ||
| 101 | } | ||
| 102 | }); | ||
| 82 | } | 103 | } |
| 83 | 104 | ||
| 84 | private ArgumentMapping readArgument(int index, String name) { | 105 | private ArgumentMapping readArgument(int index, String name) { |