[webbeans-commits] Webbeans SVN: r266 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/introspector/impl and 5 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Nov 6 11:51:22 EST 2008


Author: pete.muir at jboss.org
Date: 2008-11-06 11:51:22 -0500 (Thu, 06 Nov 2008)
New Revision: 266

Added:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Types.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Barn.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouse.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouseProducer.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/impl/AbstractAnnotatedItem.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BindingTypeTest.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Tame.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
Log:
Support primitive/boxed type equality

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java	2008-11-06 16:49:13 UTC (rev 265)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -10,6 +10,7 @@
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import javax.webbeans.NullableDependencyException;
 import javax.webbeans.manager.Bean;
 
 import org.jboss.webbeans.injectable.Injectable;
@@ -69,7 +70,18 @@
    
    private void registerInjectionPoint(Injectable<?, ?> injectable)
    {
-	   resolvedInjectionPoints.put(injectable, retainHighestPrecedenceBeans(injectable.getMatchingBeans(manager.getBeans(), manager.getModelManager()), manager.getEnabledDeploymentTypes())); 
+      Set<Bean<?>> beans = retainHighestPrecedenceBeans(injectable.getMatchingBeans(manager.getBeans(), manager.getModelManager()), manager.getEnabledDeploymentTypes());
+      if (injectable.getType().isPrimitive())
+      {
+         for (Bean<?> bean : beans)
+         {
+            if (bean.isNullable())
+            {
+               throw new NullableDependencyException("Primitive injection points resolves to nullable web bean");
+            }
+         }
+      }
+	   resolvedInjectionPoints.put(injectable, beans); 
    }
    
    public void clear()

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/impl/AbstractAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/impl/AbstractAnnotatedItem.java	2008-11-06 16:49:13 UTC (rev 265)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/impl/AbstractAnnotatedItem.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -13,6 +13,7 @@
 import org.jboss.webbeans.exceptions.TypesafeResolutionLocation;
 import org.jboss.webbeans.introspector.AnnotatedItem;
 import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Types;
 
 public abstract class AbstractAnnotatedItem<T, S> implements AnnotatedItem<T, S>
 {
@@ -149,9 +150,7 @@
    
    private boolean isAssignableFrom(Class<?> type, Type[] actualTypeArguments)
    {
-      //TODO: primitive types and wrapper types should be considered equal
-      //TODO: array types should be considered equal only if the element type matches
-      return getType().isAssignableFrom(type) && Arrays.equals(getActualTypeArguments(), actualTypeArguments);
+      return Types.boxedType(getType()).isAssignableFrom(Types.boxedType(type)) && Arrays.equals(getActualTypeArguments(), actualTypeArguments);
    }
    
    @Override

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Types.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Types.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Types.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -0,0 +1,53 @@
+package org.jboss.webbeans.util;
+
+public class Types
+{
+   
+   public static Class<?> boxedType(Class<?> type)
+   {
+      if (type.isPrimitive())
+      {
+         if (type.equals(Boolean.TYPE))
+         {
+            return Boolean.class;
+         }
+         else if (type.equals(Character.TYPE))
+         {
+            return Character.class;
+         }
+         else if (type.equals(Byte.TYPE))
+         {
+            return Byte.class;
+         }
+         else if (type.equals(Short.TYPE))
+         {
+            return Short.class;
+         }
+         else if (type.equals(Integer.TYPE))
+         {
+            return Integer.class;
+         }
+         else if (type.equals(Long.TYPE))
+         {
+            return Long.class;
+         }
+         else if (type.equals(Float.TYPE))
+         {
+            return Float.class;
+         }
+         else if (type.equals(Double.TYPE))
+         {
+            return Double.class;
+         }
+         else 
+         {
+            throw new IllegalStateException("Some weird type!!!");
+         }
+      }
+      else
+      {
+         return type;
+      }
+   }
+   
+}


Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Types.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BindingTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BindingTypeTest.java	2008-11-06 16:49:13 UTC (rev 265)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BindingTypeTest.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -1,14 +1,19 @@
 package org.jboss.webbeans.test;
 
+import static org.jboss.webbeans.test.util.Util.createProducerMethodBean;
 import static org.jboss.webbeans.test.util.Util.createSimpleModel;
+import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.webbeans.AnnotationLiteral;
 import javax.webbeans.Current;
 
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bean.SimpleBean;
 import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
 import org.jboss.webbeans.introspector.AnnotatedClass;
 import org.jboss.webbeans.introspector.impl.SimpleAnnotatedClass;
@@ -17,9 +22,14 @@
 import org.jboss.webbeans.test.annotations.Asynchronous;
 import org.jboss.webbeans.test.annotations.Synchronous;
 import org.jboss.webbeans.test.beans.Antelope;
+import org.jboss.webbeans.test.beans.Barn;
 import org.jboss.webbeans.test.beans.Cat;
 import org.jboss.webbeans.test.beans.Cod;
+import org.jboss.webbeans.test.beans.DefangedTarantula;
 import org.jboss.webbeans.test.beans.Order;
+import org.jboss.webbeans.test.beans.Spider;
+import org.jboss.webbeans.test.beans.SpiderProducer;
+import org.jboss.webbeans.test.beans.Tarantula;
 import org.jboss.webbeans.test.beans.Tuna;
 import org.jboss.webbeans.test.bindings.AsynchronousAnnotationLiteral;
 import org.jboss.webbeans.util.Reflections;
@@ -38,12 +48,6 @@
       order.getBindingTypes().iterator().next().annotationType().equals(Current.class);
    }
 
