-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
12 changed files
with
304 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
enigma/src/test/java/org/quiltmc/enigma/input/interface_union/AInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.quiltmc.enigma.input.interface_union; | ||
|
||
public interface AInterface { | ||
int methodA(); | ||
|
||
// BInterface -> Union1Class | ||
void methodFoo(); | ||
|
||
// -> Union3Record | ||
double baz(); | ||
} |
11 changes: 11 additions & 0 deletions
11
enigma/src/test/java/org/quiltmc/enigma/input/interface_union/BInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.quiltmc.enigma.input.interface_union; | ||
|
||
public interface BInterface { | ||
// AInterface -> Union1Class | ||
void methodFoo(); | ||
|
||
double methodB(); | ||
|
||
// CClass -> Union2Class | ||
boolean methodBar(); | ||
} |
15 changes: 15 additions & 0 deletions
15
enigma/src/test/java/org/quiltmc/enigma/input/interface_union/CClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
enigma/src/test/java/org/quiltmc/enigma/input/interface_union/DInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.quiltmc.enigma.input.interface_union; | ||
|
||
public interface DInterface { | ||
float factor(); | ||
} |
31 changes: 31 additions & 0 deletions
31
enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union1Class.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union2Class.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union3Record.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
5 changes: 5 additions & 0 deletions
5
enigma/src/test/java/org/quiltmc/enigma/input/interface_union/Union4Class.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.quiltmc.enigma.input.interface_union; | ||
|
||
public class Union4Class extends CClass implements DInterface { | ||
// DInterface.factor() implemented in CClass | ||
} |
103 changes: 103 additions & 0 deletions
103
enigma/src/test/java/org/quiltmc/enigma/translation/mapping/EntryRemapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<EntryMapping> 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); | ||
} | ||
} |
Oops, something went wrong.