[weld-commits] Weld SVN: r6799 - in extensions/trunk/impl/src: main/java/org/jboss/weld/extensions/bean/generic and 2 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Sat Jul 24 10:00:00 EDT 2010


Author: pete.muir at jboss.org
Date: 2010-07-24 09:59:59 -0400 (Sat, 24 Jul 2010)
New Revision: 6799

Added:
   extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBean.java
   extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Foo.java
   extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanProducer.java
   extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Message.java
Removed:
   extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/BazProducer.java
   extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Garply.java
   extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Grault.java
Modified:
   extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
   extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/Generic.java
   extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
   extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericConfiguration.java
   extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
   extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Bar.java
   extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Baz.java
   extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java
Log:
make test clearer, remove assert keyword, overloading for AnnotatedTypeBuilder, use @GenericBean qualifier

Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/annotated/AnnotatedTypeBuilder.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -94,6 +94,11 @@
       fields.get(field).add(annotation);
       return this;
    }
+   
+   public AnnotatedTypeBuilder<X> addToField(AnnotatedField<? super X> field, Annotation annotation)
+   {
+      return addToField(field.getJavaMember(), annotation);
+   }
 
    public AnnotatedTypeBuilder<X> removeFromField(Field field, Class<? extends Annotation> annotationType)
    {
@@ -103,6 +108,11 @@
       }
       return this;
    }
+   
+   public AnnotatedTypeBuilder<X> removeFromField(AnnotatedField<? super X> field, Class<? extends Annotation> annotationType)
+   {
+      return removeFromField(field.getJavaMember(), annotationType);
+   }
 
    public AnnotatedTypeBuilder<X> addToMethod(Method method, Annotation annotation)
    {
@@ -113,6 +123,11 @@
       methods.get(method).add(annotation);
       return this;
    }
+   
+   public AnnotatedTypeBuilder<X> addToMethod(AnnotatedMethod<? super X> method, Annotation annotation)
+   {
+      return addToMethod(method.getJavaMember(), annotation);
+   }
 
    public AnnotatedTypeBuilder<X> removeFromMethod(Method method, Class<? extends Annotation> annotationType)
    {
@@ -122,6 +137,11 @@
       }
       return this;
    }
+   
+   public AnnotatedTypeBuilder<X> removeFromMethod(AnnotatedMethod<? super X> method, Class<? extends Annotation> annotationType)
+   {
+      return removeFromMethod(method.getJavaMember(), annotationType);
+   }
 
    public AnnotatedTypeBuilder<X> addToMethodParameter(Method method, int position, Annotation annotation)
    {
@@ -162,8 +182,13 @@
       constructors.get(constructor).add(annotation);
       return this;
    }
+   
+   public AnnotatedTypeBuilder<X> addToConstructor(AnnotatedConstructor<X> constructor, Annotation annotation)
+   {
+      return addToConstructor(constructor.getJavaMember(), annotation);
+   }
 
-   public AnnotatedTypeBuilder<X> removeFromConstructor(Constructor<?> constructor, Class<? extends Annotation> annotationType)
+   public AnnotatedTypeBuilder<X> removeFromConstructor(Constructor<X> constructor, Class<? extends Annotation> annotationType)
    {
       if (constructors.get(constructor) != null)
       {
@@ -171,6 +196,11 @@
       }
       return this;
    }
+   
+   public AnnotatedTypeBuilder<X> removeFromConstructor(AnnotatedConstructor<X> constructor, Class<? extends Annotation> annotationType)
+   {
+      return removeFromConstructor(constructor.getJavaMember(), annotationType);
+   }
 
    public AnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int position, Annotation annotation)
    {
@@ -201,6 +231,45 @@
       }
       return this;
    }
