<X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> event, BeanManager beanManager)
{
boolean defaultBean = false;
AnnotatedType<X> tp = event.getAnnotatedType();
AnnotatedTypeBuilder<X> builder = null;
Synthetic declaringBeanSyntheticQualifier = null;
Set<Annotation> declaringBeanQualifiers = null;
if (event.getAnnotatedType().isAnnotationPresent(DefaultBean.class))
{
Set<Annotation> qualifiers = new HashSet<Annotation>();
defaultBean = true;
builder = new AnnotatedTypeBuilder<X>().readFromType(tp);
for (Annotation a : tp.getAnnotations())
{
// remove the qualifiers
if (beanManager.isQualifier(a.annotationType()))
{
qualifiers.add(a);
builder.removeFromClass(a.annotationType());
}
}
if (qualifiers.isEmpty())
{
qualifiers.add(DefaultLiteral.INSTANCE);
}
declaringBeanQualifiers = new HashSet<Annotation>(qualifiers);
declaringBeanSyntheticQualifier = syntheticProvider.get();
// store the qualifiers for later
beanTypeInformation.put(declaringBeanSyntheticQualifier, new DefaultBeanType(qualifiers, tp.getAnnotation(DefaultBean.class).value()));
builder.addToClass(declaringBeanSyntheticQualifier);
// now loop though observer methods and replace qualifiers
for (AnnotatedMethod<? super X> m : tp.getMethods())
{
AnnotatedParameter<? super X> observerParameter = null;
for (AnnotatedParameter<? super X> p : m.getParameters())
{
if (p.isAnnotationPresent(Observes.class))
{
observerParameter = p;
break;
}
}
if (observerParameter != null)
{
// we have an observer method
Set<Annotation> observerQualifiers = new HashSet<Annotation>();
for (Annotation a : observerParameter.getAnnotations())
{
// remove all qualifiers
if (beanManager.isQualifier(a.annotationType()))
{
observerQualifiers.add(a);
builder.removeFromMethodParameter(m.getJavaMember(), observerParameter.getPosition(), a.annotationType());
}
}
if (qualifiers.isEmpty())
{
qualifiers.add(DefaultLiteral.INSTANCE);
}
builder.addToMethodParameter(m.getJavaMember(), observerParameter.getPosition(), declaringBeanSyntheticQualifier);
ObserverMethodInfo<?> info = ObserverMethodInfo.of(observerQualifiers, declaringBeanQualifiers, m, declaringBeanSyntheticQualifier);
defaultObserverMethodsByBean.put(declaringBeanSyntheticQualifier, info);
defaultObserverMethods.put(m.getJavaMember(), info);
}
}
}
// now look for producer methods
// if this bean is a default bean then all producers are default beans
// otherwise the annotaion needs to be present
for (AnnotatedMethod<? super X> m : tp.getMethods())
{
if (m.isAnnotationPresent(Produces.class) && (defaultBean || m.isAnnotationPresent(DefaultBean.class)))
{
if (declaringBeanQualifiers == null)
{
declaringBeanQualifiers = new HashSet<Annotation>(Beans.getQualifiers(beanManager, tp.getAnnotations()));
if (declaringBeanQualifiers.isEmpty())
{
declaringBeanQualifiers.add(DefaultLiteral.INSTANCE);
}
}
if (builder == null)
{
builder = new AnnotatedTypeBuilder<X>().readFromType(tp);
}
Set<Annotation> qualifiers = new HashSet<Annotation>();
for (Annotation a : m.getAnnotations())
{
// remove the qualifiers
if (beanManager.isQualifier(a.annotationType()))
{
qualifiers.add(a);
builder.removeFromMethod(m, a.annotationType());
}
}
if (qualifiers.isEmpty())
{
qualifiers.add(DefaultLiteral.INSTANCE);
}
Synthetic syntheticQualifier = producerSyntheticProvider.get();
// store the qualifiers for later
Type type = null;
// if the type is not explicity set then we infer it
if (m.isAnnotationPresent(DefaultBean.class))
{
type = m.getAnnotation(DefaultBean.class).value();
}
else
{
type = m.getJavaMember().getGenericReturnType();
}
beanTypeInformation.put(syntheticQualifier, new DefaultBeanType(qualifiers, type));
builder.addToMethod(m, syntheticQualifier);
producerToDeclaringDefaultBean.put(syntheticQualifier, new DefaultBeanQualifiers(declaringBeanSyntheticQualifier, declaringBeanQualifiers));
}
}
for (AnnotatedField<? super X> f : tp.getFields())
{
if (f.isAnnotationPresent(Produces.class) && (defaultBean || f.isAnnotationPresent(DefaultBean.class)))
{
if (declaringBeanQualifiers == null)
{
declaringBeanQualifiers = new HashSet<Annotation>(Beans.getQualifiers(beanManager, tp.getAnnotations()));
if (declaringBeanQualifiers.isEmpty())
{
declaringBeanQualifiers.add(DefaultLiteral.INSTANCE);
}
}
// we do not support producer fields on normal scoped beans
// as proxies prevent us from reading the fields
for (Annotation i : tp.getAnnotations())
{
if (beanManager.isNormalScope(i.annotationType()))
{
deploymentProblems.add(new RuntimeException("Default producer fields are not supported on normal scoped beans. Field: " + f + " Declaring Bean: " + tp));
}
}
if (builder == null)
{
builder = new AnnotatedTypeBuilder<X>().readFromType(tp);
}
Set<Annotation> qualifiers = new HashSet<Annotation>();
for (Annotation a : f.getAnnotations())
{
// remove the qualifiers
if (beanManager.isQualifier(a.annotationType()))
{
qualifiers.add(a);
builder.removeFromField(f, a.annotationType());
}
}
if (qualifiers.isEmpty())
{
qualifiers.add(DefaultLiteral.INSTANCE);
}
Synthetic syntheticQualifier = producerSyntheticProvider.get();
// store the qualifiers for later
Type type = null;
if (f.isAnnotationPresent(DefaultBean.class))
{
type = f.getAnnotation(DefaultBean.class).value();