net.bytebuddy.dynamic.loading.ClassLoadingStrategy.Default Java Examples
The following examples show how to use
net.bytebuddy.dynamic.loading.ClassLoadingStrategy.Default.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QualifierAndScopeImplementationGenerator.java From Diorite with MIT License | 6 votes |
@SuppressWarnings("unchecked") @Nullable public static <T extends Annotation> Class<? extends T> transform(Class<T> clazz) { if (! clazz.isAnnotation() || ! (clazz.isAnnotationPresent(Qualifier.class) || clazz.isAnnotationPresent(Scope.class))) { return null; } try { String name = GENERATED_PREFIX + "." + clazz.getName(); Unloaded<Object> make = new ByteBuddy(ClassFileVersion.JAVA_V9).subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS) .implement(Serializable.class, clazz).name(name) .visit(new AnnotationImplementationVisitor(new ForLoadedType(clazz))).make(); Loaded<Object> load = make.load(ClassLoader.getSystemClassLoader(), Default.INJECTION); return (Class<? extends T>) load.getLoaded(); } catch (Throwable e) { throw new RuntimeException(e); } }
Example #2
Source File: ReferenceCodec.java From morphia with Apache License 2.0 | 6 votes |
private <T> T createProxy(final MorphiaReference reference) { ReferenceProxy referenceProxy = new ReferenceProxy(reference); try { Class<?> type = getField().getType(); String name = (type.getPackageName().startsWith("java") ? type.getSimpleName() : type.getName()) + "$$Proxy"; return ((Loaded<T>) new ByteBuddy() .subclass(type) .implement(MorphiaProxy.class) .name(name) .invokable(ElementMatchers.isDeclaredBy(type)) .intercept(InvocationHandlerAdapter.of(referenceProxy)) .method(ElementMatchers.isDeclaredBy(MorphiaProxy.class)) .intercept(InvocationHandlerAdapter.of(referenceProxy)) .make() .load(Thread.currentThread().getContextClassLoader(), Default.WRAPPER)) .getLoaded() .getDeclaredConstructor() .newInstance(); } catch (ReflectiveOperationException | IllegalArgumentException e) { throw new MappingException(e.getMessage(), e); } }
Example #3
Source File: ByteBuddyProcessFunctionInvoker.java From da-streamingledger with Apache License 2.0 | 5 votes |
private static Builder<?> configureByteBuddyBuilder( PackageLocalNamingStrategy generatedTypeName, TypeDefinition generatedType, TypeDefinition processFunctionType, ForLoadedConstructor superTypeConstructor, MethodDescription processMethodType, int numberOfStateBindings) { return new ByteBuddy() // final class <Name> extends <ProcessFunctionInvoker> { .with(generatedTypeName) .subclass(generatedType, ConstructorStrategy.Default.NO_CONSTRUCTORS).modifiers(Modifier.FINAL) // private final <processFunction class> delegate; .defineField("delegate", processFunctionType, Visibility.PRIVATE, FieldManifestation.FINAL) // public <Name>(<processFunction class> delegate) { // super(); // this.delegate = delegate; // } .defineConstructor(Modifier.PUBLIC) .withParameters(processFunctionType) .intercept(MethodCall.invoke(superTypeConstructor) .andThen(FieldAccessor.ofField("delegate").setsArgumentAt(0)) ) // invoke(input, context, StateAccess[] arguments) { // this.delegate.invoke(input, context, arguments[0], arguments[1], .. arguments[n - 1]); // } .method(ElementMatchers.named("invoke")) .intercept(MethodCall.invoke(processMethodType) .onField("delegate") .withArgument(0, 1) // event & context .withArgumentArrayElements(2, numberOfStateBindings) // StateAccess .withAssigner(Assigner.DEFAULT, Typing.STATIC) ); }
Example #4
Source File: ByteBuddyProcessFunctionInvoker.java From da-streamingledger with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static <InT, OutT> Class<? extends ProcessFunctionInvoker<InT, OutT>> loadClass( DynamicType.Unloaded<?> unloaded, ClassLoader classLoader) { return (Class<? extends ProcessFunctionInvoker<InT, OutT>>) unloaded .load(classLoader, Default.INJECTION) .getLoaded(); }
Example #5
Source File: Compatibility.java From Cubes with MIT License | 4 votes |
public Loaded load(Unloaded unloaded) { return unloaded.load(getClass().getClassLoader(), Default.INJECTION); }