From 9d52ada9d7714c95ca3d1fbd408498100ab5e01b Mon Sep 17 00:00:00 2001 From: Iota <47987888+IotaBread@users.noreply.github.com> Date: Thu, 4 Jan 2024 22:09:29 -0300 Subject: [PATCH] Resolve the correct amount of entries when renaming a method (#174) * Interface union tests * Resolve the correct amount of entries when renaming a method * Add an extra test * Fix checkstyle errors * Add a comment * Fix another checkstyle error * Move #newVC to TestUtil --- .../translation/mapping/EntryRemapper.java | 41 ++++++- .../input/interface_union/AInterface.java | 11 ++ .../input/interface_union/BInterface.java | 11 ++ .../enigma/input/interface_union/CClass.java | 15 +++ .../input/interface_union/DInterface.java | 5 + .../input/interface_union/Union1Class.java | 31 ++++++ .../input/interface_union/Union2Class.java | 20 ++++ .../input/interface_union/Union3Record.java | 14 +++ .../input/interface_union/Union4Class.java | 5 + .../mapping/EntryRemapperTest.java | 103 ++++++++++++++++++ .../mapping/TestMappingValidator.java | 75 +++++-------- .../java/org/quiltmc/enigma/TestUtil.java | 20 ++++ 12 files changed, 304 insertions(+), 47 deletions(-) create mode 100644 enigma/src/test/java/org/quiltmc/enigma/input/interface_union/AInterface.java create mode 100644 enigma/src/test/java/org/quiltmc/enigma/input/interface_union/BInterface.java create mode 100644 enigma/src/test/java/org/quiltmc/enigma/input/interface_union/CClass.java create mode 100644 enigma/src/test/java/org/quiltmc/enigma/input/interface_union/DInterface.java create mode 100644 enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union1Class.java create mode 100644 enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union2Class.java create mode 100644 enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union3Record.java create mode 100644 enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union4Class.java create mode 100644 enigma/src/test/java/org/quiltmc/enigma/translation/mapping/EntryRemapperTest.java diff --git a/enigma/src/main/java/org/quiltmc/enigma/api/translation/mapping/EntryRemapper.java b/enigma/src/main/java/org/quiltmc/enigma/api/translation/mapping/EntryRemapper.java index 50fd3314d..2b908a43b 100644 --- a/enigma/src/main/java/org/quiltmc/enigma/api/translation/mapping/EntryRemapper.java +++ b/enigma/src/main/java/org/quiltmc/enigma/api/translation/mapping/EntryRemapper.java @@ -1,6 +1,7 @@ package org.quiltmc.enigma.api.translation.mapping; import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex; +import org.quiltmc.enigma.api.analysis.index.jar.InheritanceIndex; import org.quiltmc.enigma.api.analysis.index.jar.JarIndex; import org.quiltmc.enigma.api.analysis.index.mapping.MappingsIndex; import org.quiltmc.enigma.api.service.NameProposalService; @@ -19,9 +20,12 @@ import org.quiltmc.enigma.util.validation.Message; import org.quiltmc.enigma.util.validation.ValidationContext; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.Objects; import java.util.List; +import java.util.Set; import java.util.stream.Stream; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -83,7 +87,7 @@ private void doPutMapping(ValidationContext vc, Entry obfuscatedEntry, @Nonnu EntryMapping oldMapping = this.getMapping(obfuscatedEntry); boolean renaming = !Objects.equals(oldMapping.targetName(), deobfMapping.targetName()); - Collection> resolvedEntries = this.obfResolver.resolveEntry(obfuscatedEntry, renaming ? ResolutionStrategy.RESOLVE_ROOT : ResolutionStrategy.RESOLVE_CLOSEST); + Collection> resolvedEntries = renaming ? this.resolveAllRoots(obfuscatedEntry) : this.obfResolver.resolveEntry(obfuscatedEntry, ResolutionStrategy.RESOLVE_CLOSEST); if (renaming && deobfMapping.targetName() != null) { for (Entry resolvedEntry : resolvedEntries) { @@ -105,6 +109,41 @@ private void doPutMapping(ValidationContext vc, Entry obfuscatedEntry, @Nonnu this.mappingsIndex.reindexEntry(deobfMapping, obfuscatedEntry); } + private Collection> resolveAllRoots(Entry obfuscatedEntry) { + if (!(obfuscatedEntry instanceof MethodEntry methodEntry)) { + return this.obfResolver.resolveEntry(obfuscatedEntry, ResolutionStrategy.RESOLVE_ROOT); + } + + InheritanceIndex inheritanceIndex = this.jarIndex.getIndex(InheritanceIndex.class); + var owner = methodEntry.getParent(); + var descendants = inheritanceIndex.getDescendants(owner); + var knownParents = new HashSet<>(inheritanceIndex.getParents(owner)); + + // Find all classes with an "unknown" parent, so we can also resolve the method from there and find other definitions + // If interfaces A and B define method `void foo()`, a class C may implement both interfaces, having a single method `void foo()` + // and effectively "joining" the two interface methods, so you have to keep both "in sync" + List classes = new ArrayList<>(); + for (ClassEntry descendant : descendants) { + var parents = inheritanceIndex.getParents(descendant); + if (parents.size() > 1) { // one of them is one of the owner's descendants + Set otherParents = new HashSet<>(parents); + otherParents.removeAll(descendants); + otherParents.removeAll(knownParents); + if (!otherParents.isEmpty()) { + classes.add(descendant); + knownParents.addAll(otherParents); + } + } + } + + Set> resolution = new HashSet<>(this.obfResolver.resolveEntry(obfuscatedEntry, ResolutionStrategy.RESOLVE_ROOT)); + for (ClassEntry clazz : classes) { + resolution.addAll(this.obfResolver.resolveEntry(methodEntry.withParent(clazz), ResolutionStrategy.RESOLVE_ROOT)); + } + + return resolution; + } + // todo this needs to be fixed for hashed mappings! // note: just supressing warnings until it's fixed @SuppressWarnings("all") diff --git a/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/AInterface.java b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/AInterface.java new file mode 100644 index 000000000..40d2ea02b --- /dev/null +++ b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/AInterface.java @@ -0,0 +1,11 @@ +package org.quiltmc.enigma.input.interface_union; + +public interface AInterface { + int methodA(); + + // BInterface -> Union1Class + void methodFoo(); + + // -> Union3Record + double baz(); +} diff --git a/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/BInterface.java b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/BInterface.java new file mode 100644 index 000000000..ec4def7f1 --- /dev/null +++ b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/BInterface.java @@ -0,0 +1,11 @@ +package org.quiltmc.enigma.input.interface_union; + +public interface BInterface { + // AInterface -> Union1Class + void methodFoo(); + + double methodB(); + + // CClass -> Union2Class + boolean methodBar(); +} diff --git a/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/CClass.java b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/CClass.java new file mode 100644 index 000000000..62d069bcd --- /dev/null +++ b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/CClass.java @@ -0,0 +1,15 @@ +package org.quiltmc.enigma.input.interface_union; + +import java.util.Random; + +public class CClass { + // BInterface -> Union2Class + public boolean methodBar() { + return true; + } + + // DInterface -> Union4Class + public float factor() { + return (float) new Random().nextGaussian(); + } +} diff --git a/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/DInterface.java b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/DInterface.java new file mode 100644 index 000000000..5daab8997 --- /dev/null +++ b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/DInterface.java @@ -0,0 +1,5 @@ +package org.quiltmc.enigma.input.interface_union; + +public interface DInterface { + float factor(); +} diff --git a/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union1Class.java b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union1Class.java new file mode 100644 index 000000000..12b44ac84 --- /dev/null +++ b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union1Class.java @@ -0,0 +1,31 @@ +package org.quiltmc.enigma.input.interface_union; + +import java.util.Random; + +public class Union1Class implements AInterface, BInterface { + @Override + public int methodA() { + return 32767; + } + + // AInterface + BInterface + @Override + public void methodFoo() { + System.out.println("foo"); + } + + @Override + public double baz() { + return 200; + } + + @Override + public double methodB() { + return new Random().nextGaussian(); + } + + @Override + public boolean methodBar() { + return false; + } +} diff --git a/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union2Class.java b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union2Class.java new file mode 100644 index 000000000..d05702c37 --- /dev/null +++ b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union2Class.java @@ -0,0 +1,20 @@ +package org.quiltmc.enigma.input.interface_union; + +import java.util.Random; + +public class Union2Class extends CClass implements BInterface { + @Override + public void methodFoo() { + } + + @Override + public double methodB() { + return 6.02e23; + } + + // BInterface + CClass + @Override + public boolean methodBar() { + return new Random().nextExponential() > 2.0; + } +} diff --git a/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union3Record.java b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union3Record.java new file mode 100644 index 000000000..395cec021 --- /dev/null +++ b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union3Record.java @@ -0,0 +1,14 @@ +package org.quiltmc.enigma.input.interface_union; + +public record Union3Record(double baz) implements AInterface { + @Override + public int methodA() { + return -1; + } + + @Override + public void methodFoo() { + } + + // AInterface -> baz() +} diff --git a/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union4Class.java b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union4Class.java new file mode 100644 index 000000000..8d31b47fc --- /dev/null +++ b/enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union4Class.java @@ -0,0 +1,5 @@ +package org.quiltmc.enigma.input.interface_union; + +public class Union4Class extends CClass implements DInterface { + // DInterface.factor() implemented in CClass +} diff --git a/enigma/src/test/java/org/quiltmc/enigma/translation/mapping/EntryRemapperTest.java b/enigma/src/test/java/org/quiltmc/enigma/translation/mapping/EntryRemapperTest.java new file mode 100644 index 000000000..a14e48cb1 --- /dev/null +++ b/enigma/src/test/java/org/quiltmc/enigma/translation/mapping/EntryRemapperTest.java @@ -0,0 +1,103 @@ +package org.quiltmc.enigma.translation.mapping; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.quiltmc.enigma.TestEntryFactory; +import org.quiltmc.enigma.TestUtil; +import org.quiltmc.enigma.api.Enigma; +import org.quiltmc.enigma.api.EnigmaProject; +import org.quiltmc.enigma.api.ProgressListener; +import org.quiltmc.enigma.api.class_provider.ClasspathClassProvider; +import org.quiltmc.enigma.api.translation.mapping.EntryMapping; +import org.quiltmc.enigma.api.translation.mapping.EntryRemapper; +import org.quiltmc.enigma.api.translation.mapping.tree.EntryTree; +import org.quiltmc.enigma.api.translation.mapping.tree.HashEntryTree; +import org.quiltmc.enigma.api.translation.representation.entry.Entry; + +import java.nio.file.Path; + +public class EntryRemapperTest { + public static final Path JAR = TestUtil.obfJar("interface_union"); + private static EnigmaProject project; + private static EntryRemapper remapper; + + @BeforeAll + public static void beforeAll() throws Exception { + Enigma enigma = Enigma.create(); + project = enigma.openJar(JAR, new ClasspathClassProvider(), ProgressListener.none()); + remapper = project.getRemapper(); + } + + @BeforeEach + public void beforeEach() { + EntryTree mappings = new HashEntryTree<>(); + project.setMappings(mappings, ProgressListener.none()); + remapper = project.getRemapper(); + } + + private static void assertName(Entry entry, String expected) { + Entry deobf = remapper.deobfuscate(entry); + Assertions.assertNotNull(deobf); + Assertions.assertEquals(expected, deobf.getName()); + } + + @Test + public void testUnionRename() { + var name = "unionAB"; + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("e", "a", "()V"), new EntryMapping(name)); + + assertName(TestEntryFactory.newMethod("e", "a", "()V"), name); + assertName(TestEntryFactory.newMethod("a", "a", "()V"), name); + assertName(TestEntryFactory.newMethod("b", "a", "()V"), name); + + name = "unionBC"; + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("f", "a", "()Z"), new EntryMapping(name)); + + assertName(TestEntryFactory.newMethod("f", "a", "()Z"), name); + assertName(TestEntryFactory.newMethod("b", "a", "()Z"), name); + assertName(TestEntryFactory.newMethod("c", "a", "()Z"), name); + + name = "unionA3"; + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("g", "a", "()D"), new EntryMapping(name)); + + assertName(TestEntryFactory.newMethod("g", "a", "()D"), name); + assertName(TestEntryFactory.newMethod("a", "a", "()D"), name); + } + + @Test + public void testElementRename() { + var name = "unionAB"; + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("e", "a", "()V"), new EntryMapping(name)); + + assertName(TestEntryFactory.newMethod("a", "a", "()V"), name); + assertName(TestEntryFactory.newMethod("e", "a", "()V"), name); + assertName(TestEntryFactory.newMethod("b", "a", "()V"), name); + + name = "unionBC"; + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("b", "a", "()Z"), new EntryMapping(name)); + + assertName(TestEntryFactory.newMethod("b", "a", "()Z"), name); + assertName(TestEntryFactory.newMethod("f", "a", "()Z"), name); + assertName(TestEntryFactory.newMethod("c", "a", "()Z"), name); + + name = "unionA3"; + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("a", "a", "()D"), new EntryMapping(name)); + + assertName(TestEntryFactory.newMethod("a", "a", "()D"), name); + assertName(TestEntryFactory.newMethod("g", "a", "()D"), name); + + name = "unionCD"; + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("c", "a", "()F"), new EntryMapping(name)); + + assertName(TestEntryFactory.newMethod("c", "a", "()F"), name); + assertName(TestEntryFactory.newMethod("d", "a", "()F"), name); + + name = "unionDC"; + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("d", "a", "()F"), new EntryMapping(name)); + + assertName(TestEntryFactory.newMethod("d", "a", "()F"), name); + assertName(TestEntryFactory.newMethod("c", "a", "()F"), name); + } +} diff --git a/enigma/src/test/java/org/quiltmc/enigma/translation/mapping/TestMappingValidator.java b/enigma/src/test/java/org/quiltmc/enigma/translation/mapping/TestMappingValidator.java index 166812e50..af50af429 100644 --- a/enigma/src/test/java/org/quiltmc/enigma/translation/mapping/TestMappingValidator.java +++ b/enigma/src/test/java/org/quiltmc/enigma/translation/mapping/TestMappingValidator.java @@ -45,33 +45,33 @@ public void beforeEach(RepetitionInfo repetitionInfo) { // repeat with mapped classes if (repetitionInfo.getCurrentRepetition() == 1) { - remapper.putMapping(newVC(), TestEntryFactory.newClass("a"), new EntryMapping("BaseClass")); - remapper.putMapping(newVC(), TestEntryFactory.newClass("b"), new EntryMapping("SuperClass")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newClass("a"), new EntryMapping("BaseClass")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newClass("b"), new EntryMapping("SuperClass")); } } @RepeatedTest(value = 2, name = REPEATED_TEST_NAME) public void shadowPrivateFields() { // static fields - remapper.putMapping(newVC(), TestEntryFactory.newField("b", "a", "Ljava/lang/String;"), new EntryMapping("FIELD_00")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newField("b", "a", "Ljava/lang/String;"), new EntryMapping("FIELD_00")); - ValidationContext vc = new ValidationContext(notifier()); + ValidationContext vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newField("a", "c", "Ljava/lang/String;"), new EntryMapping("FIELD_00")); assertMessages(vc, Message.SHADOWED_NAME_CLASS); // final fields - remapper.putMapping(newVC(), TestEntryFactory.newField("b", "a", "I"), new EntryMapping("field01")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newField("b", "a", "I"), new EntryMapping("field01")); - vc = new ValidationContext(notifier()); + vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newField("a", "a", "I"), new EntryMapping("field01")); assertMessages(vc); // instance fields - remapper.putMapping(newVC(), TestEntryFactory.newField("b", "b", "I"), new EntryMapping("field02")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newField("b", "b", "I"), new EntryMapping("field02")); - vc = new ValidationContext(notifier()); + vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newField("a", "b", "I"), new EntryMapping("field02")); assertMessages(vc); @@ -80,17 +80,17 @@ public void shadowPrivateFields() { @RepeatedTest(value = 2, name = REPEATED_TEST_NAME) public void shadowPublicFields() { // static fields - remapper.putMapping(newVC(), TestEntryFactory.newField("b", "b", "Ljava/lang/String;"), new EntryMapping("FIELD_04")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newField("b", "b", "Ljava/lang/String;"), new EntryMapping("FIELD_04")); - ValidationContext vc = new ValidationContext(notifier()); + ValidationContext vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newField("a", "a", "Ljava/lang/String;"), new EntryMapping("FIELD_04")); assertMessages(vc, Message.SHADOWED_NAME_CLASS); // default fields - remapper.putMapping(newVC(), TestEntryFactory.newField("b", "b", "Z"), new EntryMapping("field05")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newField("b", "b", "Z"), new EntryMapping("field05")); - vc = new ValidationContext(notifier()); + vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newField("a", "a", "Z"), new EntryMapping("field05")); assertMessages(vc); @@ -99,17 +99,17 @@ public void shadowPublicFields() { @RepeatedTest(value = 2, name = REPEATED_TEST_NAME) public void shadowMethods() { // static methods - remapper.putMapping(newVC(), TestEntryFactory.newMethod("b", "c", "()V"), new EntryMapping("method01")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("b", "c", "()V"), new EntryMapping("method01")); - ValidationContext vc = new ValidationContext(notifier()); + ValidationContext vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newMethod("a", "a", "()V"), new EntryMapping("method01")); assertMessages(vc, Message.SHADOWED_NAME_CLASS); // private methods - remapper.putMapping(newVC(), TestEntryFactory.newMethod("b", "a", "()V"), new EntryMapping("method02")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("b", "a", "()V"), new EntryMapping("method02")); - vc = new ValidationContext(notifier()); + vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newMethod("a", "d", "()V"), new EntryMapping("method02")); assertMessages(vc); @@ -117,16 +117,16 @@ public void shadowMethods() { @RepeatedTest(value = 2, name = REPEATED_TEST_NAME) public void nonUniqueFields() { - remapper.putMapping(newVC(), TestEntryFactory.newField("a", "a", "I"), new EntryMapping("field01")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newField("a", "a", "I"), new EntryMapping("field01")); - ValidationContext vc = new ValidationContext(notifier()); + ValidationContext vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newField("a", "b", "I"), new EntryMapping("field01")); assertMessages(vc, Message.NON_UNIQUE_NAME_CLASS); - remapper.putMapping(newVC(), TestEntryFactory.newField("a", "c", "Ljava/lang/String;"), new EntryMapping("FIELD_02")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newField("a", "c", "Ljava/lang/String;"), new EntryMapping("FIELD_02")); - vc = new ValidationContext(notifier()); + vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newField("a", "a", "Ljava/lang/String;"), new EntryMapping("FIELD_02")); assertMessages(vc, Message.NON_UNIQUE_NAME_CLASS); @@ -134,14 +134,14 @@ public void nonUniqueFields() { @RepeatedTest(value = 2, name = REPEATED_TEST_NAME) public void nonUniqueMethods() { - remapper.putMapping(newVC(), TestEntryFactory.newMethod("a", "a", "()V"), new EntryMapping("method01")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("a", "a", "()V"), new EntryMapping("method01")); - ValidationContext vc = new ValidationContext(notifier()); + ValidationContext vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newMethod("a", "b", "()V"), new EntryMapping("method01")); assertMessages(vc, Message.NON_UNIQUE_NAME_CLASS); - vc = new ValidationContext(notifier()); + vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newMethod("a", "d", "()V"), new EntryMapping("method01")); assertMessages(vc, Message.NON_UNIQUE_NAME_CLASS); @@ -150,25 +150,25 @@ public void nonUniqueMethods() { @RepeatedTest(value = 2, name = REPEATED_TEST_NAME) public void conflictingMethods() { // "overriding" w/different return descriptor - remapper.putMapping(newVC(), TestEntryFactory.newMethod("b", "a", "()Z"), new EntryMapping("method01")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("b", "a", "()Z"), new EntryMapping("method01")); - ValidationContext vc = new ValidationContext(notifier()); + ValidationContext vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newMethod("a", "b", "()V"), new EntryMapping("method01")); assertMessages(vc, Message.NON_UNIQUE_NAME_CLASS); // "overriding" a static method - remapper.putMapping(newVC(), TestEntryFactory.newMethod("b", "c", "()V"), new EntryMapping("method02")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("b", "c", "()V"), new EntryMapping("method02")); - vc = new ValidationContext(notifier()); + vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newMethod("a", "b", "()V"), new EntryMapping("method02")); assertMessages(vc, Message.NON_UNIQUE_NAME_CLASS); // "overriding" when the original methods were not related - remapper.putMapping(newVC(), TestEntryFactory.newMethod("b", "b", "()I"), new EntryMapping("method03")); + remapper.putMapping(TestUtil.newVC(), TestEntryFactory.newMethod("b", "b", "()I"), new EntryMapping("method03")); - vc = new ValidationContext(notifier()); + vc = TestUtil.newVC(); remapper.validatePutMapping(vc, TestEntryFactory.newMethod("a", "a", "()I"), new EntryMapping("method03")); assertMessages(vc, Message.NON_UNIQUE_NAME_CLASS); @@ -187,21 +187,4 @@ private static void assertMessages(ValidationContext vc, Message... messages) { assertThat(msg.message(), is(messages[i])); } } - - private static ValidationContext newVC() { - return new ValidationContext(notifier()); - } - - private static ValidationContext.Notifier notifier() { - return new ValidationContext.Notifier() { - @Override - public void notify(ParameterizedMessage message) { - } - - @Override - public boolean verifyWarning(ParameterizedMessage message) { - return true; - } - }; - } } diff --git a/enigma/src/testFixtures/java/org/quiltmc/enigma/TestUtil.java b/enigma/src/testFixtures/java/org/quiltmc/enigma/TestUtil.java index bbcc4415a..71b526fed 100644 --- a/enigma/src/testFixtures/java/org/quiltmc/enigma/TestUtil.java +++ b/enigma/src/testFixtures/java/org/quiltmc/enigma/TestUtil.java @@ -1,5 +1,8 @@ package org.quiltmc.enigma; +import org.quiltmc.enigma.util.validation.ParameterizedMessage; +import org.quiltmc.enigma.util.validation.ValidationContext; + import java.net.URISyntaxException; import java.nio.file.Path; @@ -22,4 +25,21 @@ public static Path getResource(String name) { throw new RuntimeException(e); } } + + public static ValidationContext newVC() { + return new ValidationContext(notifier()); + } + + private static ValidationContext.Notifier notifier() { + return new ValidationContext.Notifier() { + @Override + public void notify(ParameterizedMessage message) { + } + + @Override + public boolean verifyWarning(ParameterizedMessage message) { + return true; + } + }; + } }