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