use of net.bytebuddy.description.type.TypeDefinition in project byte-buddy by raphw.
the class DuplicationOtherTest method testDoubleToZeroFlip.
@Test(expected = IllegalArgumentException.class)
public void testDoubleToZeroFlip() throws Exception {
TypeDefinition typeDefinition = mock(TypeDefinition.class);
when(typeDefinition.getStackSize()).thenReturn(StackSize.ZERO);
Duplication.DOUBLE.flipOver(typeDefinition);
}
use of net.bytebuddy.description.type.TypeDefinition in project byte-buddy by raphw.
the class TransformerForFieldTest method testSimpleTransformation.
@Test
public void testSimpleTransformation() throws Exception {
when(tokenTransformer.transform(instrumentedType, fieldToken)).thenReturn(fieldToken);
FieldDescription transformed = new Transformer.ForField(tokenTransformer).transform(instrumentedType, fieldDescription);
assertThat(transformed.getDeclaringType(), is((TypeDefinition) declaringType));
assertThat(transformed.getInternalName(), is(FOO));
assertThat(transformed.getModifiers(), is(MODIFIERS));
assertThat(transformed.getDeclaredAnnotations(), is(Collections.singletonList(fieldAnnotation)));
assertThat(transformed.getType(), is(fieldType));
assertThat(transformed.asDefined(), is(definedField));
}
use of net.bytebuddy.description.type.TypeDefinition 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 net.bytebuddy.description.type.TypeDefinition in project hibernate-orm by hibernate.
the class PersistentAttributeTransformer method collectInheritPersistentFields.
private static Collection<FieldDescription> collectInheritPersistentFields(TypeDefinition managedCtClass, ByteBuddyEnhancementContext enhancementContext) {
if (managedCtClass == null || managedCtClass.represents(Object.class)) {
return Collections.emptyList();
}
TypeDefinition managedCtSuperclass = managedCtClass.getSuperClass();
if (!enhancementContext.isMappedSuperclassClass(managedCtSuperclass.asErasure())) {
return collectInheritPersistentFields(managedCtSuperclass, enhancementContext);
}
log.debugf("Found @MappedSuperclass %s to collectPersistenceFields", managedCtSuperclass);
List<FieldDescription> persistentFieldList = new ArrayList<FieldDescription>();
for (FieldDescription ctField : managedCtSuperclass.getDeclaredFields()) {
if (ctField.getName().startsWith("$$_hibernate_") || "this$0".equals(ctField.getName())) {
continue;
}
if (!ctField.isStatic() && enhancementContext.isPersistentField(ctField)) {
persistentFieldList.add(ctField);
}
}
persistentFieldList.addAll(collectInheritPersistentFields(managedCtSuperclass, enhancementContext));
return persistentFieldList;
}
use of net.bytebuddy.description.type.TypeDefinition in project hibernate-orm by hibernate.
the class EnhancerImpl method collectInheritCollectionFields.
private Collection<FieldDescription> collectInheritCollectionFields(TypeDefinition managedCtClass) {
TypeDefinition managedCtSuperclass = managedCtClass.getSuperClass();
if (managedCtSuperclass == null || managedCtSuperclass.represents(Object.class)) {
return Collections.emptyList();
}
if (!enhancementContext.isMappedSuperclassClass(managedCtSuperclass.asErasure())) {
return collectInheritCollectionFields(managedCtSuperclass.asErasure());
}
List<FieldDescription> collectionList = new ArrayList<FieldDescription>();
for (FieldDescription ctField : managedCtSuperclass.getDeclaredFields()) {
if (!Modifier.isStatic(ctField.getModifiers()) && enhancementContext.isPersistentField(ctField)) {
if (ctField.getType().asErasure().isAssignableTo(Collection.class) || ctField.getType().asErasure().isAssignableTo(Map.class)) {
collectionList.add(ctField);
}
}
}
collectionList.addAll(collectInheritCollectionFields(managedCtSuperclass));
return collectionList;
}
Aggregations