Search in sources :

Example 36 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 AbstractTypeDescriptionGenericTest method testShadowedMethodTypeVariableIsRetained.

@Test
public void testShadowedMethodTypeVariableIsRetained() throws Exception {
    TypeDescription.Generic typeDescription = describeType(MemberVariable.class.getDeclaredField(FOO));
    assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(typeDescription.getTypeArguments().size(), is(2));
    assertThat(typeDescription.getTypeArguments().get(0).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(typeDescription.getTypeArguments().get(0).asErasure().represents(Number.class), is(true));
    assertThat(typeDescription.getTypeArguments().get(1).getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(typeDescription.getTypeArguments().get(1).asErasure().represents(Integer.class), is(true));
    MethodDescription methodDescription = typeDescription.getDeclaredMethods().filter(named(BAR)).getOnly();
    assertThat(methodDescription.getReturnType().getSort(), is(TypeDefinition.Sort.VARIABLE));
    assertThat(methodDescription.getReturnType().getSymbol(), is("T"));
    assertThat(methodDescription.getReturnType().getTypeVariableSource(), is((TypeVariableSource) methodDescription.asDefined()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeVariableSource(net.bytebuddy.description.TypeVariableSource) Test(org.junit.Test)

Example 37 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 AbstractTypeDescriptionGenericTest method testMethodTypeVariableErasedBound.

@Test
public void testMethodTypeVariableErasedBound() throws Exception {
    TypeDescription.Generic typeDescription = describeType(MemberVariable.class.getDeclaredField(BAR)).getSuperClass();
    assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    MethodDescription methodDescription = typeDescription.getDeclaredMethods().filter(named(FOO)).getOnly();
    assertThat(methodDescription.getReturnType().getSort(), is(TypeDefinition.Sort.NON_GENERIC));
    assertThat(methodDescription.getReturnType().asErasure(), is(TypeDescription.OBJECT));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) Test(org.junit.Test)

Example 38 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 TransformerForMethodTest method testSimpleTransformation.

@Test
public void testSimpleTransformation() throws Exception {
    when(tokenTransformer.transform(instrumentedType, methodToken)).thenReturn(methodToken);
    MethodDescription transformed = new Transformer.ForMethod(tokenTransformer).transform(instrumentedType, methodDescription);
    assertThat(transformed.getDeclaringType(), is((TypeDefinition) declaringType));
    assertThat(transformed.getInternalName(), is(FOO));
    assertThat(transformed.getModifiers(), is(MODIFIERS));
    assertThat(transformed.getReturnType(), is(returnType));
    assertThat(transformed.getTypeVariables().size(), is(1));
    assertThat(transformed.getTypeVariables().getOnly().getSymbol(), is(QUX));
    assertThat(transformed.getExceptionTypes().size(), is(1));
    assertThat(transformed.getExceptionTypes().getOnly(), is(exceptionType));
    assertThat(transformed.getDeclaredAnnotations(), is(Collections.singletonList(methodAnnotation)));
    assertThat(transformed.getParameters().size(), is(1));
    assertThat(transformed.getParameters().getOnly().getType(), is(parameterType));
    assertThat(transformed.getParameters().getOnly().getName(), is(BAR));
    assertThat(transformed.getParameters().getOnly().getModifiers(), is(MODIFIERS * 2));
    assertThat(transformed.getParameters().getOnly().getDeclaredAnnotations().size(), is(1));
    assertThat(transformed.getParameters().getOnly().getDeclaredAnnotations().getOnly(), is(parameterAnnotation));
    assertThat(transformed.getParameters().getOnly().asDefined(), is(definedParameter));
    assertThat(transformed.getParameters().getOnly().getDeclaredAnnotations(), is(Collections.singletonList(parameterAnnotation)));
    assertThat(transformed.getParameters().getOnly().getDeclaringMethod(), is(transformed));
    assertThat(transformed.asDefined(), is(definedMethod));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDefinition(net.bytebuddy.description.type.TypeDefinition) Test(org.junit.Test)

Example 39 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 TransformerForMethodTest method testNoChangesUnlessSpecified.

@Test
public void testNoChangesUnlessSpecified() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
    MethodDescription methodDescription = typeDescription.getSuperClass().getDeclaredMethods().filter(named(FOO)).getOnly();
    MethodDescription transformed = Transformer.ForMethod.withModifiers().transform(typeDescription, methodDescription);
    assertThat(transformed, is(methodDescription));
    assertThat(transformed.getModifiers(), is(methodDescription.getModifiers()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 40 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 TransformerForMethodTest method testRetainsInstrumentedType.

@Test
public void testRetainsInstrumentedType() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Bar.class);
    MethodDescription methodDescription = typeDescription.getSuperClass().getDeclaredMethods().filter(named(BAR)).getOnly();
    MethodDescription transformed = Transformer.ForMethod.withModifiers().transform(typeDescription, methodDescription);
    assertThat(transformed, is(methodDescription));
    assertThat(transformed.getModifiers(), is(methodDescription.getModifiers()));
    assertThat(transformed.getReturnType().asErasure(), is(typeDescription));
    assertThat(transformed.getReturnType().getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
    assertThat(transformed.getReturnType().getTypeArguments().size(), is(1));
    assertThat(transformed.getReturnType().getTypeArguments().getOnly(), is(typeDescription.getSuperClass().getDeclaredMethods().filter(named(FOO)).getOnly().getReturnType()));
}
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