/** * {@inheritDoc} */ public Resolved resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Assigner.Typing typing) { return new Resolved.Simple(MethodVariableAccess.allArgumentsOf(instrumentedMethod), instrumentedMethod.getParameters().asTypeList().asErasures()); }
/** * Increments the value of the supplied parameter. * * @param parameterDescription The parameter which to increment. * @param value The value to increment with. * @return A stack manipulation incrementing the supplied parameter. */ public static StackManipulation increment(ParameterDescription parameterDescription, int value) { return of(parameterDescription.getType()).increment(parameterDescription.getOffset(), value); }
throw new IllegalStateException("Cannot assign " + parameterDescription + " to " + target); valueReads.add(new StackManipulation.Compound(MethodVariableAccess.of(parameterDescription.getType()) .loadFrom(argumentHandler.argument(parameterDescription.getOffset())), readAssignment)); throw new IllegalStateException("Cannot assign " + target + " to " + parameterDescription); valueWrites.add(new StackManipulation.Compound(writeAssignment, MethodVariableAccess.of(parameterDescription.getType()) .storeAt(argumentHandler.argument(parameterDescription.getOffset()))));
@Override protected StackManipulation resolve(TypeDescription instrumentedType) { TypeDefinition superClass = instrumentedType.getSuperClass(); if (superClass == null) { throw new IllegalStateException(instrumentedType + " does not declare a super class"); } return new StackManipulation.Compound(MethodVariableAccess.loadThis(), MethodVariableAccess.REFERENCE.loadFrom(1), MethodInvocation.invoke(EQUALS).special(superClass.asErasure()), ConditionalReturn.onZeroInteger()); } };
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { TypeDescription.Generic parameterType = instrumentedMethod.getParameters().get(0).getType(); MethodDescription setterMethod = methodAccessorFactory.registerSetterFor(fieldDescription, MethodAccessorFactory.AccessType.DEFAULT); StackManipulation.Size stackSize = new StackManipulation.Compound( fieldDescription.isStatic() ? StackManipulation.Trivial.INSTANCE : new StackManipulation.Compound( MethodVariableAccess.loadThis(), FieldAccess.forField(typeDescription.getDeclaredFields() .filter((named(AccessorProxy.FIELD_NAME))).getOnly()).read()), MethodVariableAccess.of(parameterType).loadFrom(1), assigner.assign(parameterType, setterMethod.getParameters().get(0).getType(), Assigner.Typing.DYNAMIC), MethodInvocation.invoke(setterMethod), MethodReturn.VOID ).apply(methodVisitor, implementationContext); return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize()); } }
public StackManipulation assignOperation() { //enqueue the new value as the item to set StackManipulation arg0 = MethodVariableAccess.REFERENCE.loadOffset(1); //load the value to be assigned StackManipulation val = IntegerConstant.forValue(newVal); //load the index StackManipulation indexToAssign = IntegerConstant.forValue(index); //set the return type StackManipulation.Compound compound = new StackManipulation.Compound(arg0, indexToAssign, val); return compound; } }
/** * Loads a reference to the {@code this} reference what is only meaningful for a non-static method. * * @return A stack manipulation loading the {@code this} reference. */ public static StackManipulation loadThis() { return MethodVariableAccess.REFERENCE.loadFrom(0); }
/** * {@inheritDoc} */ public StackManipulation prepare() { return fieldDescription.isStatic() ? StackManipulation.Trivial.INSTANCE : MethodVariableAccess.loadThis(); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { List<StackManipulation> fieldAssignments = new ArrayList<StackManipulation>(declaredFields.size() * 3); for (ParameterDescription parameterDescription : instrumentedMethod.getParameters()) { fieldAssignments.add(MethodVariableAccess.loadThis()); fieldAssignments.add(MethodVariableAccess.load(parameterDescription)); fieldAssignments.add(FieldAccess.forField(declaredFields.get(parameterDescription.getIndex())).write()); } return new Size(new StackManipulation.Compound( MethodVariableAccess.loadThis(), MethodInvocation.invoke(INSTANCE.objectConstructor), new StackManipulation.Compound(fieldAssignments), MethodReturn.VOID ).apply(methodVisitor, implementationContext).getMaximalSize(), instrumentedMethod.getStackSize()); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { MethodDescription.InDefinedShape proxyMethod = methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT); return new StackManipulation.Compound( MethodVariableAccess.loadThis(), fieldLoadingInstruction, MethodVariableAccess.allArgumentsOf(instrumentedMethod).asBridgeOf(proxyMethod), MethodInvocation.invoke(proxyMethod), MethodReturn.of(instrumentedMethod.getReturnType()) ).apply(methodVisitor, implementationContext); } }
/** * {@inheritDoc} */ public Resolved resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Assigner.Typing typing) { ParameterList<?> parameters = instrumentedMethod.getParameters(); if (index >= parameters.size()) { throw new IllegalStateException("No parameter " + index + " for " + instrumentedMethod); } return doResolve(MethodVariableAccess.load(parameters.get(index)), parameters.get(index).getType(), assigner, typing); }
@Override public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) { StackManipulation.Size size = loadThis ? MethodVariableAccess.loadThisReferenceAndArguments(instrumentedMethod).apply(methodVisitor, implementationContext) : MethodVariableAccess.loadArguments(instrumentedMethod).apply(methodVisitor, implementationContext); return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize()); } }
int padding = 0; for (FieldDescription.InDefinedShape fieldDescription : fieldDescriptions) { stackManipulations.add(MethodVariableAccess.loadThis()); stackManipulations.add(FieldAccess.forField(fieldDescription).read()); stackManipulations.add(MethodVariableAccess.REFERENCE.loadFrom(1)); stackManipulations.add(TypeCasting.to(instrumentedType)); stackManipulations.add(FieldAccess.forField(fieldDescription).read());
impls.add(MethodVariableAccess.INTEGER.loadOffset(totalindexarg)); impls.add(MethodVariableAccess.REFERENCE.loadOffset(arrayArgIndex)); impls.add(MethodVariableAccess.REFERENCE.loadOffset(retArrayIndex)); impls.add(IntegerConstant.forValue(i)); impls.add(MethodVariableAccess.INTEGER.loadOffset(linearIndexArg)); impls.add(MethodVariableAccess.INTEGER.loadOffset(totalindexarg)); impls.add(OpStackManipulation.div()); impls.add(ArrayStackManipulation.store()); impls.add(MethodVariableAccess.INTEGER.loadOffset(linearIndexArg)); impls.add(MethodVariableAccess.INTEGER.loadOffset(totalindexarg)); impls.add(OpStackManipulation.mod()); impls.add(new StoreIntStackManipulation(linearIndexArg)); impls.add(MethodVariableAccess.INTEGER.loadOffset(totalindexarg)); impls.add(MethodVariableAccess.REFERENCE.loadOffset(arrayArgIndex)); impls.add(MethodVariableAccess.REFERENCE.loadOffset(retArrayIndex)); impls.add(IntegerConstant.forValue(i)); impls.add(MethodVariableAccess.INTEGER.loadOffset(linearIndexArg)); impls.add(MethodVariableAccess.INTEGER.loadOffset(totalindexarg)); impls.add(OpStackManipulation.div()); impls.add(ArrayStackManipulation.store()); impls.add(MethodVariableAccess.INTEGER.loadOffset(linearIndexArg)); impls.add(MethodVariableAccess.INTEGER.loadOffset(totalindexarg));
@Override public StackManipulation resolve(TypeDescription instrumentedType) { return new StackManipulation.Compound( MethodVariableAccess.REFERENCE.loadFrom(1), ConditionalReturn.onNullValue(), MethodVariableAccess.REFERENCE.loadFrom(0), MethodInvocation.invoke(GET_CLASS), MethodVariableAccess.REFERENCE.loadFrom(1), MethodInvocation.invoke(GET_CLASS), ConditionalReturn.onNonIdentity() ); } },
/** * Prepends a reference to the {@code this} instance to the loaded parameters if the represented method is non-static. * * @return A stack manipulation that loads all method parameters onto the operand stack while additionally loading a reference * to {@code this} if the represented is non-static. Any potential parameter transformation is preserved. */ public StackManipulation prependThisReference() { return methodDescription.isStatic() ? this : new Compound(MethodVariableAccess.loadThis(), this); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { FieldList<?> fieldList = instrumentedType.getDeclaredFields(); StackManipulation[] fieldLoading = new StackManipulation[fieldList.size()]; int index = 0; for (FieldDescription fieldDescription : fieldList) { fieldLoading[index] = new StackManipulation.Compound( MethodVariableAccess.loadThis(), MethodVariableAccess.load(instrumentedMethod.getParameters().get(index)), FieldAccess.forField(fieldDescription).write() ); index++; } StackManipulation.Size stackSize = new StackManipulation.Compound( MethodVariableAccess.loadThis(), MethodInvocation.invoke(ConstructorCall.INSTANCE.objectTypeDefaultConstructor), new StackManipulation.Compound(fieldLoading), MethodReturn.VOID ).apply(methodVisitor, implementationContext); return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize()); } }
/** * {@inheritDoc} */ public StackManipulation resolveIncrement(int value) { return typeDefinition.represents(int.class) ? MethodVariableAccess.of(typeDefinition).increment(offset, value) : new StackManipulation.Compound(resolveRead(), IntegerConstant.forValue(1), Addition.INTEGER, resolveWrite()); } }