Skip to content

Commit

Permalink
Adjust frames considering static methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Apr 3, 2016
1 parent 9cfea16 commit 8affca4
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java
Expand Up @@ -505,7 +505,18 @@ public void testFrameAdvice() throws Exception {
.make() .make()
.load(null, ClassLoadingStrategy.Default.WRAPPER) .load(null, ClassLoadingStrategy.Default.WRAPPER)
.getLoaded(); .getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.newInstance()), is((Object) FOO)); assertThat(type.getDeclaredMethod(FOO, String.class).invoke(type.newInstance(), FOO), is((Object) FOO));
}

@Test
public void testFrameAdviceStatic() throws Exception {
Class<?> type = new ByteBuddy()
.redefine(FrameSample.class)
.visit(Advice.to(FrameAdvice.class).on(named(FOO)))
.make()
.load(null, ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
assertThat(type.getDeclaredMethod(BAR, String.class).invoke(null, FOO), is((Object) FOO));
} }


@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -1292,9 +1303,8 @@ private static void exit(@Advice.Origin("\\#\\#\\\\#m") String origin) throws Ex


public static class FrameSample { public static class FrameSample {


public String foo() { public String foo(String value) {
int value = 0; switch (0) {
switch (value) {
case 0: { case 0: {
long a = 1L, b = 1L, c = 1L, d = 1L, e = 1L, f = 1L; long a = 1L, b = 1L, c = 1L, d = 1L, e = 1L, f = 1L;
} }
Expand All @@ -1308,15 +1318,33 @@ public String foo() {
long a = 1L; long a = 1L;
} }
long a = 1L; long a = 1L;
return FOO; return value;
}

public static String bar(String value) {
switch (0) {
case 0: {
long a = 1L, b = 1L, c = 1L, d = 1L, e = 1L, f = 1L;
}
default: {
long a = 1L;
}
}
try {
long a = 1L;
} catch (Exception ignored) {
long a = 1L;
}
long a = 1L;
return value;
} }
} }


public static class FrameAdvice { public static class FrameAdvice {


@Advice.OnMethodEnter @Advice.OnMethodEnter
@Advice.OnMethodExit @Advice.OnMethodExit
private static void enter(@Advice.Ignored int value) { private static String enter(@Advice.Ignored int value, @Advice.Argument(0) String pseudo) {
switch (value) { switch (value) {
case 0: { case 0: {
long a = 1L, b = 1L, c = 1L, d = 1L, e = 1L, f = 1L; long a = 1L, b = 1L, c = 1L, d = 1L, e = 1L, f = 1L;
Expand All @@ -1331,6 +1359,7 @@ private static void enter(@Advice.Ignored int value) {
long a = 1L; long a = 1L;
} }
long a = 1L; long a = 1L;
return pseudo;
} }
} }


Expand Down

0 comments on commit 8affca4

Please sign in to comment.