All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ui4j.bytebuddy.instrumentation.method.bytecode.bind.annotation.SuperCall Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package com.ui4j.bytebuddy.instrumentation.method.bytecode.bind.annotation;

import com.ui4j.bytebuddy.instrumentation.Instrumentation;
import com.ui4j.bytebuddy.instrumentation.attribute.annotation.AnnotationDescription;
import com.ui4j.bytebuddy.instrumentation.method.MethodDescription;
import com.ui4j.bytebuddy.instrumentation.method.bytecode.bind.MethodDelegationBinder;
import com.ui4j.bytebuddy.instrumentation.method.bytecode.stack.assign.Assigner;
import com.ui4j.bytebuddy.instrumentation.type.TypeDescription;
import com.ui4j.bytebuddy.instrumentation.type.auxiliary.MethodCallProxy;

import java.lang.annotation.*;
import java.util.concurrent.Callable;

/**
 * Parameters that are annotated with this annotation will be assigned a proxy for calling the instrumented method's
 * {@code super} implementation. If a method does not have a super implementation, calling the annotated proxy will
 * throw an exception.
 * 

 

* The proxy will both implement the {@link java.util.concurrent.Callable} and the {@link java.lang.Runnable} interfaces * such that the annotated parameter must be assignable to any of those interfaces or be of the {@link java.lang.Object} * type. * * @see com.ui4j.bytebuddy.instrumentation.MethodDelegation * @see TargetMethodAnnotationDrivenBinder */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) public @interface SuperCall { /** * Determines if the generated proxy should be {@link java.io.Serializable}. * * @return {@code true} if the generated proxy should be {@link java.io.Serializable}. */ boolean serializableProxy() default false; /** * A binder for handling the * {@link com.ui4j.bytebuddy.instrumentation.method.bytecode.bind.annotation.SuperCall} * annotation. * * @see TargetMethodAnnotationDrivenBinder */ static enum Binder implements TargetMethodAnnotationDrivenBinder.ParameterBinder { /** * The singleton instance. */ INSTANCE; @Override public Class getHandledType() { return SuperCall.class; } @Override public MethodDelegationBinder.ParameterBinding bind(AnnotationDescription.Loadable annotation, int targetParameterIndex, MethodDescription source, MethodDescription target, Instrumentation.Target instrumentationTarget, Assigner assigner) { TypeDescription targetType = target.getParameterTypes().get(targetParameterIndex); if (!targetType.represents(Runnable.class) && !targetType.represents(Callable.class) && !targetType.represents(Object.class)) { throw new IllegalStateException("A super method call proxy can only be assigned to Runnable or Callable types: " + target); } Instrumentation.SpecialMethodInvocation specialMethodInvocation = instrumentationTarget.invokeSuper(source, Instrumentation.Target.MethodLookup.Default.EXACT); return specialMethodInvocation.isValid() ? new MethodDelegationBinder.ParameterBinding.Anonymous(new MethodCallProxy.AssignableSignatureCall(specialMethodInvocation, annotation.loadSilent().serializableProxy())) : MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy