Search in sources :

Example 1 with NamedLiteral

use of org.jboss.weld.literal.NamedLiteral in project core by weld.

the class CreateBeanAttributesTest method testBeanAttributesForManagedBeanWithModifiedAnnotatedType.

@Test
public void testBeanAttributesForManagedBeanWithModifiedAnnotatedType() {
    AnnotatedType<Mountain> type = manager.createAnnotatedType(Mountain.class);
    AnnotatedType<Mountain> wrappedType = new WrappedAnnotatedType<Mountain>(type, new NamedLiteral("Mount Blanc"));
    BeanAttributes<Mountain> attributes = manager.createBeanAttributes(wrappedType);
    verifyTypes(attributes, Mountain.class, Landmark.class, Object.class);
    assertTrue(attributes.getStereotypes().isEmpty());
    verifyQualifierTypes(attributes, Named.class, Any.class, Default.class);
    assertEquals(Dependent.class, attributes.getScope());
    assertEquals("Mount Blanc", attributes.getName());
    assertFalse(attributes.isAlternative());
}
Also used : NamedLiteral(org.jboss.weld.literal.NamedLiteral) Test(org.junit.Test)

Example 2 with NamedLiteral

use of org.jboss.weld.literal.NamedLiteral in project core by weld.

the class DummyExtension method replaceObserverMethod.

void replaceObserverMethod(@Observes ProcessObserverMethod<Number, ?> event) {
    if (!checkExperimentalObserver(event.getObserverMethod().getObservedQualifiers())) {
        return;
    }
    // first, verify getBeanClass() check
    ObserverMethod<Number> wrongObserver = new ForwardingObserverMethod<Number>(event.getObserverMethod()) {

        @Override
        public Class<?> getBeanClass() {
            return Number.class;
        }
    };
    try {
        event.setObserverMethod(wrongObserver);
        throw new RuntimeException("Expected exception not thrown");
    } catch (DefinitionException expected) {
    }
    ObserverMethod<Number> replacement = new ForwardingObserverMethod<Number>(event.getObserverMethod()) {

        @Override
        public Type getObservedType() {
            return Integer.class;
        }

        @Override
        public Set<Annotation> getObservedQualifiers() {
            Set<Annotation> qualifiers = new HashSet<>(delegate().getObservedQualifiers());
            qualifiers.add(new NamedLiteral("experimental"));
            return qualifiers;
        }
    };
    event.setObserverMethod(replacement);
}
Also used : DefinitionException(javax.enterprise.inject.spi.DefinitionException) NamedLiteral(org.jboss.weld.literal.NamedLiteral) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Example 3 with NamedLiteral

use of org.jboss.weld.literal.NamedLiteral in project core by weld.

the class ExperimentalProcessObserverMethodTest method testReplacingObserverMethod.

@Test
public void testReplacingObserverMethod() {
    @SuppressWarnings("serial") final Number number = new Number() {

        @Override
        public long longValue() {
            return 0L;
        }

        @Override
        public int intValue() {
            return 0;
        }

        @Override
        public float floatValue() {
            return 0F;
        }

        @Override
        public double doubleValue() {
            return 0D;
        }
    };
    Assert.assertEquals(0, manager.resolveObserverMethods(number, Experimental.Literal.INSTANCE).size());
    Assert.assertEquals(0, manager.resolveObserverMethods(number, Experimental.Literal.INSTANCE, new NamedLiteral("experimental")).size());
    Assert.assertEquals(0, manager.resolveObserverMethods(0, Experimental.Literal.INSTANCE).size());
    Assert.assertEquals(1, manager.resolveObserverMethods(0, Experimental.Literal.INSTANCE, new NamedLiteral("experimental")).size());
}
Also used : NamedLiteral(org.jboss.weld.literal.NamedLiteral) Test(org.junit.Test)

Example 4 with NamedLiteral

use of org.jboss.weld.literal.NamedLiteral in project core by weld.

the class SpecializationTest method validateCharlie.

private void validateCharlie(BeanAttributes<?> attributes) {
    verifyQualifiers(attributes, Foo.Literal.INSTANCE, Bar.Literal.INSTANCE, Baz.Literal.INSTANCE, Any.Literal.INSTANCE, new NamedLiteral("alpha"));
    assertEquals("alpha", attributes.getName());
}
Also used : NamedLiteral(org.jboss.weld.literal.NamedLiteral)

Example 5 with NamedLiteral

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);
}
Also used : ForwardingAnnotatedType(org.jboss.weld.util.annotated.ForwardingAnnotatedType) NamedLiteral(org.jboss.weld.literal.NamedLiteral) Annotation(java.lang.annotation.Annotation)

Aggregations

NamedLiteral (org.jboss.weld.literal.NamedLiteral)9 Named (javax.inject.Named)3 Test (org.junit.Test)3 Annotation (java.lang.annotation.Annotation)2 List (java.util.List)2 Set (java.util.Set)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Observes (javax.enterprise.event.Observes)2 AfterBeanDiscovery (javax.enterprise.inject.spi.AfterBeanDiscovery)2 Bean (javax.enterprise.inject.spi.Bean)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 AnyLiteral (org.jboss.weld.literal.AnyLiteral)2 CommonBean (org.wildfly.swarm.spi.api.cdi.CommonBean)2 CommonBeanBuilder (org.wildfly.swarm.spi.api.cdi.CommonBeanBuilder)2 ConfigKey (org.wildfly.swarm.spi.api.config.ConfigKey)2 ConfigView (org.wildfly.swarm.spi.api.config.ConfigView)2 SimpleKey (org.wildfly.swarm.spi.api.config.SimpleKey)2 Executable (java.lang.reflect.Executable)1 Member (java.lang.reflect.Member)1 Parameter (java.lang.reflect.Parameter)1