use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapWithExplicitArgumentsWithoutArgumentsThrowsException.
@Test(expected = IllegalArgumentException.class)
@JavaVersionRule.Enforce(7)
public void testBootstrapWithExplicitArgumentsWithoutArgumentsThrowsException() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(PARAMETER_BOOTSTRAP));
InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP_EXPLICIT_ARGUMENTS)).getOnly()).withoutArguments();
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapWithFieldCreation.
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapWithFieldCreation() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
DynamicType.Loaded<Simple> dynamicType = new ByteBuddy().subclass(Simple.class).defineField(FOO, String.class).method(isDeclaredBy(Simple.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly()).invoke(QUX, String.class).withField(FOO)).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredFields().length, is(1));
Simple instance = dynamicType.getLoaded().getDeclaredConstructor().newInstance();
Field field = dynamicType.getLoaded().getDeclaredField(FOO);
field.setAccessible(true);
field.set(instance, FOO);
assertThat(instance.foo(), is(FOO));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapWithFieldExplicitType.
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapWithFieldExplicitType() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
DynamicType.Loaded<Simple> dynamicType = new ByteBuddy().subclass(Simple.class).defineField(FOO, Object.class).method(isDeclaredBy(Simple.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly()).invoke(QUX, String.class).withField(FOO).as(String.class).withAssigner(Assigner.DEFAULT, Assigner.Typing.DYNAMIC)).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredFields().length, is(1));
Simple instance = dynamicType.getLoaded().getDeclaredConstructor().newInstance();
Field field = dynamicType.getLoaded().getDeclaredField(FOO);
field.setAccessible(true);
field.set(instance, FOO);
assertThat(instance.foo(), is(FOO));
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testGenericSuperClassNavigatedHierarchyResolutionIsLazy.
@Test
public void testGenericSuperClassNavigatedHierarchyResolutionIsLazy() throws Exception {
ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
assertThat(describe(GenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()).getSuperClass().getSuperClass().asErasure(), CoreMatchers.is((TypeDescription) new TypeDescription.ForLoadedType(SuperClass.class)));
verify(classFileLocator).locate(GenericType.class.getName());
verify(classFileLocator).locate(SampleGenericClass.class.getName());
verifyNoMoreInteractions(classFileLocator);
}
use of net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.
the class TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testGenericSuperClassHierarchyResolutionIsLazy.
@Test
public void testGenericSuperClassHierarchyResolutionIsLazy() throws Exception {
ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
assertThat(describe(GenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()).getSuperClass().asErasure(), CoreMatchers.is((TypeDescription) new TypeDescription.ForLoadedType(SampleGenericClass.class)));
verify(classFileLocator).locate(GenericType.class.getName());
verifyNoMoreInteractions(classFileLocator);
}
Aggregations