Search in sources :

Example 41 with MethodDescription

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

the class AbstractTypeDescriptionGenericVariableDefiningTest method testMethodVariableT.

@Test
@SuppressWarnings("unchecked")
@JavaVersionRule.Enforce(8)
public void testMethodVariableT() throws Exception {
    Class<? extends Annotation> typeAnnotation = (Class<? extends Annotation>) Class.forName(TYPE_ANNOTATION);
    MethodDescription.InDefinedShape value = new TypeDescription.ForLoadedType(typeAnnotation).getDeclaredMethods().getOnly();
    MethodDescription methodDescription = describe(Class.forName(TYPE_ANNOTATION_SAMPLES)).getDeclaredMethods().filter(named(FOO)).getOnly();
    TypeDescription.Generic t = methodDescription.getTypeVariables().getOnly();
    assertThat(t.getSort(), is(TypeDefinition.Sort.VARIABLE));
    assertThat(t.getDeclaredAnnotations().size(), is(1));
    assertThat(t.getDeclaredAnnotations().isAnnotationPresent(typeAnnotation), is(true));
    assertThat(t.getDeclaredAnnotations().ofType(typeAnnotation).getValue(value).resolve(Integer.class), is(26));
    assertThat(t.getUpperBounds().getOnly().getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(t.getUpperBounds().getOnly().getDeclaredAnnotations().size(), is(1));
    assertThat(t.getUpperBounds().getOnly().getDeclaredAnnotations().isAnnotationPresent(typeAnnotation), is(true));
    assertThat(t.getUpperBounds().getOnly().getDeclaredAnnotations().ofType(typeAnnotation).getValue(value).resolve(Integer.class), is(27));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 42 with MethodDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription 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();
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) DynamicType(net.bytebuddy.dynamic.DynamicType) TypeDescription(net.bytebuddy.description.type.TypeDescription) ByteBuddy(net.bytebuddy.ByteBuddy) Callable(java.util.concurrent.Callable)

Example 43 with MethodDescription

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

the class JavaConstantMethodHandleTest method testMethodNotSpecializable.

@Test(expected = IllegalArgumentException.class)
public void testMethodNotSpecializable() throws Exception {
    MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
    TypeDescription typeDescription = mock(TypeDescription.class);
    when(methodDescription.isSpecializableFor(typeDescription)).thenReturn(false);
    JavaConstant.MethodHandle.ofSpecial(methodDescription, typeDescription);
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 44 with MethodDescription

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

the class TypePoolDefaultComponentPoolStrategyTest method testForAnnotationProperty.

@Test
public void testForAnnotationProperty() throws Exception {
    TypePool typePool = mock(TypePool.class);
    TypeDescription typeDescription = mock(TypeDescription.class);
    when(typePool.describe(BAR)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
    when(typeDescription.getDeclaredMethods()).thenReturn(new MethodList.Explicit<MethodDescription.InDefinedShape>(methodDescription));
    when(methodDescription.getActualName()).thenReturn(FOO);
    TypeDescription.Generic returnType = mock(TypeDescription.Generic.class);
    TypeDescription rawReturnType = mock(TypeDescription.class);
    when(returnType.asErasure()).thenReturn(rawReturnType);
    when(methodDescription.getReturnType()).thenReturn(returnType);
    TypeDescription rawComponentType = mock(TypeDescription.class);
    when(rawReturnType.getComponentType()).thenReturn(rawComponentType);
    when(rawComponentType.getName()).thenReturn(QUX);
    assertThat(new TypePool.Default.ComponentTypeLocator.ForAnnotationProperty(typePool, BAR_DESCRIPTOR).bind(FOO).lookup(), is(QUX));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) MethodList(net.bytebuddy.description.method.MethodList) Test(org.junit.Test)

Example 45 with MethodDescription

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

the class TypePoolDefaultLazyTypeContainmentTest method testDeclaredInMethodGetMethodIsNull.

@Test
@SuppressWarnings("unchecked")
public void testDeclaredInMethodGetMethodIsNull() throws Exception {
    MethodDescription methodDescription = mock(MethodDescription.class);
    when(methodDescription.getActualName()).thenReturn(BAR);
    when(methodDescription.getDescriptor()).thenReturn(QUX);
    TypeDescription typeDescription = mock(TypeDescription.class);
    TypePool typePool = mock(TypePool.class);
    when(typePool.describe(FOO)).thenReturn(new TypePool.Resolution.Simple(typeDescription));
    when(typeDescription.getDeclaredMethods()).thenReturn((MethodList) new MethodList.Explicit<MethodDescription>(methodDescription));
    assertThat(new TypePool.Default.LazyTypeDescription.TypeContainment.WithinMethod(FOO_INTERNAL, BAR, QUX).getEnclosingMethod(typePool), is(methodDescription));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Aggregations

MethodDescription (net.bytebuddy.description.method.MethodDescription)105 Test (org.junit.Test)102 TypeDescription (net.bytebuddy.description.type.TypeDescription)62 MethodVisitor (org.objectweb.asm.MethodVisitor)15 StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)12 MethodList (net.bytebuddy.description.method.MethodList)9 Implementation (net.bytebuddy.implementation.Implementation)8 AbstractImplementationTargetTest (net.bytebuddy.implementation.AbstractImplementationTargetTest)6 Serializable (java.io.Serializable)4 TypeVariableSource (net.bytebuddy.description.TypeVariableSource)4 FieldList (net.bytebuddy.description.field.FieldList)4 TypePool (net.bytebuddy.pool.TypePool)4 ClassVisitor (org.objectweb.asm.ClassVisitor)4 ByteBuddy (net.bytebuddy.ByteBuddy)3 DynamicType (net.bytebuddy.dynamic.DynamicType)3 AnnotationDescription (net.bytebuddy.description.annotation.AnnotationDescription)2 LoadedTypeInitializer (net.bytebuddy.implementation.LoadedTypeInitializer)2 ByteCodeAppender (net.bytebuddy.implementation.bytecode.ByteCodeAppender)2 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1