Search in sources :

Example 41 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.

the class MethodInvocationGenericTest method testGenericMethodDynamic.

@Test
public void testGenericMethodDynamic() throws Exception {
    TypeDescription genericErasure = mock(TypeDescription.class);
    when(methodReturnType.asErasure()).thenReturn(genericErasure);
    when(declaredMethod.isBootstrap()).thenReturn(true);
    StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList());
    assertThat(stackManipulation.isValid(), is(true));
    assertThat(stackManipulation, is(MethodInvocation.invoke(declaredMethod).dynamic(FOO, otherType, Collections.<TypeDescription>emptyList(), Collections.emptyList())));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 42 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.

the class MethodInvocationGenericTest method testGenericMethod.

@Test
public void testGenericMethod() throws Exception {
    TypeDescription genericErasure = mock(TypeDescription.class);
    when(methodReturnType.asErasure()).thenReturn(genericErasure);
    StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription);
    assertThat(stackManipulation.isValid(), is(true));
    assertThat(stackManipulation, is((StackManipulation) new MethodInvocation.OfGenericMethod(genericErasure, MethodInvocation.invoke(declaredMethod))));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 43 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.

the class FieldAccessOtherTest method testGenericFieldAccessGetterEqualErasure.

@Test
public void testGenericFieldAccessGetterEqualErasure() throws Exception {
    TypeDescription declaredErasure = mock(TypeDescription.class);
    when(genericType.asErasure()).thenReturn(declaredErasure);
    when(declaredType.asErasure()).thenReturn(declaredErasure);
    StackManipulation stackManipulation = FieldAccess.forField(genericField).read();
    assertThat(stackManipulation.isValid(), is(true));
    assertThat(stackManipulation, is(FieldAccess.forField(fieldDescription).read()));
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 44 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project byte-buddy by raphw.

the class TypeVariableSourceVisitorNoOpTest method testVisitType.

@Test
public void testVisitType() throws Exception {
    TypeDescription typeDescription = mock(TypeDescription.class);
    MatcherAssert.assertThat(TypeVariableSource.Visitor.NoOp.INSTANCE.onType(typeDescription), is((TypeVariableSource) typeDescription));
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 45 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription 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()));
}
Also used : DynamicType(net.bytebuddy.dynamic.DynamicType) ByteBuddy(net.bytebuddy.ByteBuddy) TypeDescription(net.bytebuddy.description.type.TypeDescription) RandomString(net.bytebuddy.utility.RandomString) Test(org.junit.Test)

Aggregations

TypeDescription (net.bytebuddy.description.type.TypeDescription)178 Test (org.junit.Test)155 MethodDescription (net.bytebuddy.description.method.MethodDescription)75 ByteBuddy (net.bytebuddy.ByteBuddy)25 DynamicType (net.bytebuddy.dynamic.DynamicType)25 StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)17 ClassFileLocator (net.bytebuddy.dynamic.ClassFileLocator)10 AnnotationList (net.bytebuddy.description.annotation.AnnotationList)9 AbstractTypeDescriptionTest (net.bytebuddy.description.type.AbstractTypeDescriptionTest)9 Map (java.util.Map)8 MethodList (net.bytebuddy.description.method.MethodList)8 Field (java.lang.reflect.Field)7 List (java.util.List)5 FieldDescription (net.bytebuddy.description.field.FieldDescription)5 LoadedTypeInitializer (net.bytebuddy.implementation.LoadedTypeInitializer)5 Serializable (java.io.Serializable)4 URLClassLoader (java.net.URLClassLoader)4 TypeList (net.bytebuddy.description.type.TypeList)4 Before (org.junit.Before)4 MethodVisitor (org.objectweb.asm.MethodVisitor)4