Search in sources :

Example 1 with TypeStore

use of org.jboss.weld.metadata.TypeStore in project core by weld.

the class BeforeBeanDiscoveryImpl method addStereotype.

@Override
public void addStereotype(Class<? extends Annotation> stereotype, Annotation... stereotypeDef) {
    checkWithinObserverNotification();
    TypeStore typeStore = getTypeStore();
    typeStore.add(stereotype, StereotypeLiteral.INSTANCE);
    for (Annotation a : stereotypeDef) {
        typeStore.add(stereotype, a);
    }
    getBeanManager().getServices().get(ClassTransformer.class).clearAnnotationData(stereotype);
    getBeanManager().getServices().get(MetaAnnotationStore.class).clearAnnotationData(stereotype);
    BootstrapLogger.LOG.addStereoTypeCalled(getReceiver(), stereotype);
}
Also used : TypeStore(org.jboss.weld.metadata.TypeStore) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) ClassTransformer(org.jboss.weld.resources.ClassTransformer) Annotation(java.lang.annotation.Annotation)

Example 2 with TypeStore

use of org.jboss.weld.metadata.TypeStore in project core by weld.

the class AnnotatedTypesTest method testComparison.

/**
 * tests the AnnotatedTypes.compareAnnotatedTypes
 */
@Test
public void testComparison() throws SecurityException, NoSuchFieldException, NoSuchMethodException {
    // check that two weld classes on the same underlying are equal
    TypeStore ts = new TypeStore();
    ClassTransformer ct = new ClassTransformer(ts, new SharedObjectCache(), ReflectionCacheFactory.newInstance(ts), RegistrySingletonProvider.STATIC_INSTANCE);
    EnhancedAnnotatedType<Chair> chair1 = EnhancedAnnotatedTypeImpl.of(BackedAnnotatedType.of(Chair.class, ct.getSharedObjectCache(), ct.getReflectionCache(), RegistrySingletonProvider.STATIC_INSTANCE, AnnotatedTypeIdentifier.NULL_BDA_ID), ct);
    EnhancedAnnotatedType<Chair> chair2 = EnhancedAnnotatedTypeImpl.of(BackedAnnotatedType.of(Chair.class, ct.getSharedObjectCache(), ct.getReflectionCache(), RegistrySingletonProvider.STATIC_INSTANCE, AnnotatedTypeIdentifier.NULL_BDA_ID), ct);
    Assert.assertTrue(AnnotatedTypes.compareAnnotatedTypes(chair1, chair2));
    // check that a different implementation of annotated type is equal to the weld implementation
    TestAnnotatedTypeBuilder<Chair> builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToClass(new DefaultLiteral());
    builder.addToField(Chair.class.getField("legs"), new ProducesLiteral());
    builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
    AnnotatedType<Chair> chair3 = builder.create();
    Assert.assertTrue(AnnotatedTypes.compareAnnotatedTypes(chair1, chair3));
    // check that the implementation returns false if a field annotation changes
    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToClass(new DefaultLiteral());
    builder.addToField(Chair.class.getField("legs"), new DefaultLiteral());
    builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
    chair3 = builder.create();
    Assert.assertFalse(AnnotatedTypes.compareAnnotatedTypes(chair1, chair3));
    // check that the implementation returns false if a class level annotation changes
    builder = new TestAnnotatedTypeBuilder<Chair>(Chair.class);
    builder.addToClass(new ProducesLiteral());
    builder.addToField(Chair.class.getField("legs"), new DefaultLiteral());
    builder.addToMethod(Chair.class.getMethod("sit"), new ProducesLiteral());
    chair3 = builder.create();
    Assert.assertFalse(AnnotatedTypes.compareAnnotatedTypes(chair1, chair3));
}
Also used : SharedObjectCache(org.jboss.weld.resources.SharedObjectCache) TypeStore(org.jboss.weld.metadata.TypeStore) ClassTransformer(org.jboss.weld.resources.ClassTransformer) TestAnnotatedTypeBuilder(org.jboss.weld.test.util.annotated.TestAnnotatedTypeBuilder) Test(org.testng.annotations.Test)

Example 3 with TypeStore

use of org.jboss.weld.metadata.TypeStore in project core by weld.

the class BeforeBeanDiscoveryImpl method addInterceptorBinding.

@Override
public void addInterceptorBinding(Class<? extends Annotation> bindingType, Annotation... bindingTypeDef) {
    checkWithinObserverNotification();
    TypeStore typeStore = getTypeStore();
    typeStore.add(bindingType, InterceptorBindingTypeLiteral.INSTANCE);
    for (Annotation a : bindingTypeDef) {
        typeStore.add(bindingType, a);
    }
    getBeanManager().getServices().get(ClassTransformer.class).clearAnnotationData(bindingType);
    getBeanManager().getServices().get(MetaAnnotationStore.class).clearAnnotationData(bindingType);
    BootstrapLogger.LOG.addInterceptorBindingCalled(getReceiver(), bindingType);
}
Also used : TypeStore(org.jboss.weld.metadata.TypeStore) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) ClassTransformer(org.jboss.weld.resources.ClassTransformer) Annotation(java.lang.annotation.Annotation)

