diff --git a/enigma-cli/src/test/java/org/quiltmc/enigma/command/DropInvalidMappingsTest.java b/enigma-cli/src/test/java/org/quiltmc/enigma/command/DropInvalidMappingsTest.java index 7d1a492e..0ad911a7 100644 --- a/enigma-cli/src/test/java/org/quiltmc/enigma/command/DropInvalidMappingsTest.java +++ b/enigma-cli/src/test/java/org/quiltmc/enigma/command/DropInvalidMappingsTest.java @@ -19,6 +19,8 @@ public class DropInvalidMappingsTest extends CommandTest { private static final Path EMPTY_MAPPINGS_EXPECTED = EXPECTED_DIR.resolve("EmptyMappings.mapping"); private static final Path MAPPING_SAVE_INPUT = INPUT_DIR.resolve("MappingSave.mapping"); private static final Path MAPPING_SAVE_EXPECTED = EXPECTED_DIR.resolve("MappingSave.mapping"); + private static final Path DISCARD_INNER_CLASS_INPUT = INPUT_DIR.resolve("DiscardInnerClass.mapping"); + private static final Path DISCARD_INNER_CLASS_EXPECTED = EXPECTED_DIR.resolve("DiscardInnerClass.mapping"); @Test public void testInvalidMappings() throws Exception { @@ -55,4 +57,16 @@ public void testMappingSave() throws Exception { Assertions.assertEquals(expectedLines, actualLines); } + + @Test + public void testDiscardInnerClass() throws Exception { + Path resultFile = Files.createTempFile("discardInnerClass", ".mapping"); + + DropInvalidMappingsCommand.run(INNER_JAR, DISCARD_INNER_CLASS_INPUT, resultFile); + + String expectedLines = Files.readString(DISCARD_INNER_CLASS_EXPECTED); + String actualLines = Files.readString(resultFile); + + Assertions.assertEquals(expectedLines, actualLines); + } } diff --git a/enigma-cli/src/test/resources/drop_invalid_mappings/expected/DiscardInnerClass.mapping b/enigma-cli/src/test/resources/drop_invalid_mappings/expected/DiscardInnerClass.mapping new file mode 100644 index 00000000..f7672f72 --- /dev/null +++ b/enigma-cli/src/test/resources/drop_invalid_mappings/expected/DiscardInnerClass.mapping @@ -0,0 +1,4 @@ +CLASS f + CLASS a + CLASS a + FIELD a q I diff --git a/enigma-cli/src/test/resources/drop_invalid_mappings/expected/EmptyMappings.mapping b/enigma-cli/src/test/resources/drop_invalid_mappings/expected/EmptyMappings.mapping index 7b003e3f..e69de29b 100644 --- a/enigma-cli/src/test/resources/drop_invalid_mappings/expected/EmptyMappings.mapping +++ b/enigma-cli/src/test/resources/drop_invalid_mappings/expected/EmptyMappings.mapping @@ -1,4 +0,0 @@ -CLASS a - CLASS b - METHOD b (Ljava/lang/String;)V - ARG 2 nonEmpty diff --git a/enigma-cli/src/test/resources/drop_invalid_mappings/input/DiscardInnerClass.mapping b/enigma-cli/src/test/resources/drop_invalid_mappings/input/DiscardInnerClass.mapping new file mode 100644 index 00000000..a5d770a2 --- /dev/null +++ b/enigma-cli/src/test/resources/drop_invalid_mappings/input/DiscardInnerClass.mapping @@ -0,0 +1,6 @@ +CLASS f + CLASS a + CLASS a + FIELD a q I + CLASS a + FIELD a I diff --git a/enigma/src/main/java/org/quiltmc/enigma/impl/translation/mapping/MappingsChecker.java b/enigma/src/main/java/org/quiltmc/enigma/impl/translation/mapping/MappingsChecker.java index 71fe89bf..6660261e 100644 --- a/enigma/src/main/java/org/quiltmc/enigma/impl/translation/mapping/MappingsChecker.java +++ b/enigma/src/main/java/org/quiltmc/enigma/impl/translation/mapping/MappingsChecker.java @@ -118,15 +118,15 @@ private boolean hasNoMappedChildren(Entry entry, Dropped dropped) { if (!children.isEmpty()) { for (Entry child : children) { var mapping = this.mappings.get(child); - if (!dropped.getDroppedMappings().containsKey(child) - && mapping != null && mapping.tokenType() != TokenType.OBFUSCATED + if ((!dropped.getDroppedMappings().containsKey(child) + && mapping != null && mapping.tokenType() != TokenType.OBFUSCATED) || !this.hasNoMappedChildren(child, dropped)) { return false; } } } - return children.isEmpty(); + return true; } public static class Dropped {