Skip to content

Commit

Permalink
@WithBridgeMethods(void.class) could produce better code (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Nov 18, 2022
1 parent 9040c38 commit a9035f4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void inject(ClassVisitor cv) {
if (hasAdapterMethod()) {
insertAdapterMethod(ga);
} else
if (castRequired) {
if (castRequired || returnType.equals(Type.VOID_TYPE)) {
ga.unbox(returnType);
} else {
ga.box(originalReturnType);
Expand Down
15 changes: 15 additions & 0 deletions injector/src/test/client/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
public class Main {
public static void main(String[] args) throws Exception {
// invocation of void method. verify that it runs without error

Foo.toggle = false;
Foo.hello();
assertEquals(true, Foo.toggle);

Foo.toggle = false;
Foo.hello2();
assertEquals(true, Foo.toggle);

Foo.toggle = false;
new Foo().hello3();
assertEquals(true, Foo.toggle);

Foo.toggle = false;
new Foo().hello4();
assertEquals(true, Foo.toggle);

Foo.unbox();
Foo.box();

Expand Down
18 changes: 16 additions & 2 deletions injector/src/test/v1/Foo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,23 @@ public static <T extends String> T methodToWiden(Class<T> clazz) {
return clazz.cast("foo");
}

public static void hello() {}
static boolean toggle;

public static void hello2() {}
public static void hello() {
toggle = true;
}

public static void hello2() {
toggle = true;
}

public void hello3() {
toggle = true;
}

public void hello4() {
toggle = true;
}

public static int unbox() {return Integer.MIN_VALUE;}

Expand Down
16 changes: 16 additions & 0 deletions injector/src/test/v2/Foo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,31 @@ public static <T> T methodToWiden(Class<T> clazz) {
return clazz.cast("bar");
}

static boolean toggle;

@WithBridgeMethods(void.class)
public static boolean hello() {
toggle = true;
return true;
}

@WithBridgeMethods(void.class)
public static String hello2() {
toggle = true;
return "hello2";
}

@WithBridgeMethods(void.class)
public boolean hello3() {
toggle = true;
return true;
}

@WithBridgeMethods(void.class)
public String hello4() {
toggle = true;
return "hello4";
}

@WithBridgeMethods(value=int.class, castRequired=true)
public static Integer unbox() {
Expand Down

0 comments on commit a9035f4

Please sign in to comment.