Search in sources :

Example 11 with ByteCodeElement

use of net.bytebuddy.description.ByteCodeElement in project morphia by mongodb.

the class ReferenceCodec method makeProxy.

private <T> Class<T> makeProxy() {
    PropertyModel propertyModel = getPropertyModel();
    Class<?> type = propertyModel.getType();
    Builder<?> builder = new ByteBuddy().subclass(type).implement(MorphiaProxy.class).name(format("%s$%s$$ReferenceProxy", propertyModel.getEntityModel().getName(), propertyModel.getName()));
    Junction<ByteCodeElement> matcher = ElementMatchers.isDeclaredBy(type);
    if (!type.isInterface()) {
        type = type.getSuperclass();
        while (type != null && !type.equals(Object.class)) {
            matcher = matcher.or(ElementMatchers.isDeclaredBy(type));
            type = type.getSuperclass();
        }
    }
    return (Class<T>) builder.invokable(matcher.or(ElementMatchers.isDeclaredBy(MorphiaProxy.class))).intercept(InvocationHandlerAdapter.toField(FIELD_INVOCATION_HANDLER)).defineField(FIELD_INVOCATION_HANDLER, InvocationHandler.class, Visibility.PRIVATE).make().load(Thread.currentThread().getContextClassLoader(), Default.WRAPPER).getLoaded();
}
Also used : PropertyModel(dev.morphia.mapping.codec.pojo.PropertyModel) ByteBuddy(net.bytebuddy.ByteBuddy) ByteCodeElement(net.bytebuddy.description.ByteCodeElement)

Aggregations

ByteCodeElement (net.bytebuddy.description.ByteCodeElement)11 Test (org.junit.Test)10 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)1 ByteBuddy (net.bytebuddy.ByteBuddy)1