openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1458212 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/util/ClassUtil.java test/java/org/apache/webbeans/newtests/managed/generic/ test/java/org/apache/webbeans/newtests/managed/generic/GenericInjectionTest.java
Date Tue, 19 Mar 2013 10:33:56 GMT
Author: rmannibucau
Date: Tue Mar 19 10:33:56 2013
New Revision: 1458212

URL: http://svn.apache.org/r1458212
Log:
OWB-791 handling N generic types and not only a single one

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/generic/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/generic/GenericInjectionTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1458212&r1=1458211&r2=1458212&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Tue Mar 19 10:33:56 2013
@@ -670,48 +670,64 @@ public final class ClassUtil
     {
         Type requiredTypeArg = null;
         Type beanTypeArg = null;
+        int ok = 0;
         for(int i = 0; i< requiredTypeArgs.length;i++)
         {
             requiredTypeArg = requiredTypeArgs[i];
             beanTypeArg = beanTypeArgs[i];
-            
+
             //Required type is parametrized and bean type is parametrized
             if(ClassUtil.isParametrizedType(requiredTypeArg) && ClassUtil.isParametrizedType(beanTypeArg))
             {
-                return checkBeanAndRequiredTypeIsParametrized(beanTypeArg, requiredTypeArg);
+                if (checkBeanAndRequiredTypeIsParametrized(beanTypeArg, requiredTypeArg))
+                {
+                    ok++;
+                }
             }
             //Required type is wildcard
             else if(ClassUtil.isWildCardType(requiredTypeArg))
             {
-                return checkRequiredTypeIsWildCard(beanTypeArg, requiredTypeArg);
+                if (checkRequiredTypeIsWildCard(beanTypeArg, requiredTypeArg))
+                {
+                    ok++;
+                }
             }
             //Required type is actual type and bean type is type variable
             else if(requiredTypeArg instanceof Class && ClassUtil.isTypeVariable(beanTypeArg))
             {
-                return checkRequiredTypeIsClassAndBeanTypeIsVariable(beanTypeArg, requiredTypeArg);
+                if (checkRequiredTypeIsClassAndBeanTypeIsVariable(beanTypeArg, requiredTypeArg))
+                {
+                    ok++;
+                }
             }
             //Required type is Type variable and bean type is type variable
             else if(ClassUtil.isTypeVariable(requiredTypeArg) && ClassUtil.isTypeVariable(beanTypeArg))
             {
-                return checkBeanTypeAndRequiredIsTypeVariable(beanTypeArg, requiredTypeArg);
-            }      
-            
+                if ( checkBeanTypeAndRequiredIsTypeVariable(beanTypeArg, requiredTypeArg))
+                {
+                    ok++;
+                }
+            }
+
             //Both type is actual type
             else if((beanTypeArg instanceof Class) && (requiredTypeArg instanceof
Class))
             {
                 if(isClassAssignable((Class<?>)requiredTypeArg,(Class<?>)beanTypeArg))
                 {
-                    return true;
+                    ok++;
                 }
             }
             //Bean type is actual type and required type is type variable
             else if((beanTypeArg instanceof Class) && (ClassUtil.isTypeVariable(requiredTypeArg)))
             {
-                return checkRequiredTypeIsTypeVariableAndBeanTypeIsClass(beanTypeArg, requiredTypeArg);
+                if (checkRequiredTypeIsTypeVariableAndBeanTypeIsClass(beanTypeArg, requiredTypeArg))
+                {
+                    ok++;
+                }
             }
         }
-        
-        return false;
+
+        return ok == requiredTypeArgs.length;
     }
 
     /**

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/generic/GenericInjectionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/generic/GenericInjectionTest.java?rev=1458212&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/generic/GenericInjectionTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/managed/generic/GenericInjectionTest.java
Tue Mar 19 10:33:56 2013
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.managed.generic;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.inject.Inject;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.junit.Assert.assertNotNull;
+
+public class GenericInjectionTest extends AbstractUnitTest
+{
+    @Test
+    public void testGenericInjection()
+    {
+        final Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(StringIntAddress.class);
+        beanClasses.add(AddressStringInt.class);
+        beanClasses.add(IntStringAddress.class);
+        beanClasses.add(Helper.class);
+
+        startContainer(beanClasses);
+
+        // will fail if generics are not handled properly
+        final Bean<Helper> bean = getBean(Helper.class);
+        final Helper helper = Helper.class.cast(getBeanManager().getReference(bean, Helper.class,
null));
+        helper.checkAll();
+
+        shutDownContainer();
+    }
+
+    public static interface InterfaceWithMultipleGenerics<A, B, C>
+    {
+    }
+
+    public static class StringIntAddress implements InterfaceWithMultipleGenerics<String,
Integer, InetAddress>
+    {
+    }
+
+    public static class AddressStringInt implements InterfaceWithMultipleGenerics<Integer,
InetAddress, String>
+    {
+    }
+
+    public static class IntStringAddress implements InterfaceWithMultipleGenerics<Integer,
String, InetAddress>
+    {
+    }
+
+    public static class Helper
+    {
+        @Inject
+        private InterfaceWithMultipleGenerics<String, Integer, InetAddress> sia;
+
+        @Inject
+        private InterfaceWithMultipleGenerics<Integer, InetAddress, String> ias;
+
+        @Inject
+        private InterfaceWithMultipleGenerics<Integer, String, InetAddress> isa;
+
+        public void checkAll()
+        {
+            assertNotNull(sia);
+            assertNotNull(ias);
+            assertNotNull(isa);
+        }
+    }
+}



Mime
View raw message