openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1628911 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/portable/ webbeans-impl/src/main/java/org/apache/webbeans/util/ webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/ webbeans-impl/sr...
Date Thu, 02 Oct 2014 09:28:04 GMT
Author: rmannibucau
Date: Thu Oct  2 09:28:04 2014
New Revision: 1628911

URL: http://svn.apache.org/r1628911
Log:
supporting generic producers

Removed:
    openwebbeans/trunk/webbeans-tck/src/test/java/
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/GenericsInTheZooTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/StableProducer.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/util/GenericsUtilTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java?rev=1628911&r1=1628910&r2=1628911&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
Thu Oct  2 09:28:04 2014
@@ -155,7 +155,7 @@ abstract class AbstractAnnotated impleme
     {
         if (typeClosures == null)
         {
-            typeClosures = GenericsUtil.getTypeClosure(baseType, getOwningClass());
+            typeClosures = extractTypeClojure(baseType);
             Set<String> ignoredInterfaces = webBeansContext.getOpenWebBeansConfiguration().getIgnoredInterfaces();
             if (!ignoredInterfaces.isEmpty())
             {
@@ -207,6 +207,11 @@ abstract class AbstractAnnotated impleme
         }
     }
 
+    protected Set<Type> extractTypeClojure(final Type baseType)
+    {
+        return GenericsUtil.getTypeClosure(baseType, getOwningClass());
+    }
+
     /**
      * {@inheritDoc}
      */

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedMethodImpl.java?rev=1628911&r1=1628910&r2=1628911&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AnnotatedMethodImpl.java
Thu Oct  2 09:28:04 2014
@@ -22,6 +22,8 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.util.GenericsUtil;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Set;
 
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedType;
@@ -48,7 +50,12 @@ class AnnotatedMethodImpl<X> extends Abs
         setAnnotations(javaMember.getDeclaredAnnotations());
         setAnnotatedParameters(GenericsUtil.resolveParameterTypes(declaringType.getJavaClass(),
javaMember), javaMember.getParameterAnnotations());
     }
