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()));
}
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));
}
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));
}
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()));
}
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()));
}
Aggregations