summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Thog2016-08-24 09:30:15 +0200
committerGravatar Thog2016-08-24 09:30:15 +0200
commitd809895279cfff0f5331227def82633158e05218 (patch)
tree7fa1721d01ee7bc8919866847b51742767fdff85 /src
parentOnly use moveClassTree for ClassEntry (Fix #10) (diff)
downloadenigma-d809895279cfff0f5331227def82633158e05218.tar.gz
enigma-d809895279cfff0f5331227def82633158e05218.tar.xz
enigma-d809895279cfff0f5331227def82633158e05218.zip
Add file path in MappingParseException message
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java17
-rw-r--r--src/main/java/cuchaz/enigma/throwables/MappingParseException.java8
2 files changed, 15 insertions, 10 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java
index 692bd818..33eae6cb 100644
--- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java
+++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java
@@ -23,7 +23,7 @@ public class MappingsEnigmaReader
23 else 23 else
24 { 24 {
25 mappings = new Mappings(); 25 mappings = new Mappings();
26 readFile(mappings, new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))); 26 readFile(mappings, file);
27 } 27 }
28 return mappings; 28 return mappings;
29 } 29 }
@@ -33,7 +33,7 @@ public class MappingsEnigmaReader
33 if (files != null) { 33 if (files != null) {
34 for (File file : files) { 34 for (File file : files) {
35 if (file.isFile() && !file.getName().startsWith(".") && file.getName().endsWith(".mapping")) 35 if (file.isFile() && !file.getName().startsWith(".") && file.getName().endsWith(".mapping"))
36 readFile(mappings, new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))); 36 readFile(mappings, file);
37 else if (file.isDirectory()) 37 else if (file.isDirectory())
38 readDirectory(mappings, file.getAbsoluteFile()); 38 readDirectory(mappings, file.getAbsoluteFile());
39 } 39 }
@@ -42,8 +42,9 @@ public class MappingsEnigmaReader
42 throw new IOException("Cannot access directory" + directory.getAbsolutePath()); 42 throw new IOException("Cannot access directory" + directory.getAbsolutePath());
43 } 43 }
44 44
45 public Mappings readFile(Mappings mappings, BufferedReader in) throws IOException, MappingParseException { 45 public Mappings readFile(Mappings mappings, File file) throws IOException, MappingParseException {
46 46
47 BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8));
47 Deque<Object> mappingStack = Queues.newArrayDeque(); 48 Deque<Object> mappingStack = Queues.newArrayDeque();
48 49
49 int lineNumber = 0; 50 int lineNumber = 0;
@@ -91,7 +92,7 @@ public class MappingsEnigmaReader
91 92
92 // inner class 93 // inner class
93 if (!(mappingStack.peek() instanceof ClassMapping)) { 94 if (!(mappingStack.peek() instanceof ClassMapping)) {
94 throw new MappingParseException(lineNumber, "Unexpected CLASS entry here!"); 95 throw new MappingParseException(file, lineNumber, "Unexpected CLASS entry here!");
95 } 96 }
96 97
97 classMapping = readClass(parts, true); 98 classMapping = readClass(parts, true);
@@ -100,24 +101,24 @@ public class MappingsEnigmaReader
100 mappingStack.push(classMapping); 101 mappingStack.push(classMapping);
101 } else if (token.equalsIgnoreCase("FIELD")) { 102 } else if (token.equalsIgnoreCase("FIELD")) {
102 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { 103 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) {
103 throw new MappingParseException(lineNumber, "Unexpected FIELD entry here!"); 104 throw new MappingParseException(file, lineNumber, "Unexpected FIELD entry here!");
104 } 105 }
105 ((ClassMapping) mappingStack.peek()).addFieldMapping(readField(parts)); 106 ((ClassMapping) mappingStack.peek()).addFieldMapping(readField(parts));
106 } else if (token.equalsIgnoreCase("METHOD")) { 107 } else if (token.equalsIgnoreCase("METHOD")) {
107 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { 108 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) {
108 throw new MappingParseException(lineNumber, "Unexpected METHOD entry here!"); 109 throw new MappingParseException(file, lineNumber, "Unexpected METHOD entry here!");
109 } 110 }
110 MethodMapping methodMapping = readMethod(parts); 111 MethodMapping methodMapping = readMethod(parts);
111 ((ClassMapping) mappingStack.peek()).addMethodMapping(methodMapping); 112 ((ClassMapping) mappingStack.peek()).addMethodMapping(methodMapping);
112 mappingStack.push(methodMapping); 113 mappingStack.push(methodMapping);
113 } else if (token.equalsIgnoreCase("ARG")) { 114 } else if (token.equalsIgnoreCase("ARG")) {
114 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof MethodMapping)) { 115 if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof MethodMapping)) {
115 throw new MappingParseException(lineNumber, "Unexpected ARG entry here!"); 116 throw new MappingParseException(file, lineNumber, "Unexpected ARG entry here!");
116 } 117 }
117 ((MethodMapping) mappingStack.peek()).addArgumentMapping(readArgument(parts)); 118 ((MethodMapping) mappingStack.peek()).addArgumentMapping(readArgument(parts));
118 } 119 }
119 } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) { 120 } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) {
120 throw new MappingParseException(lineNumber, "Malformed line:\n" + line); 121 throw new MappingParseException(file, lineNumber, "Malformed line:\n" + line);
121 } catch (MappingConflict e) { 122 } catch (MappingConflict e) {
122 e.printStackTrace(); 123 e.printStackTrace();
123 } 124 }
diff --git a/src/main/java/cuchaz/enigma/throwables/MappingParseException.java b/src/main/java/cuchaz/enigma/throwables/MappingParseException.java
index 93ae2fda..18dff277 100644
--- a/src/main/java/cuchaz/enigma/throwables/MappingParseException.java
+++ b/src/main/java/cuchaz/enigma/throwables/MappingParseException.java
@@ -10,18 +10,22 @@
10 ******************************************************************************/ 10 ******************************************************************************/
11package cuchaz.enigma.throwables; 11package cuchaz.enigma.throwables;
12 12
13import java.io.File;
14
13public class MappingParseException extends Exception { 15public class MappingParseException extends Exception {
14 16
15 private int m_line; 17 private int m_line;
16 private String m_message; 18 private String m_message;
19 private String filePath;
17 20
18 public MappingParseException(int line, String message) { 21 public MappingParseException(File file, int line, String message) {
19 m_line = line; 22 m_line = line;
20 m_message = message; 23 m_message = message;
24 filePath = file.getAbsolutePath();
21 } 25 }
22 26
23 @Override 27 @Override
24 public String getMessage() { 28 public String getMessage() {
25 return "Line " + m_line + ": " + m_message; 29 return "Line " + m_line + ": " + m_message + " in file " + filePath;
26 } 30 }
27} 31}