-   @Test(groups={"injection", "producerMethod"}) @SpecAssertion(section="2.3.1")
-   public void testDefaultBindingTypeAssumedAtInjectionPoint() throws Exception
-   {
-      assert false;
-   }
-
    @Test(groups="annotationDefinition") @SpecAssertion(section="2.3.2")
    public void testBindingTypeHasCorrectTarget()
    {
@@ -124,9 +128,15 @@
 
 	
 	@Test(groups={"injection", "producerMethod"}) @SpecAssertion(section="2.3.5") 
-   public void testFieldInjectedFromProducerMethod()
+   public void testFieldInjectedFromProducerMethod() throws Exception
    {
-      assert false;
+	   SimpleBean<SpiderProducer> spiderProducer = createSimpleWebBean(SpiderProducer.class, manager);
+      manager.addBean(spiderProducer);
+      Method method = SpiderProducer.class.getMethod("produceTameTarantula");
+	   manager.addBean(createProducerMethodBean(Tarantula.class, method, manager, spiderProducer));
+      Barn barn = createSimpleWebBean(Barn.class, manager).create();
+      assert barn.petSpider != null;
+      assert barn.petSpider instanceof DefangedTarantula;
    }
 	
 	@Test(groups={"injection", "webbeansxml"}) @SpecAssertion(section="2.3.5") 
@@ -142,9 +152,17 @@
    }
 	
 	@Test(groups={"injection", "producerMethod"})
-   public void testMethodWithBindingAnnotationsOnParametersAreInjected()
+   public void testMethodWithBindingAnnotationsOnParametersAreInjected() throws Exception
    {
-      assert false;
+	   SimpleBean<SpiderProducer> spiderProducer = createSimpleWebBean(SpiderProducer.class, manager);
+      manager.addBean(spiderProducer);
+      Method method = SpiderProducer.class.getMethod("produceTameTarantula");
+      manager.addBean(createProducerMethodBean(Tarantula.class, method, manager, spiderProducer));
+      method = SpiderProducer.class.getMethod("produceSpiderFromInjection", Tarantula.class);
+      ProducerMethodBean<Spider> spiderBean = createProducerMethodBean(Spider.class, method, manager, spiderProducer);
+      Spider spider = spiderBean.create();
+      assert spider != null;
+      assert spider instanceof DefangedTarantula;
    }
 	
 	@Test(groups={"injection", "webbeansxml"}) @SpecAssertion(section="2.3.6") 

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java	2008-11-06 16:49:13 UTC (rev 265)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -1,12 +1,20 @@
 package org.jboss.webbeans.test;
 
