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