[webbeans-commits] Webbeans SVN: r3024 - ri/trunk/impl/src/main/java/org/jboss/webbeans/util and 1 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Jul 7 17:54:54 EDT 2009


Author: pete.muir at jboss.org
Date: 2009-07-07 17:54:54 -0400 (Tue, 07 Jul 2009)
New Revision: 3024

Added:
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/IntegerProducer.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/Small.java
Modified:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Types.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/DependencyResolutionTest.java
Log:
Test and fix for WBRI-287

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java	2009-07-07 21:51:03 UTC (rev 3023)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java	2009-07-07 21:54:54 UTC (rev 3024)
@@ -874,7 +874,8 @@
 
    public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> creationalContext)
    {
-      if (!bean.getTypes().contains(beanType))
+      
+      if (!Beans.isTypePresent(bean, beanType))
       {
          throw new IllegalArgumentException("The given beanType is not a type " + beanType +" of the bean " + bean );
       }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java	2009-07-07 21:51:03 UTC (rev 3023)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java	2009-07-07 21:54:54 UTC (rev 3024)
@@ -17,6 +17,7 @@
 package org.jboss.webbeans.util;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -186,4 +187,16 @@
       }
    }
    
+   public static boolean isTypePresent(Bean<?> bean, Type type)
+   {
+      type = Types.boxedType(type);
+      for (Type beanType : bean.getTypes())
+      {
+         if (Types.boxedType(beanType).equals(type))
+         {
+            return true;
+         }
+      }
+      return false;
+   }
 }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java	2009-07-07 21:51:03 UTC (rev 3023)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java	2009-07-07 21:54:54 UTC (rev 3024)
@@ -579,7 +579,7 @@
     */
    public static boolean isAssignableFrom(Class<?> rawType1, Type[] actualTypeArguments1, Class<?> rawType2, Type[] actualTypeArguments2)
    {
-      return Types.boxedType(rawType1).isAssignableFrom(Types.boxedType(rawType2)) && Arrays.equals(actualTypeArguments1, actualTypeArguments2);
+      return Types.boxedClass(rawType1).isAssignableFrom(Types.boxedClass(rawType2)) && Arrays.equals(actualTypeArguments1, actualTypeArguments2);
    }
    
    public static boolean isAssignableFrom(Type type1, Set<? extends Type> types2)

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Types.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Types.java	2009-07-07 21:51:03 UTC (rev 3023)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Types.java	2009-07-07 21:54:54 UTC (rev 3024)
@@ -16,6 +16,8 @@
  */
 package org.jboss.webbeans.util;
 
+import java.lang.reflect.Type;
+
 /**
  * Utility class for Types
  * 
@@ -30,55 +32,59 @@
     * @param type The type
     * @return The boxed type
     */
-   public static Class<?> boxedType(Class<?> type)
+   public static Type boxedType(Type type)
    {
-      if (type.isPrimitive())
+      if (type instanceof Class)
       {
-         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 if (type.equals(Void.TYPE))
-         {
-            return Void.class;
-         }
-         else
-         {
-            throw new IllegalStateException("Could not get boxed type for unknown type " + type);
-         }
+         return boxedClass((Class<?>) type);
       }
       else
       {
          return type;
       }
    }
+   
+   public static Class<?> boxedClass(Class<?> type)
+   {
+      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 if (type.equals(Void.TYPE))
+      {
+         return Void.class;
+      }
+      return type;
+   }
+   
+   
 
 }

Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/DependencyResolutionTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/DependencyResolutionTest.java	2009-07-07 21:51:03 UTC (rev 3023)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/DependencyResolutionTest.java	2009-07-07 21:54:54 UTC (rev 3024)
@@ -8,6 +8,7 @@
 import java.util.Set;
 
 import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.AnnotationLiteral;
 import javax.enterprise.inject.spi.Annotated;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
@@ -151,4 +152,12 @@
       MockInjectionPoint injectionPoint = new MockInjectionPoint(bean, Mustard.class, injectedField, bindings);
       getCurrentManager().getInjectableReference(injectionPoint, null);     
    }
+   
+   @Test
+   @SpecAssertion(section="5.1.3", id="aa")
+   public void testTypeBoxing()
+   {
+      assert getInstanceByType(Integer.class, new AnnotationLiteral<Small>() {}).equals(IntegerProducer.VALUE);
+   }
+   
 }

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/IntegerProducer.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/IntegerProducer.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/IntegerProducer.java	2009-07-07 21:54:54 UTC (rev 3024)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.jsr299.tck.tests.lookup.dependency.resolution;
+
+import javax.enterprise.inject.Produces;
+
+/**
+ * @author pmuir
+ *
+ */
+public class IntegerProducer
+{
+   
+   public static final int VALUE = 5;
+   
+   @Produces @Small
+   public int produce()
+   {
+      return VALUE; 
+   }
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/IntegerProducer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/Small.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/Small.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/Small.java	2009-07-07 21:54:54 UTC (rev 3024)
@@ -0,0 +1,22 @@
+package org.jboss.jsr299.tck.tests.lookup.dependency.resolution;
+
+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.enterprise.inject.BindingType;
+
+ at Target( { TYPE, METHOD, PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+ at BindingType
+ at interface Small
+{
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/dependency/resolution/Small.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the weld-commits mailing list