Generic parameterType = parameterDescription.getType(); if (!parameterType.accept(Generic.Visitor.Validator.METHOD_PARAMETER)) { throw new IllegalStateException("Illegal parameter type of " + parameterDescription + " for " + methodDescription); throw new IllegalStateException("Invisible parameter type of " + parameterDescription + " for " + methodDescription); if (parameterDescription.isNamed()) { String parameterName = parameterDescription.getName(); if (!parameterNames.add(parameterName)) { throw new IllegalStateException("Duplicate parameter name of " + parameterDescription + " for " + methodDescription); if (parameterDescription.hasModifiers() && (parameterDescription.getModifiers() & ~ModifierContributor.ForParameter.MASK) != EMPTY_MASK) { throw new IllegalStateException("Illegal modifiers of " + parameterDescription + " for " + methodDescription); for (AnnotationDescription annotationDescription : parameterDescription.getDeclaredAnnotations()) { if (!annotationDescription.getElementTypes().contains(ElementType.PARAMETER)) { throw new IllegalStateException("Cannot add " + annotationDescription + " on " + parameterDescription);
for (ParameterDescription.InDefinedShape parameterDescription : adviceMethod.getParameters()) { OffsetMapping offsetMapping = null; for (AnnotationDescription annotationDescription : parameterDescription.getDeclaredAnnotations()) { OffsetMapping.Factory<?> factory = offsetMappings.get(annotationDescription.getAnnotationType()); if (factory != null) { this.offsetMappings.put(parameterDescription.getOffset(), offsetMapping == null ? new OffsetMapping.ForArgument.Unresolved(parameterDescription) : offsetMapping);
private List<StackManipulation> loadSignatureParametersClasess() { List<StackManipulation> constructorSignature = new ArrayList<StackManipulation>(); for (InDefinedShape targetParameter : targetParameters) { constructorSignature.add( ClassConstant.of(targetParameter.getType().asErasure()) ); } return constructorSignature; }
int index = 0, currentStackSize = 0, maximumStackSize = 0; for (OffsetMapping.Target offsetMapping : offsetMappings) { currentStackSize += adviceMethod.getParameters().get(index++).getType().getStackSize().getSize(); maximumStackSize = Math.max(maximumStackSize, currentStackSize + offsetMapping.resolveRead() .apply(methodVisitor, implementationContext)
/** * Creates a binder by installing two proxy types which are implemented by this binder if a field getter * or a field setter is requested by using the * {@link FieldProxy} annotation. * * @param getterType The type which should be used for getter proxies. The type must * represent an interface which defines a single method which returns an * {@link java.lang.Object} return type and does not take any arguments. The use of generics * is permitted. * @param setterType The type which should be uses for setter proxies. The type must * represent an interface which defines a single method which returns {@code void} * and takes a single {@link java.lang.Object}-typed argument. The use of generics * is permitted. * @return A binder for the {@link FieldProxy} annotation. */ public static TargetMethodAnnotationDrivenBinder.ParameterBinder<FieldProxy> install(TypeDescription getterType, TypeDescription setterType) { MethodDescription.InDefinedShape getterMethod = onlyMethod(getterType); if (!getterMethod.getReturnType().asErasure().represents(Object.class)) { throw new IllegalArgumentException(getterMethod + " must take a single Object-typed parameter"); } else if (getterMethod.getParameters().size() != 0) { throw new IllegalArgumentException(getterMethod + " must not declare parameters"); } MethodDescription.InDefinedShape setterMethod = onlyMethod(setterType); if (!setterMethod.getReturnType().asErasure().represents(void.class)) { throw new IllegalArgumentException(setterMethod + " must return void"); } else if (setterMethod.getParameters().size() != 1 || !setterMethod.getParameters().get(0).getType().asErasure().represents(Object.class)) { throw new IllegalArgumentException(setterMethod + " must declare a single Object-typed parameters"); } return new Binder(getterMethod, setterMethod); }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Origin> annotation, AdviceType adviceType) { if (target.getType().asErasure().represents(Class.class)) { return OffsetMapping.ForInstrumentedType.INSTANCE; } else if (target.getType().asErasure().represents(Method.class)) { return OffsetMapping.ForInstrumentedMethod.METHOD; } else if (target.getType().asErasure().represents(Constructor.class)) { return OffsetMapping.ForInstrumentedMethod.CONSTRUCTOR; } else if (JavaType.EXECUTABLE.getTypeStub().equals(target.getType().asErasure())) { return OffsetMapping.ForInstrumentedMethod.EXECUTABLE; } else if (target.getType().asErasure().isAssignableFrom(String.class)) { return ForOrigin.parse(annotation.loadSilent().value()); } else { throw new IllegalStateException("Non-supported type " + target.getType() + " for @Origin annotation"); } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<AllArguments> annotation, AdviceType adviceType) { if (!target.getType().represents(Object.class) && !target.getType().isArray()) { throw new IllegalStateException("Cannot use AllArguments annotation on a non-array type"); } else if (adviceType.isDelegation() && !annotation.loadSilent().readOnly()) { throw new IllegalStateException("Cannot define writable field access for " + target); } else { return new ForAllArguments(target.getType().represents(Object.class) ? TypeDescription.Generic.OBJECT : target.getType().getComponentType(), annotation.loadSilent()); } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<FieldValue> annotation, AdviceType adviceType) { if (adviceType.isDelegation() && !annotation.getValue(ForField.READ_ONLY).resolve(Boolean.class)) { throw new IllegalStateException("Cannot write to field for " + target + " in read-only context"); } else { TypeDescription declaringType = annotation.getValue(DECLARING_TYPE).resolve(TypeDescription.class); return declaringType.represents(void.class) ? new WithImplicitType(target.getType(), annotation) : new WithExplicitType(target.getType(), annotation, declaringType); } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Local> annotation, AdviceType adviceType) { String name = annotation.loadSilent().value(); TypeDefinition namedType = namedTypes.get(name); if (namedType == null) { throw new IllegalStateException("Named local variable is unknown: " + name); } return new ForLocalValue(target.getType(), namedType.asGenericType(), name); } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Thrown> annotation, AdviceType adviceType) { if (adviceType.isDelegation() && !annotation.loadSilent().readOnly()) { throw new IllegalStateException("Cannot use writable " + target + " on read-only parameter"); } else { return new ForThrowable(target.getType(), annotation.loadSilent()); } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Return> annotation, AdviceType adviceType) { if (adviceType.isDelegation() && !annotation.loadSilent().readOnly()) { throw new IllegalStateException("Cannot write return value for " + target + " in read-only context"); } else { return new ForReturnValue(target.getType(), annotation.loadSilent()); } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Exit> annotation, AdviceType adviceType) { if (adviceType.isDelegation() && !annotation.loadSilent().readOnly()) { throw new IllegalStateException("Cannot use writable " + target + " on read-only parameter"); } else { return new ForExitValue(target.getType(), exitType.asGenericType(), annotation.loadSilent()); } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Enter> annotation, AdviceType adviceType) { if (adviceType.isDelegation() && !annotation.loadSilent().readOnly()) { throw new IllegalStateException("Cannot use writable " + target + " on read-only parameter"); } else { return new ForEnterValue(target.getType(), enterType.asGenericType(), annotation.loadSilent()); } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<This> annotation, AdviceType adviceType) { if (adviceType.isDelegation() && !annotation.loadSilent().readOnly()) { throw new IllegalStateException("Cannot write to this reference for " + target + " in read-only context"); } else { return new ForThisReference(target.getType(), annotation.loadSilent()); } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Argument> annotation, AdviceType adviceType) { if (adviceType.isDelegation() && !annotation.loadSilent().readOnly()) { throw new IllegalStateException("Cannot define writable field access for " + target + " when using delegation"); } else { return new ForArgument.Unresolved(target.getType(), annotation.loadSilent()); } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<StubValue> annotation, AdviceType adviceType) { if (!target.getType().represents(Object.class)) { throw new IllegalStateException("Cannot use StubValue on non-Object parameter type " + target); } else { return this; } } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<T> annotation, AdviceType adviceType) { return new ForSerializedValue(target.getType(), typeDescription, deserialization); } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<T> annotation, AdviceType adviceType) { return new ForStackManipulation(stackManipulation, typeDescription, target.getType(), Assigner.Typing.STATIC); } }
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Unused> annotation, AdviceType adviceType) { return new ForUnusedValue(target.getType()); } }