Ejemplo n.º 1
0
 @Override
 public Size apply(
     MethodVisitor methodVisitor,
     Context implementationContext,
     MethodDescription instrumentedMethod) {
   StackManipulation thisReference =
       MethodVariableAccess.forType(instrumentedType).loadOffset(0);
   FieldList<?> fieldList = instrumentedType.getDeclaredFields();
   StackManipulation[] fieldLoading = new StackManipulation[fieldList.size()];
   int index = 0;
   for (FieldDescription fieldDescription : fieldList) {
     fieldLoading[index++] =
         new StackManipulation.Compound(
             thisReference, FieldAccess.forField(fieldDescription).getter());
   }
   StackManipulation.Size stackSize =
       new StackManipulation.Compound(
               new StackManipulation.Compound(fieldLoading),
               MethodInvocation.invoke(accessorMethod),
               assigner.assign(
                   accessorMethod.getReturnType().asErasure(),
                   instrumentedMethod.getReturnType().asErasure(),
                   Assigner.Typing.DYNAMIC),
               MethodReturn.returning(instrumentedMethod.getReturnType().asErasure()))
           .apply(methodVisitor, implementationContext);
   return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
 }
Ejemplo n.º 2
0
 /**
  * Blueprint method that for applying the actual implementation.
  *
  * @param methodVisitor The method visitor to which the implementation is applied to.
  * @param implementationContext The implementation context for the given implementation.
  * @param instrumentedMethod The instrumented method that is target of the implementation.
  * @param fixedValueType A description of the type of the fixed value that is loaded by the {@code
  *     valueLoadingInstruction}.
  * @param valueLoadingInstruction A stack manipulation that represents the loading of the fixed
  *     value onto the operand stack.
  * @return A representation of the stack and variable array sized that are required for this
  *     implementation.
  */
 protected ByteCodeAppender.Size apply(
     MethodVisitor methodVisitor,
     Context implementationContext,
     MethodDescription instrumentedMethod,
     TypeDescription.Generic fixedValueType,
     StackManipulation valueLoadingInstruction) {
   StackManipulation assignment =
       assigner.assign(fixedValueType, instrumentedMethod.getReturnType(), typing);
   if (!assignment.isValid()) {
     throw new IllegalArgumentException(
         "Cannot return value of type " + fixedValueType + " for " + instrumentedMethod);
   }
   StackManipulation.Size stackSize =
       new StackManipulation.Compound(
               valueLoadingInstruction,
               assignment,
               MethodReturn.returning(instrumentedMethod.getReturnType().asErasure()))
           .apply(methodVisitor, implementationContext);
   return new ByteCodeAppender.Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
 }