private AnnotatedType<Object> decorateType(final AnnotatedType<Object> type, final Class<? extends Annotation> jsfScope) { final Class<? extends Annotation> cdiScope = getCdiScopeFor(jsfScope); AnnotationInstanceProvider provider = new AnnotationInstanceProvider(); final Annotation cdiScopeAnnotation = provider.get(cdiScope, Collections.EMPTY_MAP); AnnotatedTypeBuilder builder; builder = new AnnotatedTypeBuilder() .readFromType(type) .removeFromClass(jsfScope) .addToClass(cdiScopeAnnotation); return builder.create(); } }
public void overrideFieldType(Field field, Class<?> javaClass) { builder.overrideFieldType(field, javaClass); }
public void addToConstructor(Constructor<?> constructor, Annotation annotation) { builder.addToConstructor((Constructor) constructor, annotation); }
private <X> AnnotatedTypeBuilder<X> initializeBuilder(final AnnotatedTypeBuilder<X> currentBuilder, final AnnotatedType<X> source) { if (currentBuilder == null) { return new AnnotatedTypeBuilder<X>().readFromType(source); } return currentBuilder; }
public BeanResult(Class<X> type, boolean readAnnotations, BeanResultType beanType, List<FieldValueObject> fieldValues, List<BeanResult<?>> inlineBeans, BeanManager beanManager) { this.beanManager = beanManager; this.type = type; builder = new AnnotatedTypeBuilder<X>().setJavaClass(type); builder.addToClass(XmlConfiguredBeanLiteral.INSTANCE); if (readAnnotations) { builder.readFromType(type); // we don't want to keep the veto annotation on the class builder.removeFromClass(Veto.class); } this.beanType = beanType; this.fieldValues = new ArrayList<FieldValueObject>(fieldValues); this.inlineBeans = new ArrayList<BeanResult<?>>(inlineBeans); }
builder = new AnnotatedTypeBuilder<X>().readFromType(tp); for (Annotation a : tp.getAnnotations()) builder.removeFromClass(a.annotationType()); builder.addToClass(declaringBeanSyntheticQualifier); builder.removeFromMethodParameter(m.getJavaMember(), observerParameter.getPosition(), a.annotationType()); builder.addToMethodParameter(m.getJavaMember(), observerParameter.getPosition(), declaringBeanSyntheticQualifier); ObserverMethodInfo<?> info = ObserverMethodInfo.of(observerQualifiers, declaringBeanQualifiers, m, declaringBeanSyntheticQualifier); defaultObserverMethodsByBean.put(declaringBeanSyntheticQualifier, info); builder = new AnnotatedTypeBuilder<X>().readFromType(tp); builder.removeFromMethod(m, a.annotationType()); builder.addToMethod(m, syntheticQualifier); producerToDeclaringDefaultBean.put(syntheticQualifier, new DefaultBeanQualifiers(declaringBeanSyntheticQualifier, declaringBeanQualifiers)); builder = new AnnotatedTypeBuilder<X>().readFromType(tp); builder.removeFromField(f, a.annotationType()); builder.addToField(f, syntheticQualifier); producerToDeclaringDefaultBean.put(syntheticQualifier, new DefaultBeanQualifiers(declaringBeanSyntheticQualifier, declaringBeanQualifiers)); event.setAnnotatedType(builder.create());
builder.addToClass(namedFromPackage); builder.removeFromClass(Named.class); // add w/o remove was failing in cases builder.addToClass(new NamedLiteral(qualify(targetPackage, name))); builder.overrideFieldType(f, type); builder.removeFromField(f, Named.class); // add w/o remove was failing in cases builder.addToField(f, new NamedLiteral(qualify(targetPackage, name))); builder.overrideParameterType(p, type); builder.removeFromMethod(m, Named.class); // add w/o remove was failing in cases builder.addToMethod(m, new NamedLiteral(qualify(targetPackage, name))); builder.overrideParameterType(p, type); pat.setAnnotatedType(builder.create());
final AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(type); builder.addToClass(genericBeanQualifier); builder.redefine(Inject.class, new AnnotationRedefiner<Inject>() builder.redefine(Produces.class, new AnnotationRedefiner<Produces>() { builder.redefine(Disposes.class, new AnnotationRedefiner<Disposes>() builder.redefine(Generic.class, new AnnotationRedefiner<Generic>() event.setAnnotatedType(builder.create());
<X> void detectBundleInjectionTargets(@Observes ProcessInjectionTarget<X> event, BeanManager beanManager) { AnnotatedType<X> type = event.getAnnotatedType(); for (AnnotatedField<?> f : type.getFields()) { Field field = f.getJavaMember(); Class<?> clz = field.getType(); if (clz.isAnnotationPresent(MessageBundle.class)) { log.info("Add @MessageBundle to " + type.getJavaClass().getName() + "." + field.getName() + " injection point for the type: " + clz.getName()); AnnotatedTypeBuilder<X> typeBuilder = new AnnotatedTypeBuilder<X>().readFromType(type); typeBuilder.addToField(field, MessageBundleLiteral.INSTANCE); event.setInjectionTarget(beanManager.createInjectionTarget(typeBuilder.create())); } } } }
public <T> void processAnnotatedType(@Observes final ProcessAnnotatedType<T> event) { AnnotatedTypeBuilder<T> builder = new AnnotatedTypeBuilder<T>(); builder.readFromType(event.getAnnotatedType()); boolean modifiedType = false; for (AnnotatedField<?> f : event.getAnnotatedType().getFields()) { if (f.isAnnotationPresent(InputField.class)) { builder.overrideFieldType(f.getJavaMember(), Object.class); modifiedType = true; } } if (modifiedType) { AnnotatedType<T> replacement = builder.create(); typeOverrides.put(replacement.getJavaClass(), replacement); event.setAnnotatedType(replacement); } }
/** * Creates a wrapper around an AutoProxy handler class * * @param handlerClass The handler class * @throws IllegalArgumentException if the handler class is does not have a * suitable @AroundInvoke method */ ServiceHandlerManager(Class<T> handlerClass, BeanManager beanManager) throws IllegalArgumentException { this.handlerClass = handlerClass; handlerMethod = getHandlerMethod(handlerClass); //now create the InjectionTarget AnnotatedTypeBuilder<T> typeBuilder = new AnnotatedTypeBuilder<T>().readFromType(handlerClass); injectionTarget = beanManager.createInjectionTarget(typeBuilder.create()); }
public void addToClass(Annotation annotation) { // TODO: this should be done with the BeanManager one WELD-721 is resolved if (annotation.annotationType().isAnnotationPresent(Scope.class) || annotation.annotationType().isAnnotationPresent(NormalScope.class)) { // if the user is adding a new scope we need to remove any existing // ones for (Annotation typeAnnotation : type.getAnnotations()) { if (typeAnnotation.annotationType().isAnnotationPresent(Scope.class) || typeAnnotation.annotationType().isAnnotationPresent(NormalScope.class)) { builder.removeFromClass(typeAnnotation.annotationType()); } } } builder.addToClass(annotation); }
public void addToField(Field field, Annotation annotation) { if (annotation.annotationType().isAnnotationPresent(Scope.class) || annotation.annotationType().isAnnotationPresent(NormalScope.class)) { for (Annotation typeAnnotation : field.getAnnotations()) { if (typeAnnotation.annotationType().isAnnotationPresent(Scope.class) || typeAnnotation.annotationType().isAnnotationPresent(NormalScope.class)) { builder.removeFromField(field, typeAnnotation.annotationType()); } } } builder.addToField(field, annotation); }
/** * Reads in from an existing AnnotatedType. Any elements not present are * added. The javaClass will be read in. If the annotation already exists on * that element in the builder the read annotation will be used. * * @param type the type to read from * @throws IllegalArgumentException if type is null */ public AnnotatedTypeBuilder<X> readFromType(AnnotatedType<X> type) { return readFromType(type, true); }
public AnnotatedType<?> getAnnotatedType() { return builder.create(); }
public void addToMethod(Method method, Annotation annotation) { if (annotation.annotationType().isAnnotationPresent(Scope.class) || annotation.annotationType().isAnnotationPresent(NormalScope.class)) { for (Annotation typeAnnotation : method.getAnnotations()) { if (typeAnnotation.annotationType().isAnnotationPresent(Scope.class) || typeAnnotation.annotationType().isAnnotationPresent(NormalScope.class)) { builder.removeFromMethod(method, typeAnnotation.annotationType()); } } } builder.addToMethod(method, annotation); }
/** * Add an annotation to the specified parameter. If the callable which * declares the parameter is not already present, it will be added. If the * parameter is not already present on the callable, it will be added. * * @param parameter the parameter to add the annotation to * @param annotation the annotation to add * @throws IllegalArgumentException if the annotation is null or if the * parameter is not declared on either a constructor or a method */ public AnnotatedTypeBuilder<X> addToParameter(AnnotatedParameter<? super X> parameter, Annotation annotation) { if (parameter.getDeclaringCallable().getJavaMember() instanceof Method) { Method method = (Method) parameter.getDeclaringCallable().getJavaMember(); return addToMethodParameter(method, parameter.getPosition(), annotation); } if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>) { @SuppressWarnings("unchecked") Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember(); return addToConstructorParameter(constructor, parameter.getPosition(), annotation); } else { throw new IllegalArgumentException("Cannot remove from parameter " + parameter + " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember()); } }
/** * 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(AnnotatedField<? super X> field, Annotation annotation) { return addToField(field.getJavaMember(), annotation); }
removeFromClass(annotationType); for (Entry<Field, AnnotationBuilder> field : fields.entrySet())
public void addToConstructorParameter(Constructor<?> constructor, int param, Annotation annotation) { builder.addToConstructorParameter((Constructor) constructor, param, annotation); }