-
-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...buddy-dep/src/main/java/net/bytebuddy/implementation/bind/annotation/DynamicConstant.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
26 changes: 26 additions & 0 deletions
26
.../src/test/java-11/net/bytebuddy/test/precompiled/v11/MethodDelegationDynamicConstant.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,26 @@ | ||
package net.bytebuddy.test.precompiled.v11; | ||
|
||
import net.bytebuddy.implementation.bind.annotation.DynamicConstant; | ||
import net.bytebuddy.utility.JavaConstant; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
public class MethodDelegationDynamicConstant { | ||
|
||
public MethodDelegationDynamicConstant foo() { | ||
return null; | ||
} | ||
|
||
public static MethodDelegationDynamicConstant intercept(@DynamicConstant( | ||
bootstrapType = JavaConstant.MethodHandle.HandleType.INVOKE_STATIC, | ||
bootstrapName = "constantdynamic", | ||
bootstrapOwner = MethodDelegationDynamicConstant.class, | ||
bootstrapReturnType = MethodDelegationDynamicConstant.class, | ||
bootstrapParameterTypes = {MethodHandles.Lookup.class, String.class, Object[].class}) MethodDelegationDynamicConstant constant) throws Throwable { | ||
return constant; | ||
} | ||
|
||
public static MethodDelegationDynamicConstant constantdynamic(MethodHandles.Lookup lookup, String name, Object... args) { | ||
return new MethodDelegationDynamicConstant(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ep/src/test/java-7/net/bytebuddy/test/precompiled/v7/MethodDelegationDynamicConstant.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,29 @@ | ||
package net.bytebuddy.test.precompiled.v7; | ||
|
||
import net.bytebuddy.implementation.bind.annotation.DynamicConstant; | ||
import net.bytebuddy.utility.JavaConstant; | ||
|
||
import java.lang.invoke.CallSite; | ||
import java.lang.invoke.ConstantCallSite; | ||
import java.lang.invoke.MethodHandles; | ||
|
||
public class MethodDelegationDynamicConstant { | ||
|
||
public MethodDelegationDynamicConstant foo() { | ||
return null; | ||
} | ||
|
||
public static MethodDelegationDynamicConstant intercept(@DynamicConstant( | ||
bootstrapType = JavaConstant.MethodHandle.HandleType.INVOKE_STATIC, | ||
bootstrapName = "invokedynamic", | ||
bootstrapOwner = MethodDelegationDynamicConstant.class, | ||
bootstrapReturnType = CallSite.class, | ||
bootstrapParameterTypes = Object[].class, | ||
invokedynamic = true) MethodDelegationDynamicConstant constant) throws Throwable { | ||
return constant; | ||
} | ||
|
||
public static CallSite invokedynamic(Object... args) { | ||
return new ConstantCallSite(MethodHandles.constant(MethodDelegationDynamicConstant.class, new MethodDelegationDynamicConstant())); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...y-dep/src/test/java/net/bytebuddy/implementation/MethodDelegationDynamicConstantTest.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,59 @@ | ||
package net.bytebuddy.implementation; | ||
|
||
import net.bytebuddy.ByteBuddy; | ||
import net.bytebuddy.dynamic.DynamicType; | ||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; | ||
import net.bytebuddy.implementation.bind.annotation.RuntimeType; | ||
import net.bytebuddy.implementation.bind.annotation.SuperCall; | ||
import net.bytebuddy.test.utility.CallTraceable; | ||
import net.bytebuddy.test.utility.JavaVersionRule; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.MethodRule; | ||
|
||
import java.io.Serializable; | ||
import java.lang.reflect.Method; | ||
import java.util.concurrent.Callable; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isDeclaredBy; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class MethodDelegationDynamicConstantTest { | ||
private static final String FOO = "foo", BAR = "bar"; | ||
|
||
@Rule | ||
public MethodRule javaVersionRule = new JavaVersionRule(); | ||
|
||
@Test | ||
@JavaVersionRule.Enforce(7) | ||
public void testDynamicConstantInvokedynamic() throws Exception { | ||
Class<?> bootstrap = Class.forName("net.bytebuddy.test.precompiled.v7.MethodDelegationDynamicConstant"); | ||
Class<?> type = new ByteBuddy() | ||
.subclass(bootstrap) | ||
.method(isDeclaredBy(bootstrap)) | ||
.intercept(MethodDelegation.to(bootstrap)) | ||
.make() | ||
.load(bootstrap.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER) | ||
.getLoaded(); | ||
Object instance = type.getDeclaredConstructor().newInstance(); | ||
assertThat(type.getMethod(FOO).invoke(instance), instanceOf(bootstrap)); | ||
} | ||
|
||
@Test | ||
@JavaVersionRule.Enforce(11) | ||
public void testDynamicConstant() throws Exception { | ||
Class<?> bootstrap = Class.forName("net.bytebuddy.test.precompiled.v11.MethodDelegationDynamicConstant"); | ||
Class<?> type = new ByteBuddy() | ||
.subclass(bootstrap) | ||
.method(isDeclaredBy(bootstrap)) | ||
.intercept(MethodDelegation.to(bootstrap)) | ||
.make() | ||
.load(bootstrap.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER) | ||
.getLoaded(); | ||
Object instance = type.getDeclaredConstructor().newInstance(); | ||
assertThat(type.getMethod(FOO).invoke(instance), instanceOf(bootstrap)); | ||
} | ||
} |
Binary file added
BIN
+1.76 KB
...t/precompiled-11/net/bytebuddy/test/precompiled/v11/MethodDelegationDynamicConstant.class
Binary file not shown.
Binary file added
BIN
+1.71 KB
...est/precompiled-7/net/bytebuddy/test/precompiled/v7/MethodDelegationDynamicConstant.class
Binary file not shown.