@Override
 public MethodDelegationBinder.ParameterBinding<?> bind(
     AnnotationDescription.Loadable<FieldValue> annotation,
     MethodDescription source,
     ParameterDescription target,
     Implementation.Target implementationTarget,
     Assigner assigner) {
   FieldLocator.Resolution resolution =
       FieldLocator.of(
               annotation.getValue(DEFINING_TYPE, TypeDescription.class),
               implementationTarget.getTypeDescription())
           .resolve(annotation.getValue(FIELD_NAME, String.class), source.isStatic());
   if (resolution.isResolved()) {
     StackManipulation stackManipulation =
         new StackManipulation.Compound(
             resolution.getFieldDescription().isStatic()
                 ? StackManipulation.Trivial.INSTANCE
                 : MethodVariableAccess.REFERENCE.loadOffset(0),
             FieldAccess.forField(resolution.getFieldDescription()).getter(),
             assigner.assign(
                 resolution.getFieldDescription().getType().asErasure(),
                 target.getType().asErasure(),
                 RuntimeType.Verifier.check(target)));
     return stackManipulation.isValid()
         ? new MethodDelegationBinder.ParameterBinding.Anonymous(stackManipulation)
         : MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE;
   } else {
     return MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE;
   }
 }
Exemple #2
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");
   }
 }