+   
+   
+   public AnnotatedTypeBuilder<X> removeFromParameter(AnnotatedParameter<? super X> parameter, Class<? extends Annotation> annotationType)
+   {
+      if (parameter.getDeclaringCallable().getJavaMember() instanceof Method)
+      {
+         Method method = (Method) parameter.getDeclaringCallable().getJavaMember();
+         return removeFromMethodParameter(method, parameter.getPosition(), annotationType);
+      }
+      if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>)
+      {
+         @SuppressWarnings("unchecked")
+         Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember();
+         return removeFromConstructorParameter(constructor, parameter.getPosition(), annotationType);
+      }
+      else
+      {
+         throw new IllegalArgumentException("Cannot remove from parameter " + parameter + " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember());
+      }
+   }
+   
+   public AnnotatedTypeBuilder<X> addToParameter(AnnotatedParameter<? super X> parameter, Annotation annotation)
+   {
+      if (parameter.getDeclaringCallable().getJavaMember() instanceof Method)
+      {
+         Method method = (Method) parameter.getDeclaringCallable().getJavaMember();
+         return addToMethodParameter(method, parameter.getPosition(), annotation);
+      }
+      if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>)
+      {
+         @SuppressWarnings("unchecked")
+         Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember();
+         return addToConstructorParameter(constructor, parameter.getPosition(), annotation);
+      }
+      else
+      {
+         throw new IllegalArgumentException("Cannot remove from parameter " + parameter + " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember());
+      } 
+   }
 
    public AnnotatedTypeBuilder<X> removeFromAll(Class<? extends Annotation> annotationType)
    {
@@ -436,24 +505,50 @@
    {
       fieldTypes.put(field, type);
    }
+   
+   public void overrideFieldType(AnnotatedField<? super X> field, Type type)
+   {
+      fieldTypes.put(field.getJavaMember(), type);
+   }
 
-   public void overrideMethodParameterType(Method method, Type type, int position)
+   public AnnotatedTypeBuilder<X> overrideMethodParameterType(Method method, int position, Type type)
    {
       if (methodParameterTypes.get(method) == null)
       {
          methodParameterTypes.put(method, new HashMap<Integer, Type>());
       }
       methodParameterTypes.get(method).put(position, type);
+      return this;
    }
 
-   public void overrideConstructorParameterType(Constructor<?> constructor, Type type, int position)
+   public AnnotatedTypeBuilder<X> overrideConstructorParameterType(Constructor<X> constructor, int position, Type type)
    {
       if (constructorParameterTypes.get(constructor) == null)
       {
          constructorParameterTypes.put(constructor, new HashMap<Integer, Type>());
       }
       constructorParameterTypes.get(constructor).put(position, type);
+      return this;
    }
+   
+   public AnnotatedTypeBuilder<X> overrideParameterType(AnnotatedParameter<? super X> parameter, Type type)
+   {
+      if (parameter.getDeclaringCallable().getJavaMember() instanceof Method)
+      {
+         Method method = (Method) parameter.getDeclaringCallable().getJavaMember();
+         return overrideMethodParameterType(method, parameter.getPosition(), type); 
+      }
+      if (parameter.getDeclaringCallable().getJavaMember() instanceof Constructor<?>)
+      {
+         @SuppressWarnings("unchecked")
+         Constructor<X> constructor = (Constructor<X>) parameter.getDeclaringCallable().getJavaMember();
+         return overrideConstructorParameterType(constructor, parameter.getPosition(), type);
+      }
+      else
+      {
+         throw new IllegalArgumentException("Cannot remove from parameter " + parameter + " - cannot operate on member " + parameter.getDeclaringCallable().getJavaMember());
+      }
+   }
 
    public Class<X> getJavaClass()
    {

Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/Generic.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/Generic.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/Generic.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -19,6 +19,7 @@
 import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
@@ -31,6 +32,7 @@
  */
 @Retention( RUNTIME )
 @Target( TYPE )
+ at Documented
 public @interface Generic
 {
    Class<?> value();

Added: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBean.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBean.java	                        (rev 0)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBean.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.weld.extensions.bean.generic;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * 
+ * Qualifier used to identify generic bean injection points. Generic bean
+ * injections can only occur in other generic beans which share the same config
+ * annotation.
+ * 
+ * 
+ * @author stuart
+ * @author Pete Muir
+ * 
+ */
+ at Retention(RUNTIME)
+ at Target( { METHOD, FIELD, PARAMETER, TYPE })
+ at Qualifier
+ at Documented
+public @interface GenericBean
+{
+
+}


Property changes on: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericBeanExtension.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -16,9 +16,6 @@
  */
 package org.jboss.weld.extensions.bean.generic;
 
-import static org.jboss.weld.extensions.util.Reflections.EMPTY_ANNOTATION_ARRAY;
-import static org.jboss.weld.extensions.util.Reflections.getQualifiers;
-
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Member;
 import java.lang.reflect.Type;
@@ -86,6 +83,7 @@
    void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event)
    {
       event.addQualifier(Synthetic.class);
+      event.addQualifier(GenericBean.class);
    }
 
    void processAnnotatedType(@Observes ProcessAnnotatedType<?> event)
@@ -201,7 +199,10 @@
       Synthetic genericBeanQualifier = syntheticProvider.get(concrete);
 
       AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(annotatedType);
+
+      // Add in the synthetic qualifier to the bean
       builder.addToClass(genericBeanQualifier);
+
       for (AnnotatedField<? super X> field : annotatedType.getFields())
       {
          if (field.isAnnotationPresent(Inject.class))
@@ -210,56 +211,27 @@
             if (concrete.annotationType().isAssignableFrom(field.getJavaMember().getType()))
             {
                Synthetic genericConfigurationQualifier = syntheticProvider.get();
-               builder.addToField(field.getJavaMember(), genericConfigurationQualifier);
+               builder.addToField(field, genericConfigurationQualifier);
                event.addBean(createConfigurationBean(beanManager, concrete, genericConfigurationQualifier));
             }
-            else
+            // if this is a generic bean injection point
+            else if (field.isAnnotationPresent(Inject.class) && field.isAnnotationPresent(GenericBean.class))
             {
-               /*
-                * check to see if we should be injecting a generic bean we do
-                * this by checking if there are any beans that can be injected
-                * into this point if there is not then we assume it is a generic
-                * injection point this has the downside that if it is actually a
-                * deployment error then it will confuse the user
-                */
-               // TODO Improve this
-               Annotation[] qualifiers = getQualifiers(field.getAnnotations(), beanManager).toArray(EMPTY_ANNOTATION_ARRAY);
-               Set<Bean<?>> beans = beanManager.getBeans(field.getJavaMember().getType(), qualifiers);
-               if (beans.isEmpty())
-               {
-                  builder.addToField(field.getJavaMember(), genericBeanQualifier);
-               }
+               builder.removeFromField(field, GenericBean.class);
+               builder.addToField(field, genericBeanQualifier);
             }
          }
-         else if (field.isAnnotationPresent(Produces.class))
-         {
-            // TODO: register a producer with the appropriate qualifier
-         }
       }
-      for (AnnotatedMethod<?> method : annotatedType.getMethods())
+      for (AnnotatedMethod<? super X> method : annotatedType.getMethods())
       {
-         // TODO: need to properly handle Observer methods and Disposal
-         // methods
-         if (method.isAnnotationPresent(Produces.class))
+         if (method.isAnnotationPresent(Inject.class))
          {
-            // TODO: we need to register the producer bean, so this is not
-            // very useful at the moment
-            for (AnnotatedParameter<?> pm : method.getParameters())
+            for (AnnotatedParameter<? super X> parameter : method.getParameters())
             {
-               Class<?> paramType = method.getJavaMember().getParameterTypes()[pm.getPosition()];
-
-               // check to see if we should be injecting a generic bean
-               // we do this by checking if there are any beans that can be
-               // injected into this point
-               // if there is not then we assume it is a generic injection
-               // point
-               // this has the downside that if it is actually a deployment
-               // error then it will confuse the user
-               Annotation[] qualifiers = getQualifiers(pm.getAnnotations(), beanManager).toArray(EMPTY_ANNOTATION_ARRAY);
-               Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
-               if (beans.isEmpty())
+               if (parameter.isAnnotationPresent(GenericBean.class))
                {
-                  builder.addToMethod(method.getJavaMember(), genericBeanQualifier);
+                  builder.removeFromParameter(parameter, GenericBean.class);
+                  builder.addToParameter(parameter, genericBeanQualifier);
                }
             }
          }
@@ -271,12 +243,10 @@
          {
             for (AnnotatedParameter<X> parameter : constructor.getParameters())
             {
-               Class<?> paramType = constructor.getJavaMember().getParameterTypes()[parameter.getPosition()];
-               Annotation[] qualifiers = getQualifiers(parameter.getAnnotations(), beanManager).toArray(EMPTY_ANNOTATION_ARRAY);
-               Set<Bean<?>> beans = beanManager.getBeans(paramType, qualifiers);
-               if (beans.isEmpty())
+               if (parameter.isAnnotationPresent(GenericBean.class))
                {
-                  builder.addToConstructorParameter(constructor.getJavaMember(), parameter.getPosition(), genericBeanQualifier);
+                  builder.removeFromParameter(parameter, GenericBean.class);
+                  builder.addToParameter(parameter, genericBeanQualifier);
                }
             }
          }

Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericConfiguration.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericConfiguration.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/GenericConfiguration.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -16,6 +16,7 @@
  */
 package org.jboss.weld.extensions.bean.generic;
 
+import java.lang.annotation.Documented;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -30,6 +31,7 @@
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target( { ElementType.TYPE })
+ at Documented
 public @interface GenericConfiguration
 {
 

Modified: extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
--- extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -111,7 +111,7 @@
          if (f.isAnnotationPresent(Exact.class))
          {
             Class<?> type = f.getAnnotation(Exact.class).value();
-            builder.overrideFieldType(f.getJavaMember(), type);
+            builder.overrideFieldType(f, type);
          }
       }
       // method parameters
@@ -122,7 +122,7 @@
             if (p.isAnnotationPresent(Exact.class))
             {
                Class<?> type = p.getAnnotation(Exact.class).value();
-               builder.overrideMethodParameterType(m.getJavaMember(), type, p.getPosition());
+               builder.overrideParameterType(p, type);
             }
          }
       }
