示例#1
0
 @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;
   }
 }
示例#2
0
 @Override
 public boolean equals(Object other) {
   return this == other
       || !(other == null || getClass() != other.getClass())
           && accessorMethod.equals(((MethodCall) other).accessorMethod)
           && assigner.equals(((MethodCall) other).assigner);
 }
示例#3
0
 @Override
 public boolean equals(Object other) {
   return this == other
       || !(other == null || getClass() != other.getClass())
           && typing == ((FixedValue) other).typing
           && assigner.equals(((FixedValue) other).assigner);
 }
示例#4
0
 @Override
 public int hashCode() {
   int result = specialMethodInvocation.hashCode();
   result = 31 * result + (serializableProxy ? 1 : 0);
   result = 31 * result + assigner.hashCode();
   return result;
 }
示例#5
0
 @Override
 public boolean equals(Object other) {
   if (this == other) return true;
   if (other == null || getClass() != other.getClass()) return false;
   MethodCallProxy that = (MethodCallProxy) other;
   return serializableProxy == that.serializableProxy
       && assigner.equals(that.assigner)
       && specialMethodInvocation.equals(that.specialMethodInvocation);
 }
 @Before
 public void setUp() throws Exception {
   when(chainedAssigner.assign(
           any(TypeDescription.Generic.class),
           any(TypeDescription.Generic.class),
           any(Assigner.Typing.class)))
       .thenReturn(stackManipulation);
   when(stackManipulation.isValid()).thenReturn(true);
   when(stackManipulation.apply(any(MethodVisitor.class), any(Implementation.Context.class)))
       .thenReturn(StackSize.ZERO.toIncreasingSize());
 }
 @Before
 public void setUp() throws Exception {
   when(sourceTypeDescription.represents(sourceType)).thenReturn(true);
   when(sourceTypeDescription.isPrimitive()).thenReturn(true);
   when(targetTypeDescription.represents(targetType)).thenReturn(true);
   when(targetTypeDescription.isPrimitive()).thenReturn(false);
   when(chainedStackManipulation.isValid()).thenReturn(true);
   when(chainedAssigner.assign(
           any(TypeDescription.class), any(TypeDescription.class), any(Assigner.Typing.class)))
       .thenReturn(chainedStackManipulation);
   primitiveAssigner = new PrimitiveTypeAwareAssigner(chainedAssigner);
 }
示例#8
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());
 }
 @Test
 public void testBoxingAssignment() {
   StackManipulation stackManipulation =
       primitiveAssigner.assign(
           sourceTypeDescription, targetTypeDescription, Assigner.Typing.STATIC);
   assertThat(stackManipulation.isValid(), is(assignable));
   verify(chainedStackManipulation).isValid();
   verifyNoMoreInteractions(chainedStackManipulation);
   verify(sourceTypeDescription, atLeast(0)).represents(any(Class.class));
   verify(sourceTypeDescription).represents(sourceType);
   verify(sourceTypeDescription, atLeast(1)).isPrimitive();
   verifyNoMoreInteractions(sourceTypeDescription);
   verify(targetTypeDescription, atLeast(1)).isPrimitive();
   verifyNoMoreInteractions(targetTypeDescription);
   verify(chainedAssigner)
       .assign(
           new TypeDescription.ForLoadedType(targetType),
           targetTypeDescription,
           Assigner.Typing.STATIC);
   verifyNoMoreInteractions(chainedAssigner);
 }
示例#10
0
 @Override
 public int hashCode() {
   return accessorMethod.hashCode() + 31 * assigner.hashCode();
 }
示例#11
0
 @Override
 public int hashCode() {
   return 31 * assigner.hashCode() + typing.hashCode();
 }
 /**
  * Creates a stack manipulation that boxes the represented primitive type and applies a chained
  * assignment to the result of this boxing operation.
  *
  * @param targetType The type that is target of the assignment operation.
  * @param chainedAssigner The assigner that is to be used to perform the chained assignment.
  * @param dynamicallyTyped If {@code true}, unsafe cast operations are allowed for performing an
  *     assignment.
  * @return A stack manipulation that represents the described assignment operation.
  */
 public StackManipulation assignBoxedTo(
     TypeDescription targetType, Assigner chainedAssigner, boolean dynamicallyTyped) {
   return new BoxingStackManipulation(
       chainedAssigner.assign(wrapperType, targetType, dynamicallyTyped));
 }