+import static org.jboss.webbeans.test.util.Util.createProducerMethodBean;
 import static org.jboss.webbeans.test.util.Util.createSimpleModel;
+import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
 
+import java.lang.reflect.Method;
+
 import javax.webbeans.Production;
 import javax.webbeans.RequestScoped;
+import javax.webbeans.manager.Bean;
 
+import org.jboss.webbeans.bean.SimpleBean;
 import org.jboss.webbeans.model.bean.BeanModel;
 import org.jboss.webbeans.test.beans.RedSnapper;
+import org.jboss.webbeans.test.beans.Spider;
+import org.jboss.webbeans.test.beans.SpiderProducer;
 import org.testng.annotations.Test;
 
 /**
@@ -49,9 +57,16 @@
 	}
 	
 	@Test(groups="producerMethod") @SpecAssertion(section="4.2")
-   public void testIsNullable()
+   public void testIsNullable() throws Exception
    {
-      assert false;
+	   SimpleBean<SpiderProducer> spiderProducerBean = createSimpleWebBean(SpiderProducer.class, manager);
+	   manager.addBean(spiderProducerBean);
+      Method method = SpiderProducer.class.getMethod("getWolfSpiderSize");
+      Bean<Integer> bean = createProducerMethodBean(int.class, method, manager);
+      assert !bean.isNullable();
+      method = SpiderProducer.class.getMethod("makeASpider");
+      Bean<Spider> spiderBean = createProducerMethodBean(Spider.class, method, manager);
+      assert spiderBean.isNullable();
    }
 	
 }

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java	2008-11-06 16:49:13 UTC (rev 265)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -1,6 +1,7 @@
 package org.jboss.webbeans.test;
 
 
+import static org.jboss.webbeans.test.util.Util.createProducerMethodBean;
 import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
 
 import javax.webbeans.ContextNotActiveException;
@@ -15,6 +16,8 @@
 import org.jboss.webbeans.test.beans.Tuna;
 import org.jboss.webbeans.test.beans.broken.BeanWithFinalBoundField;
 import org.jboss.webbeans.test.beans.broken.BeanWithStaticBoundField;
+import org.jboss.webbeans.test.beans.broken.FarmHouse;
+import org.jboss.webbeans.test.beans.broken.FarmHouseProducer;
 import org.testng.annotations.Test;
 
 @SpecVersion("PDR")
@@ -40,15 +43,17 @@
    }
    
    @Test(groups={"injection", "producerMethod"}, expectedExceptions=NullableDependencyException.class) @SpecAssertion(section="4.2")
-   public void testPrimitiveInjectionPointResolvesToNullableWebBean()
+   public void testPrimitiveInjectionPointResolvesToNullableWebBean() throws Exception
    {
-      assert false;
+      Bean<FarmHouse> farmHouseBean = createSimpleWebBean(FarmHouse.class, manager);
+      manager.addBean(createProducerMethodBean(Integer.class, FarmHouseProducer.class.getMethod("getNumberOfBedrooms"), manager));
+      FarmHouse farmHouse = farmHouseBean.create();
    }
    
    @Test(groups={"injection", "clientProxy"}, expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="4.3")
    public void testInvokeNormalInjectedWebBeanWhenContextNotActive()
    {
-    
+      
    }
    
    @Test(groups="injection") @SpecAssertion(section="4.3")

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java	2008-11-06 16:49:13 UTC (rev 265)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -89,7 +89,7 @@
       assert false;
    }
    
-   @Test(groups="producerMethod") @SpecAssertion(section="3.4")
+   @Test(groups="producerMethod") @SpecAssertion(section={"3.4", "2.3.1"})
    public void testDefaultBindingType() throws Exception
    {
       SimpleBeanModel<SpiderProducer> model = createSimpleModel(SpiderProducer.class, manager);

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java	2008-11-06 16:49:13 UTC (rev 265)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -1,7 +1,9 @@
 package org.jboss.webbeans.test;
 
+import static org.jboss.webbeans.test.util.Util.createProducerMethodBean;
 import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
 
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
@@ -13,6 +15,7 @@
 import javax.webbeans.manager.Bean;
 
 import org.jboss.webbeans.ResolutionManager;
+import org.jboss.webbeans.bean.SimpleBean;
 import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
 import org.jboss.webbeans.injectable.InjectableField;
 import org.jboss.webbeans.test.annotations.Expensive;
@@ -31,6 +34,8 @@
 import org.jboss.webbeans.test.beans.ScottishFishFarmer;
 import org.jboss.webbeans.test.beans.SeaBass;
 import org.jboss.webbeans.test.beans.Sole;
+import org.jboss.webbeans.test.beans.Spider;
+import org.jboss.webbeans.test.beans.SpiderProducer;
 import org.jboss.webbeans.test.beans.Tuna;
 import org.jboss.webbeans.test.bindings.AnotherDeploymentTypeAnnotationLiteral;
 import org.jboss.webbeans.test.bindings.BindingTypeWithBindingAnnotationMemberAnnotationLiteral;
@@ -206,9 +211,18 @@
    }
    
    @Test(groups={"resolution", "producerMethod"}) @SpecAssertion(section="4.9.2")
-   public void testResolveByTypeWithArray()
+   public void testResolveByTypeWithArray() throws Exception
    {
-      assert false;
+      SimpleBean<SpiderProducer> spiderProducerBean = createSimpleWebBean(SpiderProducer.class, manager);
+      manager.addBean(spiderProducerBean);
+      Method method = SpiderProducer.class.getMethod("getSpiders");
+      Bean<Spider[]> spidersModel = createProducerMethodBean(Spider[].class, method, manager);
+      manager.addBean(spidersModel);
+      method = SpiderProducer.class.getMethod("getStrings");
+      Bean<String[]> stringModel = createProducerMethodBean(String[].class, method, manager);
+      manager.addBean(stringModel);
+      
+      assert manager.resolveByType(Spider[].class).size() == 1;
    }
    
    @Test @SpecAssertion(section="4.9.2")

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Tame.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Tame.java	2008-11-06 16:49:13 UTC (rev 265)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Tame.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -1,5 +1,6 @@
 package org.jboss.webbeans.test.annotations;
 
+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;
@@ -11,7 +12,7 @@
 
 import javax.webbeans.BindingType;
 
- at Target( { TYPE, METHOD, PARAMETER })
+ at Target( { TYPE, METHOD, PARAMETER, FIELD })
 @Retention(RUNTIME)
 @Documented
 @BindingType

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Barn.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Barn.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Barn.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.beans;
+
+import org.jboss.webbeans.test.annotations.Tame;
+
+public class Barn
+{
+   
+   @Tame
+   public Tarantula petSpider;
+   
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Barn.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java	2008-11-06 16:49:13 UTC (rev 265)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -70,6 +70,11 @@
       return ALL_SPIDERS;
    }
    
+   @Produces public String[] getStrings()
+   {
+      return new String[0];
+   }
+   
    @Produces public <T> FunnelWeaver<T> getFunnelWeaver()
    {
       return new FunnelWeaver<T>();
@@ -89,5 +94,10 @@
    {
       return null;
    }
+   
+   @Produces public Spider produceSpiderFromInjection(@Tame Tarantula tarantula) 
+   {
+      return tarantula;
+   }
 
 }

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouse.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouse.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouse.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.webbeans.Current;
+
+public class FarmHouse
+{
+
+   @Current
+   public int noOfBedrooms;
+   
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouse.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouseProducer.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouseProducer.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouseProducer.java	2008-11-06 16:51:22 UTC (rev 266)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.webbeans.Produces;
+
+public class FarmHouseProducer
+{
+   
+   @Produces public Integer getNumberOfBedrooms()
+   {
+      return null;
+   }
+   
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/FarmHouseProducer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the weld-commits mailing list