@@ -134,7 +134,7 @@
             if (p.isAnnotationPresent(Exact.class))
             {
                Class<?> type = p.getAnnotation(Exact.class).value();
-               builder.overrideConstructorParameterType(c.getJavaMember(), type, p.getPosition());
+               builder.overrideParameterType(p, type);
             }
          }
       }
@@ -151,10 +151,10 @@
             // remove bean constructors annotated @Inject
             for (AnnotatedConstructor<X> constructor2 : pat.getAnnotatedType().getConstructors())
             {
-               annotatedTypeBuilder.removeFromConstructor(constructor2.getJavaMember(), Inject.class);
+               annotatedTypeBuilder.removeFromConstructor(constructor2, Inject.class);
             }
             // make the constructor annotated @Constructs the bean constructor
-            annotatedTypeBuilder.addToConstructor(constructor.getJavaMember(), InjectLiteral.INSTANCE);
+            annotatedTypeBuilder.addToConstructor(constructor, InjectLiteral.INSTANCE);
             // add all the annotations of this constructor to the class
             for (Annotation ann : constructor.getAnnotations())
             {

Modified: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Bar.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Bar.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Bar.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -21,28 +21,28 @@
 import org.jboss.weld.extensions.bean.generic.Generic;
 
 /**
- * A generic bean
+ * A generic bean for the config annotation Message
  * 
  * @author pmuir
  *
  */
 
- at Generic(Garply.class)
+ at Generic(Message.class)
 public class Bar
 {
    @Inject
-   private Garply injectedGarply;
+   private Message injectedMessage;
 
-   // A Garply with no @Inject
-   private Garply garply;
+   // A Message with no @Inject
+   private Message message;
 
-   public Garply getInjectedGarply()
+   public Message getInjectedMessage()
    {
-      return injectedGarply;
+      return injectedMessage;
    }
 
-   public Garply getGarply()
+   public Message getMessage()
    {
-      return garply;
+      return message;
    }
 }

Modified: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Baz.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Baz.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Baz.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -19,26 +19,27 @@
 import javax.inject.Inject;
 
 import org.jboss.weld.extensions.bean.generic.Generic;
+import org.jboss.weld.extensions.bean.generic.GenericBean;
 
 /**
+ * A generic bean for the config annotation Garply
  * 
- * 
  * @author pmuir
  *
  */
 
- at Generic(Garply.class)
+ at Generic(Message.class)
 public class Baz
 {
 
-   @Inject
+   @Inject @GenericBean
    private Bar bar;
 
    @Inject
    private Corge corge;
    
    @Inject 
-   private Garply garply;
+   private Message message;
 
    public Bar getBar()
    {
@@ -50,8 +51,8 @@
       return corge;
    }
    
-   public Garply getGarply()
+   public Message getMessage()
    {
-      return garply;
+      return message;
    }
 }

Deleted: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/BazProducer.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/BazProducer.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/BazProducer.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.test.bean.generic;
-
-import javax.enterprise.inject.Produces;
-
-/**
- * A producer of Baz's
- * @author pmuir
- *
- */
-public class BazProducer
-{
-   @SuppressWarnings("unused")
-   @Grault(1)
-   @Produces
-   @Garply("hello1")
-   private Baz baz1;
-
-   @SuppressWarnings("unused")
-   @Grault(2)
-   @Produces
-   @Garply("hello2")
-   private Baz baz2;
-
-}

Copied: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Foo.java (from rev 6781, extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Grault.java)
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Foo.java	                        (rev 0)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Foo.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.test.bean.generic;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * A qualifier
+ * 
+ * @author pmuir
+ *
+ */
+
+ at Retention(RUNTIME)
+ at Target({METHOD, FIELD, PARAMETER, TYPE})
+ at Qualifier
+public @interface Foo
+{
+   int value();
+}

Deleted: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Garply.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Garply.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Garply.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.test.bean.generic;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import org.jboss.weld.extensions.bean.generic.GenericConfiguration;
-
-/**
- * The annotation used to configure a generic bean
- * 
- * @author pmuir
- *
- */
-
- at Retention(RUNTIME)
- at Target({METHOD, FIELD, PARAMETER, TYPE})
- at GenericConfiguration
-public @interface Garply
-{
-   String value();
-}

Copied: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanProducer.java (from rev 6781, extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/BazProducer.java)
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanProducer.java	                        (rev 0)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanProducer.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.test.bean.generic;
+
+import javax.enterprise.inject.Produces;
+
+/**
+ * A producer of generic beans
+ * @author pmuir
+ *
+ */
+public class GenericBeanProducer
+{
+   @SuppressWarnings("unused")
+   @Foo(1)
+   @Produces
+   @Message("hello1")
+   private Baz baz1;
+
+   @SuppressWarnings("unused")
+   @Foo(2)
+   @Produces
+   @Message("hello2")
+   private Baz baz2;
+   
+   @Foo(1)
+   @Produces
+   @Message("bye1")
+   private Bar bar1;
+   
+   @Foo(2)
+   @Produces
+   @Message("bye2")
+   private Bar bar2;
+
+}

Modified: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/GenericBeanTest.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -16,6 +16,10 @@
  */
 package org.jboss.weld.extensions.test.bean.generic;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
 import javax.inject.Inject;
 
 import org.jboss.arquillian.api.Deployment;
@@ -36,32 +40,51 @@
    }
 
    @Inject
