Skip to content

Commit 0537ff7

Browse files
committed
fix class parsing for enigma format
1 parent 3dcd89c commit 0537ff7

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/RawEntryMapping.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import cuchaz.enigma.translation.mapping.EntryMapping;
44

5+
import javax.annotation.Nullable;
56
import java.util.ArrayList;
67
import java.util.List;
78

89
public final class RawEntryMapping {
910
private final String targetName;
1011
private final List<String> javadocs = new ArrayList<>();
1112

12-
public RawEntryMapping(String targetName) {
13+
public RawEntryMapping(@Nullable String targetName) {
1314
this.targetName = targetName != null && !targetName.equals("-") ? targetName : null;
1415
}
1516

enigma/src/main/java/cuchaz/enigma/translation/mapping/serde/enigma/EnigmaMappingsReader.java

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Deque;
3333
import java.util.List;
3434
import java.util.Locale;
35+
import java.util.stream.Stream;
3536

3637
public enum EnigmaMappingsReader implements MappingsReader {
3738
FILE {
@@ -56,10 +57,13 @@ public EntryTree<EntryMapping> read(Path root, ProgressListener progress, Mappin
5657

5758
EntryTree<EntryMapping> mappings = new HashEntryTree<>();
5859

59-
List<Path> files = Files.walk(root)
60+
List<Path> files;
61+
try (Stream<Path> fileStream = Files.walk(root)) {
62+
files = fileStream
6063
.filter(f -> !Files.isDirectory(f))
6164
.filter(f -> f.toString().endsWith(".mapping"))
6265
.toList();
66+
}
6367

6468
progress.init(files.size(), I18n.translate("progress.mappings.enigma_directory.loading"));
6569
int step = 0;
@@ -85,34 +89,6 @@ public EntryTree<EntryMapping> read(Path zip, ProgressListener progress, Mapping
8589
}
8690
};
8791

88-
/**
89-
* Reads multiple Enigma mapping files.
90-
*
91-
* @param progress the progress listener
92-
* @param paths the Enigma files to read; cannot be empty
93-
* @return the parsed mappings
94-
* @throws MappingParseException if a mapping file cannot be parsed
95-
* @throws IOException if an IO error occurs
96-
* @throws IllegalArgumentException if there are no paths to read
97-
*/
98-
public static EntryTree<EntryMapping> readFiles(ProgressListener progress, Path... paths) throws MappingParseException, IOException {
99-
EntryTree<EntryMapping> mappings = new HashEntryTree<>();
100-
101-
if (paths.length == 0) {
102-
throw new IllegalArgumentException("No paths to read mappings from");
103-
}
104-
105-
progress.init(paths.length, I18n.translate("progress.mappings.enigma_directory.loading"));
106-
int step = 0;
107-
108-
for (Path file : paths) {
109-
progress.step(step++, paths.toString());
110-
readFile(file, mappings);
111-
}
112-
113-
return mappings;
114-
}
115-
11692
private static void readFile(Path path, EntryTree<EntryMapping> mappings) throws IOException, MappingParseException {
11793
List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
11894
Deque<MappingPair<?, RawEntryMapping>> mappingStack = new ArrayDeque<>();
@@ -245,7 +221,12 @@ private static MappingPair<ClassEntry, RawEntryMapping> parseClass(@Nullable Ent
245221
obfuscatedEntry = new ClassEntry(obfuscatedName);
246222
}
247223

248-
String mapping = tokens[2];
224+
String mapping = null;
225+
if (tokens.length == 3) {
226+
mapping = tokens[2];
227+
} else if (tokens.length != 2) {
228+
throw new RuntimeException("invalid class declaration: not enough tokens (" + tokens.length + " found, 2 needed)!");
229+
}
249230

250231
return new MappingPair<>(obfuscatedEntry, new RawEntryMapping(mapping));
251232
}

0 commit comments

Comments
 (0)