diff options
| author | 2019-12-05 15:45:36 +0200 | |
|---|---|---|
| committer | 2019-12-05 13:45:36 +0000 | |
| commit | 7ceb4a7668d4e13ed0f4e621f52c5fe974fd32a1 (patch) | |
| tree | 6c3b5cbccc273fdd3dd721eb7f3ef68a18a69a6a /src | |
| parent | Allow attaching class, method, field, and parameter javadocs (#185) (diff) | |
| download | enigma-7ceb4a7668d4e13ed0f4e621f52c5fe974fd32a1.tar.gz enigma-7ceb4a7668d4e13ed0f4e621f52c5fe974fd32a1.tar.xz enigma-7ceb4a7668d4e13ed0f4e621f52c5fe974fd32a1.zip | |
Fix comments (#187)
* fix comments
* indent
Diffstat (limited to 'src')
3 files changed, 61 insertions, 1 deletions
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java b/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java index 2c993f44..fba93590 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java | |||
| @@ -18,6 +18,7 @@ import java.io.IOException; | |||
| 18 | import java.nio.file.Files; | 18 | import java.nio.file.Files; |
| 19 | import java.nio.file.Path; | 19 | import java.nio.file.Path; |
| 20 | import java.util.ArrayDeque; | 20 | import java.util.ArrayDeque; |
| 21 | import java.util.Arrays; | ||
| 21 | import java.util.Deque; | 22 | import java.util.Deque; |
| 22 | import java.util.List; | 23 | import java.util.List; |
| 23 | import java.util.Locale; | 24 | import java.util.Locale; |
| @@ -160,7 +161,8 @@ public enum EnigmaMappingsReader implements MappingsReader { | |||
| 160 | private void readJavadoc(MappingPair<?, RawEntryMapping> parent, String[] tokens) { | 161 | private void readJavadoc(MappingPair<?, RawEntryMapping> parent, String[] tokens) { |
| 161 | if (parent == null) | 162 | if (parent == null) |
| 162 | throw new IllegalStateException("Javadoc has no parent!"); | 163 | throw new IllegalStateException("Javadoc has no parent!"); |
| 163 | String jdLine = tokens.length > 1 ? tokens[1] : ""; // Empty string to concat | 164 | // Empty string to concat |
| 165 | String jdLine = tokens.length > 1 ? String.join(" ", Arrays.copyOfRange(tokens,1,tokens.length)) : ""; | ||
| 164 | if (parent.getMapping() == null) | 166 | if (parent.getMapping() == null) |
| 165 | throw new IllegalStateException("Javadoc requires a mapping!"); | 167 | throw new IllegalStateException("Javadoc requires a mapping!"); |
| 166 | parent.getMapping().addJavadocLine(MappingHelper.unescape(jdLine)); | 168 | parent.getMapping().addJavadocLine(MappingHelper.unescape(jdLine)); |
diff --git a/src/test/java/cuchaz/enigma/mapping/TestComments.java b/src/test/java/cuchaz/enigma/mapping/TestComments.java new file mode 100644 index 00000000..b3a60056 --- /dev/null +++ b/src/test/java/cuchaz/enigma/mapping/TestComments.java | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | package cuchaz.enigma.mapping; | ||
| 2 | |||
| 3 | import java.io.IOException; | ||
| 4 | import java.net.URISyntaxException; | ||
| 5 | import java.nio.file.Path; | ||
| 6 | import java.nio.file.Paths; | ||
| 7 | |||
| 8 | import cuchaz.enigma.ProgressListener; | ||
| 9 | import cuchaz.enigma.throwables.MappingParseException; | ||
| 10 | import cuchaz.enigma.translation.mapping.EntryMapping; | ||
| 11 | import cuchaz.enigma.translation.mapping.MappingFileNameFormat; | ||
| 12 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 13 | import cuchaz.enigma.translation.mapping.serde.EnigmaMappingsReader; | ||
| 14 | import cuchaz.enigma.translation.mapping.serde.TinyV2Writer; | ||
| 15 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | ||
| 16 | import org.junit.Test; | ||
| 17 | |||
| 18 | public class TestComments { | ||
| 19 | private static Path DIRECTORY; | ||
| 20 | |||
| 21 | static { | ||
| 22 | try { | ||
| 23 | DIRECTORY = Paths.get(TestTinyV2InnerClasses.class.getResource("/comments/").toURI()); | ||
| 24 | } catch (URISyntaxException e) { | ||
| 25 | throw new RuntimeException(e); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | @Test | ||
| 30 | public void testParseAndWrite() throws IOException, MappingParseException { | ||
| 31 | ProgressListener progressListener = ProgressListener.none(); | ||
| 32 | MappingSaveParameters params = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); | ||
| 33 | EntryTree<EntryMapping> mappings = EnigmaMappingsReader.DIRECTORY.read( | ||
| 34 | DIRECTORY, progressListener, params); | ||
| 35 | |||
| 36 | new TinyV2Writer("intermediary", "named") | ||
| 37 | .write(mappings, DIRECTORY.resolve("convertedtiny.tiny"), progressListener, params); | ||
| 38 | } | ||
| 39 | |||
| 40 | } \ No newline at end of file | ||
diff --git a/src/test/resources/comments/test.mapping b/src/test/resources/comments/test.mapping new file mode 100644 index 00000000..d1345583 --- /dev/null +++ b/src/test/resources/comments/test.mapping | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | CLASS net/minecraft/class_1158 net/minecraft/util/math/Quaternion | ||
| 2 | COMMENT it circel | ||
| 3 | COMMENT next line | ||
| 4 | FIELD field_21493 IDENTITY Lnet/minecraft/class_1158; | ||
| 5 | COMMENT moar comment thing | ||
| 6 | COMMENT near field | ||
| 7 | METHOD foo bar (FFFF)V | ||
| 8 | COMMENT method comment | ||
| 9 | COMMENT second line | ||
| 10 | COMMENT third line | ||
| 11 | ARG 1 b | ||
| 12 | COMMENT arg comment | ||
| 13 | CLASS old new | ||
| 14 | COMMENT inner comment | ||
| 15 | FIELD field_19263 iterator Lnet/minecraft/class_3980; | ||
| 16 | METHOD tryAdvance (Ljava/util/function/Consumer;)Z | ||
| 17 | ARG 1 consumer | ||
| 18 | COMMENT very inner comment \ No newline at end of file | ||