/** * Add an annotation to the specified constructor. If the constructor is not * already present, it will be added. * * @param constructor the constructor to add the annotation to * @param annotation the annotation to add * @throws IllegalArgumentException if the annotation is null */ public AnnotatedTypeBuilder<X> addToConstructor(Constructor<X> constructor, Annotation annotation) { if (constructors.get(constructor) == null) { constructors.put(constructor, new AnnotationBuilder()); } constructors.get(constructor).add(annotation); return this; }
/** * Create a new builder. A new builder has no annotations and no members. * * @see #readFromType(AnnotatedType) * @see #readFromType(Class) * @see #readFromType(AnnotatedType, boolean) * @see #readFromType(Class, boolean) */ public AnnotatedTypeBuilder() { this.typeAnnotations = new AnnotationBuilder(); this.constructors = new HashMap<Constructor<?>, AnnotationBuilder>(); this.constructorParameters = new HashMap<Constructor<?>, Map<Integer, AnnotationBuilder>>(); this.constructorParameterTypes = new HashMap<Constructor<?>, Map<Integer, Type>>(); this.fields = new HashMap<Field, AnnotationBuilder>(); this.fieldTypes = new HashMap<Field, Type>(); this.methods = new HashMap<Method, AnnotationBuilder>(); this.methodParameters = new HashMap<Method, Map<Integer, AnnotationBuilder>>(); this.methodParameterTypes = new HashMap<Method, Map<Integer, Type>>(); }
/** * Add an annotation to the specified field. If the field is not already * present, it will be added. * * @param field the field to add the annotation to * @param annotation the annotation to add * @throws IllegalArgumentException if the annotation is null */ public AnnotatedTypeBuilder<X> addToField(Field field, Annotation annotation) { if (fields.get(field) == null) { fields.put(field, new AnnotationBuilder()); } fields.get(field).add(annotation); return this; }
/** * Add an annotation to the specified method. If the method is not already * present, it will be added. * * @param method the method to add the annotation to * @param annotation the annotation to add * @throws IllegalArgumentException if the annotation is null */ public AnnotatedTypeBuilder<X> addToMethod(Method method, Annotation annotation) { if (methods.get(method) == null) { methods.put(method, new AnnotationBuilder()); } methods.get(method).add(annotation); return this; }
/** * Add an annotation to the specified method parameter. If the method is not * already present, it will be added. If the method parameter is not already * present, it will be added. * * @param method the method to add the annotation to * @param position the position of the parameter to add * @param annotation the annotation to add * @throws IllegalArgumentException if the annotation is null */ public AnnotatedTypeBuilder<X> addToMethodParameter(Method method, int position, Annotation annotation) { if (!methods.containsKey(method)) { methods.put(method, new AnnotationBuilder()); } if (methodParameters.get(method) == null) { methodParameters.put(method, new HashMap<Integer, AnnotationBuilder>()); } if (methodParameters.get(method).get(position) == null) { methodParameters.get(method).put(position, new AnnotationBuilder()); } methodParameters.get(method).get(position).add(annotation); return this; }
/** * Add an annotation to the specified constructor parameter. If the * constructor is not already present, it will be added. If the constructor * parameter is not already present, it will be added. * * @param method the constructor to add the annotation to * @param position the position of the parameter to add * @param annotation the annotation to add * @throws IllegalArgumentException if the annotation is null */ public AnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int position, Annotation annotation) { if (!constructors.containsKey(constructor)) { constructors.put(constructor, new AnnotationBuilder()); } if (constructorParameters.get(constructor) == null) { constructorParameters.put(constructor, new HashMap<Integer, AnnotationBuilder>()); } if (constructorParameters.get(constructor).get(position) == null) { constructorParameters.get(constructor).put(position, new AnnotationBuilder()); } constructorParameters.get(constructor).get(position).add(annotation); return this; }
private static <X, Y extends Member> List<AnnotatedParameter<X>> getAnnotatedParameters(AnnotatedCallableImpl<X, Y> callable, Class<?>[] parameterTypes, Type[] genericTypes, Map<Integer, AnnotationStore> parameterAnnotations, Map<Integer, Type> parameterTypeOverrides) { List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>(); int len = parameterTypes.length; for (int i = 0; i < len; ++i) { AnnotationBuilder builder = new AnnotationBuilder(); if (parameterAnnotations != null && parameterAnnotations.containsKey(i)) { builder.addAll(parameterAnnotations.get(i)); } Type over = null; if (parameterTypeOverrides != null) { over = parameterTypeOverrides.get(i); } AnnotatedParameterImpl<X> p = new AnnotatedParameterImpl<X>(callable, parameterTypes[i], i, builder.create(), genericTypes[i], over); parameters.add(p); } return parameters; }
if (annotationBuilder == null) annotationBuilder = new AnnotationBuilder(); fields.put(field, annotationBuilder); if (annotationBuilder == null) annotationBuilder = new AnnotationBuilder(); methods.put(method, annotationBuilder); if (parameterAnnotationBuilder == null) parameterAnnotationBuilder = new AnnotationBuilder(); parameters.put(i, parameterAnnotationBuilder); if (annotationBuilder == null) annotationBuilder = new AnnotationBuilder(); constructors.put(constructor, annotationBuilder); if (parameterAnnotationBuilder == null) parameterAnnotationBuilder = new AnnotationBuilder(); mparams.put(i, parameterAnnotationBuilder);
fields.put(field.getJavaMember(), new AnnotationBuilder()); methods.put(method.getJavaMember(), new AnnotationBuilder()); methodParameters.get(method.getJavaMember()).put(p.getPosition(), new AnnotationBuilder()); constructors.put(constructor.getJavaMember(), new AnnotationBuilder()); constructorParameters.get(constructor.getJavaMember()).put(p.getPosition(), new AnnotationBuilder());