use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType in project byte-buddy by raphw.
the class TrivialTypeTest method testPlain.
@Test
public void testPlain() throws Exception {
when(classFileVersion.getMinorMajorVersion()).thenReturn(ClassFileVersion.JAVA_V5.getMinorMajorVersion());
DynamicType dynamicType = TrivialType.PLAIN.make(FOO, classFileVersion, methodAccessorFactory);
assertThat(dynamicType.getTypeDescription().getName(), is(FOO));
assertThat(dynamicType.getTypeDescription().getModifiers(), is(Opcodes.ACC_SYNTHETIC));
assertThat(dynamicType.getTypeDescription().getDeclaredAnnotations().size(), is(0));
assertThat(dynamicType.getAuxiliaryTypes().size(), is(0));
assertThat(dynamicType.getLoadedTypeInitializers().get(dynamicType.getTypeDescription()).isAlive(), is(false));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType in project byte-buddy by raphw.
the class ClassInjectorUsingInstrumentationTest method testSystemInjection.
@Test
@AgentAttachmentRule.Enforce
public void testSystemInjection() throws Exception {
ClassInjector classInjector = ClassInjector.UsingInstrumentation.of(folder, ClassInjector.UsingInstrumentation.Target.SYSTEM, ByteBuddyAgent.install());
String name = BAR + RandomString.make();
DynamicType dynamicType = new ByteBuddy().subclass(Object.class).name(name).make();
Map<TypeDescription, Class<?>> types = classInjector.inject(Collections.singletonMap(dynamicType.getTypeDescription(), dynamicType.getBytes()));
assertThat(types.size(), is(1));
assertThat(types.get(dynamicType.getTypeDescription()).getName(), is(name));
assertThat(types.get(dynamicType.getTypeDescription()).getClassLoader(), is(ClassLoader.getSystemClassLoader()));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType in project byte-buddy by raphw.
the class MethodCallProxy method make.
@Override
public DynamicType make(String auxiliaryTypeName, ClassFileVersion classFileVersion, MethodAccessorFactory methodAccessorFactory) {
MethodDescription accessorMethod = methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT);
LinkedHashMap<String, TypeDescription> parameterFields = extractFields(accessorMethod);
DynamicType.Builder<?> builder = new ByteBuddy(classFileVersion).with(PrecomputedMethodGraph.INSTANCE).subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS).name(auxiliaryTypeName).modifiers(DEFAULT_TYPE_MODIFIER).implement(Runnable.class, Callable.class).intercept(new MethodCall(accessorMethod, assigner)).implement(serializableProxy ? new Class<?>[] { Serializable.class } : new Class<?>[0]).defineConstructor().withParameters(parameterFields.values()).intercept(ConstructorCall.INSTANCE);
for (Map.Entry<String, TypeDescription> field : parameterFields.entrySet()) {
builder = builder.defineField(field.getKey(), field.getValue(), Visibility.PRIVATE);
}
return builder.make();
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapWithArrayArgumentsWithoutArguments.
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapWithArrayArgumentsWithoutArguments() throws Exception {
Class<?> type = Class.forName(PARAMETER_BOOTSTRAP);
Field field = type.getDeclaredField(ARGUMENTS_FIELD_NAME);
field.set(null, null);
TypeDescription typeDescription = new TypeDescription.ForLoadedType(type);
DynamicType.Loaded<Simple> dynamicType = new ByteBuddy().subclass(Simple.class).method(isDeclaredBy(Simple.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP_ARRAY_ARGUMENTS)).getOnly()).withoutArguments()).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(), is(FOO));
Object[] arguments = (Object[]) field.get(null);
assertThat(arguments.length, is(0));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapWithImplicitArgument.
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapWithImplicitArgument() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
DynamicType.Loaded<SimpleWithArgument> dynamicType = new ByteBuddy().subclass(SimpleWithArgument.class).method(isDeclaredBy(SimpleWithArgument.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly()).invoke(QUX, String.class).withMethodArguments()).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredFields().length, is(0));
assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(FOO), is(FOO));
}
Aggregations