Example #1
0
 @Override
 public MethodDelegationBinder.ParameterBinding<?> bind(
     AnnotationDescription.Loadable<Origin> annotation,
     MethodDescription source,
     ParameterDescription target,
     Implementation.Target implementationTarget,
     Assigner assigner) {
   TypeDescription parameterType = target.getType().asErasure();
   if (parameterType.represents(Class.class)) {
     return new MethodDelegationBinder.ParameterBinding.Anonymous(
         ClassConstant.of(implementationTarget.getOriginType()));
   } else if (parameterType.represents(Method.class)) {
     return new MethodDelegationBinder.ParameterBinding.Anonymous(
         annotation.loadSilent().cache()
             ? MethodConstant.forMethod(source.asDefined()).cached()
             : MethodConstant.forMethod(source.asDefined()));
   } else if (parameterType.represents(String.class)) {
     return new MethodDelegationBinder.ParameterBinding.Anonymous(
         new TextConstant(source.toString()));
   } else if (parameterType.represents(int.class)) {
     return new MethodDelegationBinder.ParameterBinding.Anonymous(
         IntegerConstant.forValue(source.getModifiers()));
   } else if (parameterType.equals(JavaType.METHOD_HANDLE.getTypeStub())) {
     return new MethodDelegationBinder.ParameterBinding.Anonymous(
         MethodHandleConstant.of(source.asDefined()));
   } else if (parameterType.equals(JavaType.METHOD_TYPE.getTypeStub())) {
     return new MethodDelegationBinder.ParameterBinding.Anonymous(
         MethodTypeConstant.of(source.asDefined()));
   } else {
     throw new IllegalStateException(
         "The "
             + target
             + " method's "
             + target.getIndex()
             + " parameter is annotated with a Origin annotation with an argument not representing a Class,"
             + " Method, String, int, MethodType or MethodHandle type");
   }
 }