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