Search in sources :

Example 26 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 MethodGraphCompilerDefaultTest method testClassInheritance.

@Test
public void testClassInheritance() throws Exception {
    TypeDescription typeDescription = new TypeDescription.ForLoadedType(ClassBase.Inner.class);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.Default.forJavaHierarchy().compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(TypeDescription.OBJECT.getDeclaredMethods().filter(isVirtual()).size() + 1));
    MethodDescription method = typeDescription.getDeclaredMethods().filter(isMethod()).getOnly();
    MethodGraph.Node node = methodGraph.locate(method.asSignatureToken());
    assertThat(node.getSort(), is(MethodGraph.Node.Sort.RESOLVED));
    assertThat(node.getMethodTypes().size(), is(1));
    assertThat(node.getMethodTypes().contains(method.asTypeToken()), is(true));
    assertThat(node.getRepresentative(), is(method));
    assertThat(node.getVisibility(), is(method.getVisibility()));
    assertThat(methodGraph.listNodes().contains(node), is(true));
    MethodGraph.Node baseNode = methodGraph.getSuperClassGraph().locate(method.asSignatureToken());
    assertThat(node, not(baseNode));
    assertThat(typeDescription.getSuperClass().getDeclaredMethods().filter(ElementMatchers.is(baseNode.getRepresentative())).getOnly(), is(baseNode.getRepresentative()));
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 27 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 MethodGraphCompilerForDeclaredMethodsTest method testCompilationNonBridge.

@Test
public void testCompilationNonBridge() throws Exception {
    TypeDescription typeDescription = mock(TypeDescription.class);
    MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
    when(typeDescription.getDeclaredMethods()).thenReturn(new MethodList.Explicit<MethodDescription.InDefinedShape>(methodDescription));
    when(methodDescription.isVirtual()).thenReturn(true);
    when(methodDescription.getModifiers()).thenReturn(Opcodes.ACC_BRIDGE);
    when(methodDescription.isVisibleTo(typeDescription)).thenReturn(true);
    MethodGraph.Linked methodGraph = MethodGraph.Compiler.ForDeclaredMethods.INSTANCE.compile(typeDescription);
    assertThat(methodGraph.listNodes().size(), is(0));
}
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 28 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 ImplementationContextDefaultOtherTest method testInstrumentationGetter.

@Test
public void testInstrumentationGetter() throws Exception {
    TypeDescription instrumentedType = mock(TypeDescription.class);
    assertThat(new Implementation.Context.Default(instrumentedType, mock(ClassFileVersion.class), mock(AuxiliaryType.NamingStrategy.class), mock(TypeInitializer.class), mock(ClassFileVersion.class)).getInstrumentedType(), is(instrumentedType));
}
Also used : ClassFileVersion(net.bytebuddy.ClassFileVersion) TypeDescription(net.bytebuddy.description.type.TypeDescription) TypeInitializer(net.bytebuddy.dynamic.scaffold.TypeInitializer) Test(org.junit.Test)

Example 29 with TypeDescription

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription in project hibernate-orm by hibernate.

the class BiDirectionalAssociationHandler method wrap.

static Implementation wrap(TypeDescription managedCtClass, ByteBuddyEnhancementContext enhancementContext, FieldDescription persistentField, Implementation implementation) {
    if (!enhancementContext.doBiDirectionalAssociationManagement(persistentField)) {
        return implementation;
    }
    TypeDescription targetEntity = getTargetEntityClass(managedCtClass, persistentField);
    if (targetEntity == null) {
        return implementation;
    }
    String mappedBy = getMappedBy(persistentField, targetEntity, enhancementContext);
    if (mappedBy == null || mappedBy.isEmpty()) {
        log.infof("Could not find bi-directional association for field [%s#%s]", managedCtClass.getName(), persistentField.getName());
        return implementation;
    }
    TypeDescription targetType = FieldLocator.ForClassHierarchy.Factory.INSTANCE.make(targetEntity).locate(mappedBy).getField().getType().asErasure();
    if (EnhancerImpl.isAnnotationPresent(persistentField, OneToOne.class)) {
        implementation = Advice.withCustomMapping().bind(CodeTemplates.FieldValue.class, persistentField).bind(CodeTemplates.MappedBy.class, mappedBy).to(CodeTemplates.OneToOneHandler.class).wrap(implementation);
    }
    if (EnhancerImpl.isAnnotationPresent(persistentField, OneToMany.class)) {
        implementation = Advice.withCustomMapping().bind(CodeTemplates.FieldValue.class, persistentField).bind(CodeTemplates.MappedBy.class, mappedBy).to(persistentField.getType().asErasure().isAssignableTo(Map.class) ? CodeTemplates.OneToManyOnMapHandler.class : CodeTemplates.OneToManyOnCollectionHandler.class).wrap(implementation);
    }
    if (EnhancerImpl.isAnnotationPresent(persistentField, ManyToOne.class)) {
        implementation = Advice.withCustomMapping().bind(CodeTemplates.FieldValue.class, persistentField).bind(CodeTemplates.MappedBy.class, mappedBy).to(CodeTemplates.ManyToOneHandler.class).wrap(implementation);
    }
    if (EnhancerImpl.isAnnotationPresent(persistentField, ManyToMany.class)) {
        if (persistentField.getType().asErasure().isAssignableTo(Map.class) || targetType.isAssignableTo(Map.class)) {
            log.infof("Bi-directional association for field [%s#%s] not managed: @ManyToMany in java.util.Map attribute not supported ", managedCtClass.getName(), persistentField.getName());
            return implementation;
        }
        implementation = Advice.withCustomMapping().bind(CodeTemplates.FieldValue.class, persistentField).bind(CodeTemplates.MappedBy.class, mappedBy).to(CodeTemplates.ManyToManyHandler.class).wrap(implementation);
    }
    return new BiDirectionalAssociationHandler(implementation, targetEntity, targetType, mappedBy);
}
Also used : TypeDescription(net.bytebuddy.description.type.TypeDescription) Map(java.util.Map)

Example 30 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 JavaConstantMethodHandleTest method testAbstractMethodNotSpecial.

@Test(expected = IllegalArgumentException.class)
public void testAbstractMethodNotSpecial() throws Exception {
    MethodDescription.InDefinedShape methodDescription = mock(MethodDescription.InDefinedShape.class);
    TypeDescription typeDescription = mock(TypeDescription.class);
    when(methodDescription.isAbstract()).thenReturn(true);
    when(methodDescription.isSpecializableFor(typeDescription)).thenReturn(true);
    JavaConstant.MethodHandle.ofSpecial(methodDescription, typeDescription);
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) TypeDescription(net.bytebuddy.description.type.TypeDescription) 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