-    
+
+    @Override
+    protected Set<Type> extractTypeClojure(final Type baseType)
+    {   // we want to skip hasTypeParameters() check which is already done for methods
+        return GenericsUtil.getDirectTypeClosure(baseType, getOwningClass());
+    }
     
     /**
      * {@inheritDoc}
@@ -58,16 +65,11 @@ class AnnotatedMethodImpl<X> extends Abs
     {
         return Method.class.cast(javaMember);
     }
-    
+
+    @Override
     public String toString()
     {
-        StringBuilder builder = new StringBuilder();
-        builder.append("Annotated Method '");
-        builder.append(javaMember.getName());
-        builder.append("', ");
-        builder.append(super.toString());
-
-        return builder.toString();
+        return "Annotated Method '" + javaMember.getName() + "', " + super.toString();
     }
     
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java?rev=1628911&r1=1628910&r2=1628911&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
Thu Oct  2 09:28:04 2014
@@ -231,6 +231,19 @@ public final class GenericsUtil
         Class<?> rawInjectionPointType = getRawType(injectionPointType);
         if (rawInjectionPointType.equals(beanType))
         {
+            if (isProducer)
+            {
+                for (final Type t : injectionPointType.getActualTypeArguments())
+                {
+                    if (!TypeVariable.class.isInstance(t) || !isNotBound(TypeVariable.class.cast(t).getBounds()))
+                    {
+                        if (!Class.class.isInstance(t) || Object.class != t)
+                        {
+                            return false;
+                        }
+                    }
+                }
+            }
             return true;
         }
         if (!rawInjectionPointType.isAssignableFrom(beanType))
@@ -293,20 +306,14 @@ public final class GenericsUtil
             {
                 final Type[] bounds = ((TypeVariable<?>) beanTypeArgument).getBounds();
                 final boolean isNotBound = isNotBound(bounds);
-                if (isNotBound)
-                {
-                    final boolean valid = Object.class == injectionPointTypeArgument
-                            || (TypeVariable.class.isInstance(injectionPointTypeArgument)
&& isNotBound(TypeVariable.class.cast(injectionPointTypeArgument).getBounds()));
-                    if (!valid)
-                    {
-                        return !isProducer;
-                    }
-                }
-                for (final Type upperBound : bounds)
+                if (!isNotBound)
                 {
-                    if (!isAssignableFrom(true, false, upperBound, injectionPointTypeArgument))
+                    for (final Type upperBound : bounds)
                     {
-                        return false;
+                        if (!isAssignableFrom(true, false, upperBound, injectionPointTypeArgument))
+                        {
+                            return false;
+                        }
                     }
                 }
             }
@@ -316,10 +323,7 @@ public final class GenericsUtil
             }
             else if (!isAssignableFrom(isDelegateOrEvent, false, injectionPointTypeArgument,
beanTypeArgument))
             {
-                if (!isProducer || beanTypeArgument != Object.class) // if unbound that's
ok for producers (5.2.3 IIRC)
-                {
-                    return false;
-                }
+                return false;
             }
         }
         return true;
@@ -672,6 +676,11 @@ public final class GenericsUtil
         {
             type = getParameterizedType(type);
         }
+        return getDirectTypeClosure(type, actualType);
+    }
+
+    public static Set<Type> getDirectTypeClosure(final Type type, final Type actualType)
+    {
         Set<Type> typeClosure = new HashSet<Type>();
         typeClosure.add(Object.class);
         fillTypeHierarchy(typeClosure, type, actualType);
@@ -707,6 +716,30 @@ public final class GenericsUtil
         return false;
     }
 
+    public static boolean hasBoundParameters(final ParameterizedType pt)
+    {
+        final Type[] typeParameters = pt.getActualTypeArguments();
+        if (typeParameters == null || typeParameters.length == 0)
+        {
+            return false;
+        }
+        for (final Type tv : typeParameters)
+        {
+            if (TypeVariable.class.isInstance(tv))
+            {
+                if (!isNotBound(TypeVariable.class.cast(tv).getBounds()))
+                {
+                    return true;
+                }
+            }
+            else
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
     public static ParameterizedType getParameterizedType(Type type)
     {
         if (type instanceof ParameterizedType)

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/GenericsInTheZooTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/GenericsInTheZooTest.java?rev=1628911&r1=1628910&r2=1628911&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/GenericsInTheZooTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/GenericsInTheZooTest.java
Thu Oct  2 09:28:04 2014
@@ -18,13 +18,11 @@
  */
 package org.apache.webbeans.test.injection.generics.zoo;
 
-import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.junit.Assert;
 import org.junit.Test;
 
 import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.spi.DeploymentException;
 import javax.inject.Inject;
 
 /**
@@ -64,7 +62,7 @@ public class GenericsInTheZooTest extend
         }
     }
 
-    @Test(expected = WebBeansConfigurationException.class) // yes it sucks but producers
and managed beans doesn't have same rules
+    @Test
     public void testGenericProducer() throws Exception
     {
         // create the stables via a single producer method

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/StableProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/StableProducer.java?rev=1628911&r1=1628910&r2=1628911&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/StableProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/zoo/StableProducer.java
Thu Oct  2 09:28:04 2014
@@ -48,4 +48,11 @@ public class StableProducer
 
         return stable;
     }
+
+    @Produces
+    @Dependent
+    public Stable createStableWithoutGenerics(InjectionPoint injectionPoint)
+    {
+        throw new UnsupportedOperationException("shouldn't be called");
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/util/GenericsUtilTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/util/GenericsUtilTest.java?rev=1628911&r1=1628910&r2=1628911&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/util/GenericsUtilTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/util/GenericsUtilTest.java
Thu Oct  2 09:28:04 2014
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTru
 
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.util.Set;
@@ -72,7 +73,6 @@ public class GenericsUtilTest {
         Assert.assertFalse(GenericsUtil.containsWildcardType(GenericObject.class.getMethod("getObject").getGenericReturnType()));
     }
 
-
     public static abstract class AbstractObject<V>
     {
     
@@ -142,4 +142,19 @@ public class GenericsUtilTest {
     {
 
     }
+
+    public static class Methods
+    {
+        public AbstractObject raw()
+        {
+            return new AbstractObject() {
+            };
+        }
+
+        public <T> AbstractObject<T> generic()
+        {
+            return new AbstractObject<T>() {
+            };
+        }
+    }
 }



Mime
View raw message