Example 4 with TypeStore

use of org.jboss.weld.metadata.TypeStore in project core by weld.

the class SimpleWeldClassTest method testWeldClassForCovariantReturnType.

/*
    * description = "WELD-568"
    */
@Category(Broken.class)
@Test
public void testWeldClassForCovariantReturnType() {
    TypeStore typeStore = new TypeStore();
    EnhancedAnnotatedType<Attacker> weldClass = new ClassTransformer(typeStore, new SharedObjectCache(), ReflectionCacheFactory.newInstance(typeStore), RegistrySingletonProvider.STATIC_INSTANCE).getEnhancedAnnotatedType(Attacker.class, AnnotatedTypeIdentifier.NULL_BDA_ID);
    Collection<EnhancedAnnotatedMethod<?, ? super Attacker>> methods = weldClass.getEnhancedMethods();
    Assert.assertEquals(4, methods.size());
    List<EnhancedAnnotatedMethod<?, ?>> interceptableMethods = Beans.getInterceptableMethods(weldClass);
    Assert.assertEquals(4, interceptableMethods.size());
}
Also used : SharedObjectCache(org.jboss.weld.resources.SharedObjectCache) TypeStore(org.jboss.weld.metadata.TypeStore) ClassTransformer(org.jboss.weld.resources.ClassTransformer) EnhancedAnnotatedMethod(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedMethod) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 5 with TypeStore

use of org.jboss.weld.metadata.TypeStore in project core by weld.

the class SimpleWeldClassTest method testWeldClassForGenericSuperclass.

/*
    * description = "WELD-568"
    */
@Test
public void testWeldClassForGenericSuperclass() {
    TypeStore ts = new TypeStore();
    EnhancedAnnotatedType<StringProcessor> weldClass = new ClassTransformer(ts, new SharedObjectCache(), ReflectionCacheFactory.newInstance(ts), RegistrySingletonProvider.STATIC_INSTANCE).getEnhancedAnnotatedType(StringProcessor.class, AnnotatedTypeIdentifier.NULL_BDA_ID);
    Collection<EnhancedAnnotatedMethod<?, ? super StringProcessor>> methods = weldClass.getEnhancedMethods();
    // assert methods.size() == 2;
    List<EnhancedAnnotatedMethod<?, ?>> interceptableMethods = Beans.getInterceptableMethods(weldClass);
    Assert.assertEquals(3, interceptableMethods.size());
}
Also used : SharedObjectCache(org.jboss.weld.resources.SharedObjectCache) TypeStore(org.jboss.weld.metadata.TypeStore) ClassTransformer(org.jboss.weld.resources.ClassTransformer) EnhancedAnnotatedMethod(org.jboss.weld.annotated.enhanced.EnhancedAnnotatedMethod) Test(org.junit.Test)

Aggregations

TypeStore (org.jboss.weld.metadata.TypeStore)9 ClassTransformer (org.jboss.weld.resources.ClassTransformer)9 SharedObjectCache (org.jboss.weld.resources.SharedObjectCache)7 Annotation (java.lang.annotation.Annotation)3 MetaAnnotationStore (org.jboss.weld.metadata.cache.MetaAnnotationStore)3 Test (org.junit.Test)3 EnhancedAnnotatedMethod (org.jboss.weld.annotated.enhanced.EnhancedAnnotatedMethod)2 ReflectionCache (org.jboss.weld.resources.ReflectionCache)2 SlimAnnotatedTypeStore (org.jboss.weld.annotated.slim.SlimAnnotatedTypeStore)1 SpecializationAndEnablementRegistry (org.jboss.weld.bootstrap.SpecializationAndEnablementRegistry)1 SimpleServiceRegistry (org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry)1 WeldConfiguration (org.jboss.weld.config.WeldConfiguration)1 GlobalObserverNotifierService (org.jboss.weld.event.GlobalObserverNotifierService)1 ResourceInjectionFactory (org.jboss.weld.injection.ResourceInjectionFactory)1 InjectionTargetService (org.jboss.weld.injection.producer.InjectionTargetService)1 InterceptorsApiAbstraction (org.jboss.weld.interceptor.builder.InterceptorsApiAbstraction)1 InterceptorBindingModel (org.jboss.weld.metadata.cache.InterceptorBindingModel)1 BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)1 ContextualStoreImpl (org.jboss.weld.serialization.ContextualStoreImpl)1 TestAnnotatedTypeBuilder (org.jboss.weld.test.util.annotated.TestAnnotatedTypeBuilder)1