Java Code Examples for net.bytebuddy.implementation.Implementation#Target
The following examples show how to use
net.bytebuddy.implementation.Implementation#Target .
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: MethodDelegationBinder.java From byte-buddy with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public MethodBinding bind(Implementation.Target implementationTarget, MethodDescription source, TerminationHandler terminationHandler, MethodInvoker methodInvoker, Assigner assigner) { List<MethodBinding> targets = new ArrayList<MethodBinding>(); for (Record record : records) { MethodBinding methodBinding = record.bind(implementationTarget, source, terminationHandler, methodInvoker, assigner); if (methodBinding.isValid()) { targets.add(methodBinding); } } if (targets.isEmpty()) { throw new IllegalArgumentException("None of " + records + " allows for delegation from " + source); } return bindingResolver.resolve(ambiguityResolver, source, targets); }
Example 2
Source File: MethodDelegationBinder.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public MethodBinding bind(Implementation.Target implementationTarget, MethodDescription source, TerminationHandler terminationHandler, MethodInvoker methodInvoker, Assigner assigner) { return MethodBinding.Illegal.INSTANCE; }
Example 3
Source File: TypeProxy.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a new stack operation for creating a type proxy by calling one of its constructors. * * @param proxiedType The type for the type proxy to subclass or implement. * @param implementationTarget The implementation target this type proxy is created for. * @param constructorParameters The parameter types of the constructor that should be called. * @param ignoreFinalizer {@code true} if any finalizers should be ignored for the delegation. * @param serializableProxy Determines if the proxy should be serializable. */ public ForSuperMethodByConstructor(TypeDescription proxiedType, Implementation.Target implementationTarget, List<TypeDescription> constructorParameters, boolean ignoreFinalizer, boolean serializableProxy) { this.proxiedType = proxiedType; this.implementationTarget = implementationTarget; this.constructorParameters = constructorParameters; this.ignoreFinalizer = ignoreFinalizer; this.serializableProxy = serializableProxy; }
Example 4
Source File: TypeProxy.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a new stack operation for reflectively creating a type proxy for the given arguments. * * @param proxiedType The type for the type proxy to subclass or implement. * @param implementationTarget The implementation target this type proxy is created for. * @param ignoreFinalizer {@code true} if any finalizer methods should be ignored for proxying. * @param serializableProxy Determines if the proxy should be serializable. */ public ForSuperMethodByReflectionFactory(TypeDescription proxiedType, Implementation.Target implementationTarget, boolean ignoreFinalizer, boolean serializableProxy) { this.proxiedType = proxiedType; this.implementationTarget = implementationTarget; this.ignoreFinalizer = ignoreFinalizer; this.serializableProxy = serializableProxy; }
Example 5
Source File: TypeProxy.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a new proxy creation for a default interface type proxy. * * @param proxiedType The proxied interface type. * @param implementationTarget The implementation target for the original implementation. * @param serializableProxy {@code true} if the proxy should be {@link java.io.Serializable}. */ public ForDefaultMethod(TypeDescription proxiedType, Implementation.Target implementationTarget, boolean serializableProxy) { this.proxiedType = proxiedType; this.implementationTarget = implementationTarget; this.serializableProxy = serializableProxy; }
Example 6
Source File: MethodRegistry.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public MethodRegistry.Compiled compile(Implementation.Target.Factory implementationTargetFactory, ClassFileVersion classFileVersion) { Map<Handler, Handler.Compiled> compilationCache = new HashMap<Handler, Handler.Compiled>(); Map<MethodAttributeAppender.Factory, MethodAttributeAppender> attributeAppenderCache = new HashMap<MethodAttributeAppender.Factory, MethodAttributeAppender>(); LinkedHashMap<MethodDescription, Compiled.Entry> entries = new LinkedHashMap<MethodDescription, Compiled.Entry>(); Implementation.Target implementationTarget = implementationTargetFactory.make(instrumentedType, methodGraph, classFileVersion); for (Map.Entry<MethodDescription, Entry> entry : implementations.entrySet()) { Handler.Compiled cachedHandler = compilationCache.get(entry.getValue().getHandler()); if (cachedHandler == null) { cachedHandler = entry.getValue().getHandler().compile(implementationTarget); compilationCache.put(entry.getValue().getHandler(), cachedHandler); } MethodAttributeAppender cachedAttributeAppender = attributeAppenderCache.get(entry.getValue().getAppenderFactory()); if (cachedAttributeAppender == null) { cachedAttributeAppender = entry.getValue().getAppenderFactory().make(instrumentedType); attributeAppenderCache.put(entry.getValue().getAppenderFactory(), cachedAttributeAppender); } entries.put(entry.getKey(), new Compiled.Entry(cachedHandler, cachedAttributeAppender, entry.getValue().getMethodDescription(), entry.getValue().resolveBridgeTypes(), entry.getValue().getVisibility(), entry.getValue().isBridgeMethod())); } return new Compiled(instrumentedType, loadedTypeInitializer, typeInitializer, methods, entries, classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)); }
Example 7
Source File: DefaultMethod.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public Implementation.SpecialMethodInvocation resolve(Implementation.Target implementationTarget, MethodDescription source) { if (!typeDescription.isInterface()) { throw new IllegalStateException(source + " method carries default method call parameter on non-interface type"); } return implementationTarget.invokeDefault(source.asSignatureToken(), TargetType.resolve(typeDescription, implementationTarget.getInstrumentedType())); }
Example 8
Source File: DefaultCall.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public Implementation.SpecialMethodInvocation resolve(Implementation.Target implementationTarget, MethodDescription source) { if (!typeDescription.isInterface()) { throw new IllegalStateException(source + " method carries default method call parameter on non-interface type"); } return implementationTarget.invokeDefault(source.asSignatureToken(), typeDescription); }
Example 9
Source File: TypeProxy.java From byte-buddy with Apache License 2.0 | 5 votes |
/** * Creates a new type proxy. * * @param proxiedType The type this proxy should implement which can either be a non-final class or an interface. * @param implementationTarget The implementation target this type proxy is created for. * @param invocationFactory The invocation factory for creating special method invocations. * @param ignoreFinalizer {@code true} if any finalizer methods should be ignored for proxying. * @param serializableProxy Determines if the proxy should be serializable. */ public TypeProxy(TypeDescription proxiedType, Implementation.Target implementationTarget, InvocationFactory invocationFactory, boolean ignoreFinalizer, boolean serializableProxy) { this.proxiedType = proxiedType; this.implementationTarget = implementationTarget; this.invocationFactory = invocationFactory; this.ignoreFinalizer = ignoreFinalizer; this.serializableProxy = serializableProxy; }
Example 10
Source File: MethodRegistry.java From byte-buddy with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public Compiled compile(Implementation.Target implementationTarget) { return new Compiled(implementation.appender(implementationTarget)); }
Example 11
Source File: MethodRegistry.java From byte-buddy with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public Compiled compile(Implementation.Target implementationTarget) { return this; }
Example 12
Source File: MethodRegistry.java From byte-buddy with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public Compiled compile(Implementation.Target implementationTarget) { return this; }
Example 13
Source File: SubclassImplementationTarget.java From byte-buddy with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public Implementation.Target make(TypeDescription instrumentedType, MethodGraph.Linked methodGraph, ClassFileVersion classFileVersion) { return new SubclassImplementationTarget(instrumentedType, methodGraph, DefaultMethodInvocation.of(classFileVersion), originTypeResolver); }
Example 14
Source File: TargetMethodAnnotationDrivenBinder.java From byte-buddy with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public ParameterBinding<?> bind(AnnotationDescription.Loadable<S> annotation, MethodDescription source, ParameterDescription target, Implementation.Target implementationTarget, Assigner assigner, Assigner.Typing typing) { Object value = bind(annotation, source, target); if (value == null) { return new ParameterBinding.Anonymous(DefaultValue.of(target.getType())); } StackManipulation stackManipulation; TypeDescription suppliedType; if (value instanceof Boolean) { stackManipulation = IntegerConstant.forValue((Boolean) value); suppliedType = TypeDescription.ForLoadedType.of(boolean.class); } else if (value instanceof Byte) { stackManipulation = IntegerConstant.forValue((Byte) value); suppliedType = TypeDescription.ForLoadedType.of(byte.class); } else if (value instanceof Short) { stackManipulation = IntegerConstant.forValue((Short) value); suppliedType = TypeDescription.ForLoadedType.of(short.class); } else if (value instanceof Character) { stackManipulation = IntegerConstant.forValue((Character) value); suppliedType = TypeDescription.ForLoadedType.of(char.class); } else if (value instanceof Integer) { stackManipulation = IntegerConstant.forValue((Integer) value); suppliedType = TypeDescription.ForLoadedType.of(int.class); } else if (value instanceof Long) { stackManipulation = LongConstant.forValue((Long) value); suppliedType = TypeDescription.ForLoadedType.of(long.class); } else if (value instanceof Float) { stackManipulation = FloatConstant.forValue((Float) value); suppliedType = TypeDescription.ForLoadedType.of(float.class); } else if (value instanceof Double) { stackManipulation = DoubleConstant.forValue((Double) value); suppliedType = TypeDescription.ForLoadedType.of(double.class); } else if (value instanceof String) { stackManipulation = new TextConstant((String) value); suppliedType = TypeDescription.STRING; } else if (value instanceof Class) { stackManipulation = ClassConstant.of(TypeDescription.ForLoadedType.of((Class<?>) value)); suppliedType = TypeDescription.CLASS; } else if (value instanceof TypeDescription) { stackManipulation = ClassConstant.of((TypeDescription) value); suppliedType = TypeDescription.CLASS; } else if (JavaType.METHOD_HANDLE.isInstance(value)) { stackManipulation = new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(value)); suppliedType = JavaType.METHOD_HANDLE.getTypeStub(); } else if (value instanceof JavaConstant.MethodHandle) { stackManipulation = new JavaConstantValue((JavaConstant.MethodHandle) value); suppliedType = JavaType.METHOD_HANDLE.getTypeStub(); } else if (JavaType.METHOD_TYPE.isInstance(value)) { stackManipulation = new JavaConstantValue(JavaConstant.MethodType.ofLoaded(value)); suppliedType = JavaType.METHOD_HANDLE.getTypeStub(); } else if (value instanceof JavaConstant.MethodType) { stackManipulation = new JavaConstantValue((JavaConstant.MethodType) value); suppliedType = JavaType.METHOD_HANDLE.getTypeStub(); } else { throw new IllegalStateException("Not able to save in class's constant pool: " + value); } return new ParameterBinding.Anonymous(new StackManipulation.Compound( stackManipulation, assigner.assign(suppliedType.asGenericType(), target.getType(), typing) )); }
Example 15
Source File: DefaultCall.java From byte-buddy with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public Implementation.SpecialMethodInvocation resolve(Implementation.Target implementationTarget, MethodDescription source) { return implementationTarget.invokeDefault(source.asSignatureToken()); }
Example 16
Source File: TypeProxy.java From byte-buddy with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ public Implementation.SpecialMethodInvocation invoke(Implementation.Target implementationTarget, TypeDescription proxiedType, MethodDescription instrumentedMethod) { return implementationTarget.invokeDominant(instrumentedMethod.asSignatureToken()); }
Example 17
Source File: RebaseImplementationTargetTest.java From byte-buddy with Apache License 2.0 | 4 votes |
protected Implementation.Target makeImplementationTarget() { return new RebaseImplementationTarget(instrumentedType, methodGraph, defaultMethodInvocation, Collections.singletonMap(rebasedSignatureToken, resolution)); }
Example 18
Source File: TargetMethodAnnotationDrivenBinder.java From byte-buddy with Apache License 2.0 | 3 votes |
/** * Creates a parameter binding for the given target parameter. * * @param fieldDescription The field for which this binder binds a value. * @param annotation The annotation that was cause for the delegation to this argument binder. * @param source The intercepted source method. * @param target Tge target parameter that is subject to be bound to * intercepting the {@code source} method. * @param implementationTarget The target of the current implementation that is subject to this binding. * @param assigner An assigner that can be used for applying the binding. * @return A parameter binding for the requested target method parameter. */ protected abstract ParameterBinding<?> bind(FieldDescription fieldDescription, AnnotationDescription.Loadable<S> annotation, MethodDescription source, ParameterDescription target, Implementation.Target implementationTarget, Assigner assigner);
Example 19
Source File: TargetMethodAnnotationDrivenBinder.java From byte-buddy with Apache License 2.0 | 3 votes |
/** * Creates a parameter binding for the given target parameter. * * @param annotation The annotation that was cause for the delegation to this argument binder. * @param source The intercepted source method. * @param target Tge target parameter that is subject to be bound to * intercepting the {@code source} method. * @param implementationTarget The target of the current implementation that is subject to this binding. * @param assigner An assigner that can be used for applying the binding. * @param typing The typing to apply. * @return A parameter binding for the requested target method parameter. */ ParameterBinding<?> bind(AnnotationDescription.Loadable<T> annotation, MethodDescription source, ParameterDescription target, Implementation.Target implementationTarget, Assigner assigner, Assigner.Typing typing);
Example 20
Source File: MethodDelegationBinder.java From byte-buddy with Apache License 2.0 | 2 votes |
/** * Attempts a binding of a source method to this compiled target. * * @param implementationTarget The target of the current implementation onto which this binding is to be applied. * @param source The method that is to be bound to the {@code target} method. * @param terminationHandler The termination handler to apply. * @param methodInvoker The method invoker to use. * @param assigner The assigner to use. * @return A binding representing this attempt to bind the {@code source} method to the {@code target} method. */ MethodBinding bind(Implementation.Target implementationTarget, MethodDescription source, TerminationHandler terminationHandler, MethodInvoker methodInvoker, Assigner assigner);