use of org.jboss.weld.literal.NamedLiteral in project core by weld.
the class ModifyingExtension method registerAdditionalFooAnnotatedType.
public void registerAdditionalFooAnnotatedType(@Observes BeforeBeanDiscovery event, BeanManager manager) {
final AnnotatedType<Foo> anotherFoo = manager.createAnnotatedType(Foo.class);
AnnotatedType<Foo> modifiedAnotherFoo = new ForwardingAnnotatedType<Foo>() {
private final NamedLiteral qualifierInstance = new NamedLiteral("anotherFoo");
@Override
public AnnotatedType<Foo> delegate() {
return anotherFoo;
}
@Override
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
if (Named.class.equals(annotationType)) {
return cast(qualifierInstance);
}
return null;
}
@Override
public Set<Annotation> getAnnotations() {
return Collections.<Annotation>singleton(qualifierInstance);
}
@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
return Named.class.equals(annotationType);
}
};
event.addAnnotatedType(modifiedAnotherFoo);
}
use of org.jboss.weld.literal.NamedLiteral 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;
}
use of org.jboss.weld.literal.NamedLiteral in project core by weld.
the class VetoTest method testSpecializedBeanAvailableAfterSpecializingBeanVetoed.
@Test
public void testSpecializedBeanAvailableAfterSpecializingBeanVetoed(BeanManager manager, @Any Alpha alpha, VerifyingExtension extension) {
Bean<?> bean = manager.resolve(manager.getBeans(Alpha.class, Any.Literal.INSTANCE));
assertNotNull(bean);
assertEquals(Bravo.class, bean.getBeanClass());
assertEquals("alpha", bean.getName());
verifyQualifiers(bean, Foo.Literal.INSTANCE, Bar.Literal.INSTANCE, new NamedLiteral("alpha"), Any.Literal.INSTANCE);
assertNotNull(alpha);
assertTrue(alpha instanceof Bravo);
assertFalse(alpha instanceof Charlie);
assertNull(extension.getAlpha());
assertNotNull(extension.getBravo());
assertNotNull(extension.getCharlie());
}
use of org.jboss.weld.literal.NamedLiteral in project wildfly-swarm by wildfly-swarm.
the class SocketBindingGroupExtension method afterBeanDiscovery.
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
List<SimpleKey> configuredGroups = this.configView.simpleSubkeys(ROOT);
for (SimpleKey groupName : configuredGroups) {
Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
AtomicBoolean producerRequired = new AtomicBoolean(false);
if (groups.stream().noneMatch(e -> e.getQualifiers().stream().anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(groupName)))) {
SocketBindingGroup group = new SocketBindingGroup(groupName.name(), null, "0");
applyConfiguration(group);
if (producerRequired.get()) {
CommonBean<SocketBindingGroup> interfaceBean = CommonBeanBuilder.newBuilder(SocketBindingGroup.class).beanClass(SocketBindingGroupExtension.class).scope(ApplicationScoped.class).addQualifier(AnyLiteral.INSTANCE).addQualifier(new NamedLiteral(group.name())).createSupplier(() -> group).addType(SocketBindingGroup.class).addType(Object.class).build();
abd.addBean(interfaceBean);
}
}
}
}
Aggregations