-   @Grault(1)
+   @Foo(1)
    private Baz baz1;
 
    @Inject
-   @Grault(2)
+   @Foo(2)
    private Baz baz2;
+   
+   @Inject
+   @Foo(1)
+   private Bar bar1;
+   
+   @Inject
+   @Foo(2)
+   private Bar bar2;
 
    @Test
    public void testGeneric()
    {
-      // Test that the generic configuration injection wiring is working!
-      assert baz1.getGarply() != null;
-      assert baz1.getGarply().value().equals("hello1");
-      assert baz2.getGarply() != null;
-      assert baz2.getGarply().value().equals("hello2");
-      assert baz1.getBar() != null;
-      assert baz1.getBar().getInjectedGarply() != null;
-      assert baz1.getBar().getInjectedGarply().value().equals("hello1");
-      assert baz2.getBar() != null;
-      assert baz2.getBar().getInjectedGarply() != null;
-      assert baz2.getBar().getInjectedGarply().value().equals("hello2");
+      // Check that normal bean injection is working correctly!
+      assertNotNull(baz2.getCorge());
+      assertEquals(baz2.getCorge().getName(), "fred");
+      
+      // Test that the generic configuration injection wiring is working for bar
+      assertNotNull(bar1.getInjectedMessage());
+      assertEquals(bar1.getInjectedMessage().value(), "bye1");
+      assertNotNull(bar2.getInjectedMessage());
+      assertEquals(bar2.getInjectedMessage().value(), "bye2");
+      
+      // Check that the generic configuration injection wiring is working for baz
+      assertNotNull(baz1.getMessage());
+      assertEquals(baz1.getMessage().value(), "hello1");
+      assertNotNull(baz2.getMessage());
+      assertEquals(baz2.getMessage().value(), "hello2");
+      
+      // Check that generic beans can inject each other
+      assertNotNull(baz1.getBar());
+      assertNotNull(baz1.getBar().getInjectedMessage());
+      assertEquals(baz1.getBar().getInjectedMessage().value(), "hello1");
+      assertNotNull(baz2.getBar());
+      assertNotNull(baz2.getBar().getInjectedMessage());
+      assertEquals(baz2.getBar().getInjectedMessage().value(), "hello2");
+      
       // Check that this isn't affecting annotations on the generic bean without @Inject 
-      assert baz1.getBar().getGarply() == null;
-      assert baz2.getBar().getGarply() == null;
-      // Check that normal bean injection is working correctly!
-      assert baz2.getCorge() != null;
-      assert baz2.getCorge().getName() == "fred";
+      assertNull(baz1.getBar().getMessage());
+      assertNull(baz2.getBar().getMessage());
+     
    }
 }

Deleted: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Grault.java
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Grault.java	2010-07-24 13:23:55 UTC (rev 6798)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Grault.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.test.bean.generic;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * A qualifier
- * 
- * @author pmuir
- *
- */
-
- at Retention(RUNTIME)
- at Target({METHOD, FIELD, PARAMETER, TYPE})
- at Qualifier
-public @interface Grault
-{
-   int value();
-}

Copied: extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Message.java (from rev 6785, extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Garply.java)
===================================================================
--- extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Message.java	                        (rev 0)
+++ extensions/trunk/impl/src/test/java/org/jboss/weld/extensions/test/bean/generic/Message.java	2010-07-24 13:59:59 UTC (rev 6799)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.test.bean.generic;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.jboss.weld.extensions.bean.generic.GenericConfiguration;
+
+/**
+ * The annotation used to configure a generic bean
+ * 
+ * @author pmuir
+ *
+ */
+
+ at Retention(RUNTIME)
+ at Target({METHOD, FIELD, PARAMETER, TYPE})
+ at GenericConfiguration
+public @interface Message
+{
+   String value();
+}



More information about the weld-commits mailing list