Search in sources :

Example 86 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 TypePoolDefaultWithLazyResolutionTypeDescriptionTest method testGenericSuperInterfaceHierarchyResolutionIsLazy.

@Test
public void testGenericSuperInterfaceHierarchyResolutionIsLazy() throws Exception {
    ClassFileLocator classFileLocator = spy(ClassFileLocator.ForClassLoader.ofClassPath());
    assertThat(describe(GenericType.class, classFileLocator, new TypePool.CacheProvider.Simple()).getInterfaces().getOnly().asErasure(), CoreMatchers.is((TypeDescription) new TypeDescription.ForLoadedType(SampleGenericInterface.class)));
    verify(classFileLocator).locate(GenericType.class.getName());
    verifyNoMoreInteractions(classFileLocator);
}
Also used : ClassFileLocator(net.bytebuddy.dynamic.ClassFileLocator) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test) AbstractTypeDescriptionTest(net.bytebuddy.description.type.AbstractTypeDescriptionTest)

Example 87 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 RebaseDynamicTypeBuilderTest method testObjectProperties.

@Test
public void testObjectProperties() throws Exception {
    ObjectPropertyAssertion.of(RebaseDynamicTypeBuilder.class).create(new ObjectPropertyAssertion.Creator<List<?>>() {

        @Override
        public List<?> create() {
            TypeDescription typeDescription = mock(TypeDescription.class);
            when(typeDescription.asErasure()).thenReturn(typeDescription);
            return Collections.singletonList(typeDescription);
        }
    }).create(new ObjectPropertyAssertion.Creator<TypeDescription>() {

        @Override
        public TypeDescription create() {
            TypeDescription rawTypeDescription = mock(TypeDescription.class);
            when(rawTypeDescription.asErasure()).thenReturn(rawTypeDescription);
            when(rawTypeDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
            when(rawTypeDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
            TypeDescription.Generic typeDescription = mock(TypeDescription.Generic.class);
            when(typeDescription.asGenericType()).thenReturn(typeDescription);
            when(typeDescription.asErasure()).thenReturn(rawTypeDescription);
            when(rawTypeDescription.getInterfaces()).thenReturn(new TypeList.Generic.Explicit(typeDescription));
            when(rawTypeDescription.getDeclaredFields()).thenReturn(new FieldList.Empty<FieldDescription.InDefinedShape>());
            when(rawTypeDescription.getDeclaredMethods()).thenReturn(new MethodList.Empty<MethodDescription.InDefinedShape>());
            return rawTypeDescription;
        }
    }).apply();
}
Also used : MethodList(net.bytebuddy.description.method.MethodList) AnnotationList(net.bytebuddy.description.annotation.AnnotationList) FieldList(net.bytebuddy.description.field.FieldList) TypeDescription(net.bytebuddy.description.type.TypeDescription) AnnotationList(net.bytebuddy.description.annotation.AnnotationList) TypeList(net.bytebuddy.description.type.TypeList) MethodList(net.bytebuddy.description.method.MethodList) List(java.util.List) FieldList(net.bytebuddy.description.field.FieldList) ObjectPropertyAssertion(net.bytebuddy.test.utility.ObjectPropertyAssertion) Test(org.junit.Test)

Example 88 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 RedefinitionDynamicTypeBuilderTest method testObjectProperties.

@Test
@SuppressWarnings("unchecked")
public void testObjectProperties() throws Exception {
    ObjectPropertyAssertion.of(RedefinitionDynamicTypeBuilder.class).create(new ObjectPropertyAssertion.Creator<List<?>>() {

        @Override
        public List<?> create() {
            TypeDescription typeDescription = mock(TypeDescription.class);
            when(typeDescription.asErasure()).thenReturn(typeDescription);
            return Collections.singletonList(typeDescription);
        }
    }).create(new ObjectPropertyAssertion.Creator<TypeDescription>() {

        @Override
        public TypeDescription create() {
            TypeDescription rawTypeDescription = mock(TypeDescription.class);
            when(rawTypeDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
            when(rawTypeDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
            TypeDescription.Generic typeDescription = mock(TypeDescription.Generic.class);
            when(typeDescription.asErasure()).thenReturn(rawTypeDescription);
            when(typeDescription.asGenericType()).thenReturn(typeDescription);
            when(rawTypeDescription.getInterfaces()).thenReturn(new TypeList.Generic.Explicit(typeDescription));
            when(rawTypeDescription.getDeclaredFields()).thenReturn(new FieldList.Empty<FieldDescription.InDefinedShape>());
            when(rawTypeDescription.getDeclaredMethods()).thenReturn(new MethodList.Empty<MethodDescription.InDefinedShape>());
            return rawTypeDescription;
        }
    }).apply();
}
Also used : MethodList(net.bytebuddy.description.method.MethodList) AnnotationList(net.bytebuddy.description.annotation.AnnotationList) FieldList(net.bytebuddy.description.field.FieldList) TypeDescription(net.bytebuddy.description.type.TypeDescription) AnnotationList(net.bytebuddy.description.annotation.AnnotationList) TypeList(net.bytebuddy.description.type.TypeList) MethodList(net.bytebuddy.description.method.MethodList) List(java.util.List) FieldList(net.bytebuddy.description.field.FieldList) ObjectPropertyAssertion(net.bytebuddy.test.utility.ObjectPropertyAssertion) Test(org.junit.Test)

Example 89 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 ImplementationSpecialMethodInvocationSimpleTest method testEquality.

@Test
public void testEquality() throws Exception {
    MethodDescription firstMethod = mock(MethodDescription.class), secondMethod = mock(MethodDescription.class);
    MethodDescription.SignatureToken firstToken = mock(MethodDescription.SignatureToken.class), secondToken = mock(MethodDescription.SignatureToken.class);
    when(firstMethod.asSignatureToken()).thenReturn(firstToken);
    when(secondMethod.asSignatureToken()).thenReturn(secondToken);
    TypeDescription firstType = mock(TypeDescription.class), secondType = mock(TypeDescription.class);
    assertThat(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class)), is(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class))));
    assertThat(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class)), not(new Implementation.SpecialMethodInvocation.Simple(secondMethod, firstType, mock(StackManipulation.class))));
    assertThat(new Implementation.SpecialMethodInvocation.Simple(firstMethod, firstType, mock(StackManipulation.class)), not(new Implementation.SpecialMethodInvocation.Simple(firstMethod, secondType, mock(StackManipulation.class))));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 90 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 InvokeDynamicTest method testChainedInvocation.

@Test
@JavaVersionRule.Enforce(7)
public void testChainedInvocation() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
    DynamicType.Loaded<SimpleWithArgument> dynamicType = new ByteBuddy().subclass(SimpleWithArgument.class).method(isDeclaredBy(SimpleWithArgument.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly()).invoke(QUX, String.class).withArgument(0).andThen(FixedValue.value(BAZ))).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
    assertThat(dynamicType.getLoaded().getDeclaredFields().length, is(0));
    assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(FOO), is(BAZ));
}
Also used : DynamicType(net.bytebuddy.dynamic.DynamicType) TypeDescription(net.bytebuddy.description.type.TypeDescription) ByteBuddy(net.bytebuddy.ByteBuddy) 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