use of javax.enterprise.inject.New in project core by weld.
the class BeanDeployerEnvironment method addNewBeansFromInjectionPoints.
public void addNewBeansFromInjectionPoints(Set<? extends InjectionPoint> injectionPoints) {
for (InjectionPoint injectionPoint : injectionPoints) {
WeldInjectionPointAttributes<?, ?> weldInjectionPoint = InjectionPoints.getWeldInjectionPoint(injectionPoint);
if (weldInjectionPoint.getQualifier(New.class) != null) {
Class<?> rawType = Reflections.getRawType(weldInjectionPoint.getType());
if (Event.class.equals(rawType)) {
continue;
}
New _new = weldInjectionPoint.getQualifier(New.class);
if (_new.value().equals(New.class)) {
if (rawType.equals(Instance.class)) {
// e.g. @Inject @New(ChequePaymentProcessor.class) Instance<PaymentProcessor> chequePaymentProcessor;
// see WELD-975
Type typeParameter = Reflections.getActualTypeArguments(weldInjectionPoint.getType())[0];
addNewBeanFromInjectionPoint(typeParameter);
} else {
addNewBeanFromInjectionPoint(weldInjectionPoint.getType());
}
} else {
addNewBeanFromInjectionPoint(_new.value());
}
}
}
}
use of javax.enterprise.inject.New in project core by weld.
the class ResolvableBuilder method addQualifier.
private ResolvableBuilder addQualifier(Annotation qualifier, InjectionPoint injectionPoint) {
QualifierInstance qualifierInstance = QualifierInstance.of(qualifier, store);
final Class<? extends Annotation> annotationType = qualifierInstance.getAnnotationClass();
// Handle the @New qualifier special case
if (annotationType.equals(New.class)) {
New newQualifier = New.class.cast(qualifier);
if (newQualifier.value().equals(New.class) && rawType == null) {
throw new IllegalStateException("Cannot transform @New when there is no known raw type");
} else if (newQualifier.value().equals(New.class)) {
qualifier = new NewLiteral(rawType);
qualifierInstance = QualifierInstance.of(qualifier, store);
}
} else if (injectionPoint != null && annotationType.equals(Named.class)) {
Named named = (Named) qualifier;
if (named.value().equals("")) {
// WELD-1739
// This is an injection point with an @Named qualifier, with no value specified, we need to assume the name of the field or parameter is the
// value
Member member = injectionPoint.getMember();
if (member instanceof Executable) {
// Method or constructor injection
Executable executable = (Executable) member;
AnnotatedParameter<?> annotatedParameter = (AnnotatedParameter<?>) injectionPoint.getAnnotated();
Parameter parameter = executable.getParameters()[annotatedParameter.getPosition()];
named = new NamedLiteral(parameter.getName());
} else {
named = new NamedLiteral(injectionPoint.getMember().getName());
}
qualifier = named;
qualifierInstance = QualifierInstance.of(named, store);
}
}
checkQualifier(qualifier, qualifierInstance, annotationType);
this.qualifierInstances.add(qualifierInstance);
return this;
}
Aggregations