/** * 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; }
protected void mergeAnnotationsOnElement(Annotated annotated, boolean overwriteExisting, AnnotationBuilder typeAnnotations) { for (Annotation annotation : annotated.getAnnotations()) { if (typeAnnotations.getAnnotation(annotation.annotationType()) != null) { if (overwriteExisting) { typeAnnotations.remove(annotation.annotationType()); typeAnnotations.add(annotation); } } else { typeAnnotations.add(annotation); } } }
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 (overwrite || !typeAnnotations.isAnnotationPresent(annotation.annotationType())) typeAnnotations.add(annotation); annotationBuilder = new AnnotationBuilder(); fields.put(field, annotationBuilder); if (overwrite || !annotationBuilder.isAnnotationPresent(annotation.annotationType())) annotationBuilder.add(annotation); annotationBuilder = new AnnotationBuilder(); methods.put(method, annotationBuilder); if (overwrite || !annotationBuilder.isAnnotationPresent(annotation.annotationType())) annotationBuilder.add(annotation); parameterAnnotationBuilder = new AnnotationBuilder(); parameters.put(i, parameterAnnotationBuilder); if (overwrite || !parameterAnnotationBuilder.isAnnotationPresent(annotation.annotationType())) parameterAnnotationBuilder.add(annotation); annotationBuilder = new AnnotationBuilder(); constructors.put(constructor, annotationBuilder); if (overwrite || !annotationBuilder.isAnnotationPresent(annotation.annotationType()))
public void redefine(RedefinitionContext<Inject> ctx) { if (ctx.getAnnotatedElement() instanceof Field) { if (ctx.getAnnotatedElement().isAnnotationPresent(Generic.class)) { // This is a Generic bean injection point ctx.getAnnotationBuilder().remove(Inject.class).add(InjectGenericLiteral.INSTANCE); } } }
/** * Remove an annotation from the type * * @param annotationType the annotation type to remove * @throws IllegalArgumentException if the annotationType */ public AnnotatedTypeBuilder<X> removeFromClass(Class<? extends Annotation> annotationType) { typeAnnotations.remove(annotationType); return this; }
/** * Add an annotation to the type declaration. * * @param annotation the annotation instance to add * @throws IllegalArgumentException if the annotation is null */ public AnnotatedTypeBuilder<X> addToClass(Annotation annotation) { typeAnnotations.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>>(); }
fieldAnnotations.put(field.getKey(), field.getValue().create()); methodAnnotations.put(method.getKey(), method.getValue().create()); for (Entry<Integer, AnnotationBuilder> parameter : parameters.getValue().entrySet()) parameterAnnotations.put(parameter.getKey(), parameter.getValue().create()); constructorAnnotations.put(constructor.getKey(), constructor.getValue().create()); for (Entry<Integer, AnnotationBuilder> parameter : parameters.getValue().entrySet()) parameterAnnotations.put(parameter.getKey(), parameter.getValue().create()); return new AnnotatedTypeImpl<X>(javaClass, typeAnnotations.create(), fieldAnnotations, methodAnnotations, methodParameterAnnnotations, constructorAnnotations, constructorParameterAnnnotations, fieldTypes, methodParameterTypes, constructorParameterTypes);
protected <A extends Annotation> void redefineAnnotationBuilder(Class<A> annotationType, AnnotationRedefiner<A> redefinition, AnnotatedElement annotated, Type baseType, AnnotationBuilder builder, String elementName) { if (builder.isAnnotationPresent(annotationType)) { redefinition.redefine(new RedefinitionContext<A>(annotated, baseType, builder, elementName)); } }
public void redefine(RedefinitionContext<Generic> ctx) { // if it is a parameter annotation if (!(ctx.getAnnotatedElement() instanceof AccessibleObject)) { // stick an InjectGeneric as a marker. ctx.getAnnotationBuilder().remove(Generic.class).add(InjectGenericLiteral.INSTANCE); if (ctx.getRawType().isAnnotationPresent(GenericConfiguration.class)) { ctx.getAnnotationBuilder().add(genericBeanQualifier); } } } });
/** * Remove an annotation from the specified constructor. * * @param constructor the constructor to add the annotation to * @param annotation the annotation to add * @throws IllegalArgumentException if the annotationType is null or if the * constructor is not currently declared on the type */ public AnnotatedTypeBuilder<X> removeFromConstructor(Constructor<X> constructor, Class<? extends Annotation> annotationType) { if (constructors.get(constructor) != null) { constructors.get(constructor).remove(annotationType); } return this; }
public AnnotationBuilder addAll(Set<Annotation> annotations) { for (Annotation annotation : annotations) { add(annotation); } return this; }
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());
/** * 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; }
/** * Remove an annotation from the specified constructor parameter. * * @param method the constructor to remove the annotation from * @param position the position of the parameter to remove * @param annotationType the annotation type to remove * @throws IllegalArgumentException if the annotationType is null, if the * constructor is not currently declared on the type or if the * parameter is not declared on the constructor */ public AnnotatedTypeBuilder<X> removeFromConstructorParameter(Constructor<X> constructor, int position, Class<? extends Annotation> annotationType) { if (constructorParameters.get(constructor) != null) { if (constructorParameters.get(constructor).get(position) != null) { constructorParameters.get(constructor).get(position).remove(annotationType); } } return this; }
public AnnotationBuilder addAll(AnnotatedElement element) { for (Annotation a : element.getAnnotations()) { add(a); } 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; }
/** * Remove an annotation from the specified field. * * @param field the field to remove the annotation from * @param annotationType the annotation type to remove * @throws IllegalArgumentException if the annotationType is null or if the * field is not currently declared on the type */ public AnnotatedTypeBuilder<X> removeFromField(Field field, Class<? extends Annotation> annotationType) { if (fields.get(field) == null) { throw new IllegalArgumentException(messages.fieldNotPresent(field, getJavaClass())); } else { fields.get(field).remove(annotationType); } return this; }