Refine search
/** * Creates a new builder for the binding of a given method. * * @param methodInvoker The method invoker that is used to create the method invocation of the {@code target} method. * @param candidate The target method that is target of the binding. */ public Builder(MethodInvoker methodInvoker, MethodDescription candidate) { this.methodInvoker = methodInvoker; this.candidate = candidate; parameterStackManipulations = new ArrayList<StackManipulation>(candidate.getParameters().size()); registeredTargetIndices = new LinkedHashMap<Object, Integer>(); nextParameterIndex = 0; }
/** * {@inheritDoc} */ public List<ArgumentLoader> resolve(MethodDescription instrumentedMethod, MethodDescription invokedMethod) { if (index >= instrumentedMethod.getParameters().size()) { throw new IllegalStateException(instrumentedMethod + " does not have a parameter with index " + index); } return Collections.<ArgumentLoader>singletonList(new ForMethodParameter(index, instrumentedMethod)); } }
/** * {@inheritDoc} */ public List<ArgumentLoader> resolve(MethodDescription instrumentedMethod, MethodDescription invokedMethod) { List<ArgumentLoader> argumentLoaders = new ArrayList<ArgumentLoader>(instrumentedMethod.getParameters().size()); for (ParameterDescription parameterDescription : instrumentedMethod.getParameters()) { argumentLoaders.add(new ForMethodParameter(parameterDescription.getIndex(), instrumentedMethod)); } return argumentLoaders; } }
@Override protected ParameterDescription resolve(MethodDescription instrumentedMethod) { ParameterList<?> parameters = instrumentedMethod.getParameters(); if (parameters.size() <= index) { throw new IllegalStateException(instrumentedMethod + " does not define an index " + index); } else { return parameters.get(index); } }
/** * {@inheritDoc} */ public AnnotationAppender.Target make(MethodVisitor methodVisitor, MethodDescription methodDescription) { if (parameterIndex >= methodDescription.getParameters().size()) { throw new IllegalArgumentException("Method " + methodDescription + " has less then " + parameterIndex + " parameters"); } return new AnnotationAppender.Target.OnMethodParameter(methodVisitor, parameterIndex); } }
/** * {@inheritDoc} */ public TargetHandler.Resolved resolve(MethodDescription instrumentedMethod) { if (instrumentedMethod.getParameters().size() < index) { throw new IllegalArgumentException(instrumentedMethod + " does not have a parameter with index " + index); } return new Resolved(instrumentedMethod.getParameters().get(index)); }
@Override protected int copy(TypeDescription instrumentedType, MethodDescription instrumentedMethod, MethodDescription methodDescription, Object[] localVariable, Object[] translated) { int length = instrumentedMethod.getParameters().size() + (instrumentedMethod.isStatic() ? 0 : 1); System.arraycopy(localVariable, 0, translated, 0, length); return length; }
/** * {@inheritDoc} */ public List<ArgumentLoader> resolve(MethodDescription instrumentedMethod, MethodDescription invokedMethod) { if (instrumentedMethod.getParameters().size() <= index) { throw new IllegalStateException(instrumentedMethod + " does not declare a parameter with index " + index); } else if (!instrumentedMethod.getParameters().get(index).getType().isArray()) { throw new IllegalStateException("Cannot access an item from non-array parameter " + instrumentedMethod.getParameters().get(index)); } List<ArgumentLoader> argumentLoaders = new ArrayList<ArgumentLoader>(instrumentedMethod.getParameters().size()); for (int index = 0; index < invokedMethod.getParameters().size(); index++) { argumentLoaders.add(new ForMethodParameterArrayElement(instrumentedMethod.getParameters().get(this.index), index++)); } return argumentLoaders; } }
/** * {@inheritDoc} */ public List<ArgumentLoader> resolve(MethodDescription instrumentedMethod, MethodDescription invokedMethod) { if (instrumentedMethod.getParameters().size() <= index) { throw new IllegalStateException(instrumentedMethod + " does not declare a parameter with index " + index); } else if (!instrumentedMethod.getParameters().get(index).getType().isArray()) { throw new IllegalStateException("Cannot access an item from non-array parameter " + instrumentedMethod.getParameters().get(index)); } return Collections.<ArgumentLoader>singletonList(new ForMethodParameterArrayElement(instrumentedMethod.getParameters().get(index), arrayIndex)); } }
/** * {@inheritDoc} */ public Resolution resolve(MethodDescription source, MethodDelegationBinder.MethodBinding left, MethodDelegationBinder.MethodBinding right) { int leftLength = left.getTarget().getParameters().size(); int rightLength = right.getTarget().getParameters().size(); if (leftLength == rightLength) { return Resolution.AMBIGUOUS; } else if (leftLength < rightLength) { return Resolution.RIGHT; } else { return Resolution.LEFT; } } }
/** * {@inheritDoc} */ public MethodDelegationBinder.Record compile(MethodDescription candidate) { if (IgnoreForBinding.Verifier.check(candidate)) { return MethodDelegationBinder.Record.Illegal.INSTANCE; } List<DelegationProcessor.Handler> handlers = new ArrayList<DelegationProcessor.Handler>(candidate.getParameters().size()); for (ParameterDescription parameterDescription : candidate.getParameters()) { handlers.add(delegationProcessor.prepare(parameterDescription)); } return new Record(candidate, handlers, RuntimeType.Verifier.check(candidate)); }
/** * Creates a binding that represents the bindings collected by this {@code Builder}. * * @param terminatingManipulation A stack manipulation that is applied after the method invocation. * @return A binding representing the parameter bindings collected by this builder. */ public MethodBinding build(StackManipulation terminatingManipulation) { if (candidate.getParameters().size() != nextParameterIndex) { throw new IllegalStateException("The number of parameters bound does not equal the target's number of parameters"); } return new Build(candidate, registeredTargetIndices, methodInvoker.invoke(candidate), parameterStackManipulations, terminatingManipulation); }
/** * {@inheritDoc} */ public int variable(int index) { return (instrumentedMethod.isStatic() ? 0 : 1) + instrumentedMethod.getParameters().size() + (exitType.represents(void.class) ? 0 : 1) + namedTypes.size() + (enterType.represents(void.class) ? 0 : 1) + index; }
/** * {@inheritDoc} */ protected StackManipulation resolve(Void unused, FieldDescription fieldDescription, TypeDescription instrumentedType, MethodDescription instrumentedMethod) { if (instrumentedMethod.getParameters().size() <= index) { throw new IllegalStateException(instrumentedMethod + " does not define a parameter with index " + index); } else { return new StackManipulation.Compound( MethodVariableAccess.load(instrumentedMethod.getParameters().get(index)), assigner.assign(instrumentedMethod.getParameters().get(index).getType(), fieldDescription.getType(), typing) ); } }
/** * Creates a new harmonized key for the given method description. * * @param methodDescription The method description to represent as a harmonized key. * @param harmonizer The harmonizer to use. * @param <Q> The type of the token yielded by a harmonizer. * @return A harmonized key representing the provided method. */ protected static <Q> Harmonized<Q> of(MethodDescription methodDescription, Harmonizer<Q> harmonizer) { MethodDescription.TypeToken typeToken = methodDescription.asTypeToken(); return new Harmonized<Q>(methodDescription.getInternalName(), methodDescription.getParameters().size(), Collections.singletonMap(harmonizer.harmonize(typeToken), Collections.<MethodDescription.TypeToken>emptySet())); }
/** * {@inheritDoc} */ public int variable(int index) { return index < (instrumentedMethod.isStatic() ? 0 : 1) + instrumentedMethod.getParameters().size() ? index : index + (exitType.represents(void.class) ? 0 : 1) + StackSize.of(namedTypes.values()) + (enterType.represents(void.class) ? 0 : 1); }
/** * {@inheritDoc} */ public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, ArgumentHandler argumentHandler, Sort sort) { if (optional && instrumentedMethod.getParameters().size() <= index) { return readOnly ? new Target.ForDefaultValue.ReadOnly(target) : new Target.ForDefaultValue.ReadWrite(target); } return super.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler, sort); }
/** * {@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); }
/** * Creates a method attribute appender factory that writes all annotations of a given method, both the method * annotations themselves and all annotations that are defined for every parameter. * * @param methodDescription The method from which to extract the annotations. * @return A method attribute appender factory for an appender that writes all annotations of the supplied method. */ public static Factory of(MethodDescription methodDescription) { ParameterList<?> parameters = methodDescription.getParameters(); List<MethodAttributeAppender.Factory> methodAttributeAppenders = new ArrayList<MethodAttributeAppender.Factory>(parameters.size() + 1); methodAttributeAppenders.add(new Explicit(methodDescription.getDeclaredAnnotations())); for (ParameterDescription parameter : parameters) { methodAttributeAppenders.add(new Explicit(parameter.getIndex(), parameter.getDeclaredAnnotations())); } return new Factory.Compound(methodAttributeAppenders); }
case Opcodes.F_FULL: case Opcodes.F_NEW: if (methodDescription.getParameters().size() + (methodDescription.isStatic() ? 0 : 1) > localVariableLength) { throw new IllegalStateException("Inconsistent frame length for " + methodDescription + ": " + localVariableLength); for (int index = 0; index < methodDescription.getParameters().size(); index++) { if (!toFrame(methodDescription.getParameters().get(index).getType().asErasure()).equals(localVariable[index + offset])) { throw new IllegalStateException(methodDescription + " is inconsistent at " + index + ": " + localVariable[index + offset]); - methodDescription.getParameters().size() + (instrumentedMethod.isStatic() ? 0 : 1) + instrumentedMethod.getParameters().size() + additionalTypes.size()]; int index = translationMode.copy(instrumentedType, instrumentedMethod, methodDescription, localVariable, translated); methodDescription.getParameters().size() + (methodDescription.isStatic() ? 0 : 1), translated, index,