Skip to content

Commit eb3a2ac

Browse files
committed
Add more slightly more complex test case for many redirects
1 parent 773bfa7 commit eb3a2ac

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package io.github.notstirred.dasm.test.tests.combined_field_method_redirects;
22

3-
import io.github.notstirred.dasm.test.targets.CubePos;
3+
import io.github.notstirred.dasm.test.targets.Vec3i;
44

55
public class CombinedFieldMethodRedirectsInput {
66
void method1() {
7-
CubePos.fromLong(0);
7+
Vec3i pos1 = new Vec3i(0);
8+
System.out.println(pos1.x + ", " + pos1.y + ", " + pos1.z + ", long:" + pos1.asLong());
9+
Vec3i pos2 = new Vec3i(pos1.getX() + 1, pos1.getY() + 1, pos1.getZ() + 1);
10+
System.out.println(pos2);
11+
}
12+
13+
void method2() {
14+
Vec3i pos1 = new Vec3i(0);
15+
System.out.println(pos1.x + ", " + pos1.y + ", " + pos1.z + ", long:" + pos1.asLong());
16+
Vec3i pos2 = new Vec3i(new Vec3i(0).getX() + 1, new Vec3i(0).getY() + 1, new Vec3i(0).getZ() + 1);
17+
System.out.println(pos2);
818
}
919
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
package io.github.notstirred.dasm.test.tests.combined_field_method_redirects;
22

33
import io.github.notstirred.dasm.test.targets.CubePos;
4-
import io.github.notstirred.dasm.test.tests.add_to_sets.TestAddToSets;
4+
import io.github.notstirred.dasm.test.targets.Vec3i;
55

66
public class CombinedFieldMethodRedirectsOutput {
77
void method1() {
8-
CubePos.fromLong(0);
8+
Vec3i pos1 = new Vec3i(0);
9+
System.out.println(pos1.x + ", " + pos1.y + ", " + pos1.z + ", long:" + pos1.asLong());
10+
Vec3i pos2 = new Vec3i(pos1.getX() + 1, pos1.getY() + 1, pos1.getZ() + 1);
11+
System.out.println(pos2);
12+
}
13+
14+
void method2() {
15+
Vec3i pos1 = new Vec3i(0);
16+
System.out.println(pos1.x + ", " + pos1.y + ", " + pos1.z + ", long:" + pos1.asLong());
17+
Vec3i pos2 = new Vec3i(new Vec3i(0).getX() + 1, new Vec3i(0).getY() + 1, new Vec3i(0).getZ() + 1);
18+
System.out.println(pos2);
919
}
1020

1121
void method1out() {
12-
TestAddToSets.testFoo(0);
22+
CubePos pos1 = CubePos.from(0);
23+
System.out.println(pos1.x + ", " + pos1.y + ", " + pos1.z + ", long:" + pos1.asLong());
24+
CubePos pos2 = new CubePos(pos1.x() + 1, pos1.y() + 1, pos1.z() + 1);
25+
System.out.println(pos2);
26+
}
27+
28+
void method2out() {
29+
CubePos pos1 = CubePos.from(0);
30+
System.out.println(pos1.x + ", " + pos1.y + ", " + pos1.z + ", long:" + pos1.asLong());
31+
CubePos pos2 = new CubePos(CubePos.from(0).x() + 1, CubePos.from(0).y() + 1, CubePos.from(0).z() + 1);
32+
System.out.println(pos2);
1333
}
1434
}

src/test/java/io/github/notstirred/dasm/test/tests/combined_field_method_redirects/TestCombinedFieldMethodRedirects.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33

44
import io.github.notstirred.dasm.api.annotations.Dasm;
55
import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddMethodToSets;
6+
import io.github.notstirred.dasm.api.annotations.redirect.redirects.ConstructorToFactoryRedirect;
7+
import io.github.notstirred.dasm.api.annotations.redirect.redirects.MethodRedirect;
68
import io.github.notstirred.dasm.api.annotations.redirect.redirects.TypeRedirect;
79
import io.github.notstirred.dasm.api.annotations.redirect.sets.RedirectSet;
10+
import io.github.notstirred.dasm.api.annotations.selector.ConstructorMethodSig;
811
import io.github.notstirred.dasm.api.annotations.selector.MethodSig;
912
import io.github.notstirred.dasm.api.annotations.selector.Ref;
1013
import io.github.notstirred.dasm.api.annotations.transform.TransformFromMethod;
1114
import io.github.notstirred.dasm.test.targets.CubePos;
15+
import io.github.notstirred.dasm.test.targets.Vec3i;
1216
import io.github.notstirred.dasm.test.tests.BaseMethodTest;
1317

1418
import static io.github.notstirred.dasm.test.tests.TestData.single;
1519

1620
/**
1721
* A trivial test for a static {@link AddMethodToSets}
1822
*/
19-
@Dasm(io.github.notstirred.dasm.test.tests.add_to_sets.TestAddToSets.Set.class)
23+
@Dasm(TestCombinedFieldMethodRedirects.Set.class)
2024
public class TestCombinedFieldMethodRedirects extends BaseMethodTest {
2125
public TestCombinedFieldMethodRedirects() {
2226
super(single(CombinedFieldMethodRedirectsInput.class, CombinedFieldMethodRedirectsOutput.class, TestCombinedFieldMethodRedirects.class));
@@ -25,13 +29,28 @@ public TestCombinedFieldMethodRedirects() {
2529
@TransformFromMethod(value = @MethodSig("method1()V"))
2630
native String method1out();
2731

32+
@TransformFromMethod(value = @MethodSig("method2()V"))
33+
native String method2out();
34+
2835
@RedirectSet
2936
public interface Set {
30-
@TypeRedirect(from = @Ref(Object.class), to = @Ref(String.class))
31-
abstract class A { }
37+
@TypeRedirect(from = @Ref(Vec3i.class), to = @Ref(CubePos.class))
38+
abstract class A {
39+
@MethodRedirect(@MethodSig(name = "getX", args = { }, ret = @Ref(int.class)))
40+
native int x();
41+
42+
@MethodRedirect(@MethodSig(name = "getY", args = { }, ret = @Ref(int.class)))
43+
native int y();
44+
45+
@MethodRedirect(@MethodSig(name = "getZ", args = { }, ret = @Ref(int.class)))
46+
native int z();
47+
48+
@ConstructorToFactoryRedirect(@ConstructorMethodSig(args = { @Ref(long.class) }))
49+
native CubePos from();
50+
}
3251
}
3352

34-
@AddMethodToSets(owner = @Ref(CubePos.class), method = @MethodSig(name = "fromLong", ret = @Ref(CubePos.class), args = { @Ref(long.class) }), sets = io.github.notstirred.dasm.test.tests.add_to_sets.TestAddToSets.Set.class)
53+
@AddMethodToSets(owner = @Ref(CubePos.class), method = @MethodSig(name = "fromLong", ret = @Ref(CubePos.class), args = { @Ref(long.class) }), sets = Set.class)
3554
public static CubePos testFoo(long l) {
3655
return null;
3756
}

0 commit comments

Comments
 (0)