openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r788172 - in /incubator/openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/container/ main/java/org/apache/webbeans/inject/impl/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/test/component/inject/parame...
Date Wed, 24 Jun 2009 20:26:08 GMT
Author: gerdogdu
Date: Wed Jun 24 20:26:08 2009
New Revision: 788172

URL: http://svn.apache.org/viewvc?rev=788172&view=rev
Log:
Adding Parameterized Resolution Utility. See Specification Chapter 5.3.3

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Dao.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Persistent.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/User.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/UserDao.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/WithTypeVariable.java
  (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/parametrized/
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/parametrized/GenericClassTest.java
  (with props)
Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=788172&r1=788171&r2=788172&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
Wed Jun 24 20:26:08 2009
@@ -223,6 +223,15 @@
         return resolvedComponents;
     }
 
+    /**
+     * Resolution by type.
+     * 
+     * @param <T> bean type info
+     * @param apiType injection point api type
+     * @param actualTypeArguments actual type arguments if parameterized type
+     * @param binding binding type of the injection point
+     * @return set of resolved beans
+     */
     public <T> Set<Bean<T>> implResolveByType(Class<?> apiType, Type[]
actualTypeArguments, Annotation... binding)
     {
         Asserts.assertNotNull(apiType, "apiType parameter can not be null");
@@ -279,6 +288,7 @@
                     if (actualTypeArguments.length > 0)
                     {
                         Type[] actualArgs = null;
+                        
                         if (ClassUtil.isAssignable(apiType, componentApiType))
                         {
                             if (ProducerComponentImpl.class.isAssignableFrom(component.getClass()))

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java?rev=788172&r1=788171&r2=788172&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
Wed Jun 24 20:26:08 2009
@@ -28,6 +28,9 @@
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.ClassUtil;
+
 class InjectionPointImpl implements InjectionPoint
 {
     private Set<Annotation> bindingAnnotations = new HashSet<Annotation>();
@@ -42,6 +45,12 @@
     
     InjectionPointImpl(Bean<?> ownerBean, Type type, Member member)
     {
+        //Check for injection point type variable
+        if(ClassUtil.isTypeVariable(type))
+        {
+            throw new WebBeansConfigurationException("Injection point in bean : " + ownerBean
+ " can not define Type Variable generic type");
+        }
+        
         this.ownerBean = ownerBean;
         this.injectionMember = member;
         this.injectionType = type;

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=788172&r1=788171&r2=788172&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
(original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Wed Jun 24 20:26:08 2009
@@ -726,28 +726,64 @@
         return true;
     }
 
-    public static boolean isAssignable(Type lhs, Type rhs)
+    public static boolean isAssignable(Type beanType, Type requiredType)
     {
-        Asserts.assertNotNull(lhs, "lhs parameter can not be null");
-        Asserts.assertNotNull(rhs, "rhs parameter can not be null");
+        Asserts.assertNotNull(beanType, "lhs parameter can not be null");
+        Asserts.assertNotNull(requiredType, "rhs parameter can not be null");
 
-        if (lhs instanceof ParameterizedType && rhs instanceof ParameterizedType)
+        if (beanType instanceof ParameterizedType && requiredType instanceof ParameterizedType)
         {
-            return isAssignable((ParameterizedType) lhs, (ParameterizedType) rhs);
+            return isAssignableForParametrized((ParameterizedType) beanType, (ParameterizedType)
requiredType);
         }
-        else
+        else if (beanType instanceof Class && requiredType instanceof Class)
         {
-            if (lhs instanceof Class && rhs instanceof Class)
-            {
-                return isAssignable((Class) lhs, (Class) rhs);
-            }
-            else
+            return isAssignable((Class) beanType, (Class) requiredType);
+        }
+        else if(beanType instanceof ParameterizedType && requiredType instanceof
Class)
+        {
+            boolean ok = true;
+            Type[]  beanTypeArgs = ((ParameterizedType)beanType).getActualTypeArguments();
              
+            for(Type actual : beanTypeArgs)
             {
-                return false;
+                if(!ClassUtil.isWildCardType(actual))
+                {
+                    if(actual instanceof Class)
+                    {
+                        Class<?> clazz = (Class<?>)actual;
+                        if(clazz.equals(Object.class))
+                        {
+                            continue;
+                        }
+                        else
+                        {
+                            ok = false;
+                            break;
+                        }
+                    }
+                    else
+                    {
+                        ok = false;
+                        break;
+                    }
+                }
             }
+            
+            return ok;
+        }
+        else
+        {
+            return false;
         }
     }
 
+    /**
+     * Returns true if rhs is assignable type
+     * to the lhs, false otherwise.
+     * 
+     * @param lhs left hand side class
+     * @param rhs right hand side class
+     * @return true if rhs is assignable to lhs
+     */
     public static boolean isAssignable(Class<?> lhs, Class<?> rhs)
     {
         Asserts.assertNotNull(lhs, "lhs parameter can not be null");
@@ -761,25 +797,207 @@
         return false;
     }
 
-    public static boolean isAssignableForParametrized(ParameterizedType lhs, ParameterizedType
rhs)
+    /**
+     * Returns true if given bean's api type is injectable to
+     * injection point required type.
+     * 
+     * @param beanType bean parametrized api type
+     * @param requiredType injection point parametrized api type
+     * @return if injection is possible false otherwise
+     */
+    public static boolean isAssignableForParametrized(ParameterizedType beanType, ParameterizedType
requiredType)
     {
-        Class<?> rowLhs = (Class<?>) lhs.getRawType();
-        Class<?> rowRhs = (Class<?>) rhs.getRawType();
+        Class<?> beanRawType = (Class<?>) beanType.getRawType();
+        Class<?> requiredRawType = (Class<?>) requiredType.getRawType();
 
-        if (isAssignable(rowLhs, rowRhs))
+        if (ClassUtil.isAssignable(requiredRawType,beanRawType))
         {
-            Type[] lhsArgs = lhs.getActualTypeArguments();
-            Type[] rhsArgs = rhs.getActualTypeArguments();
+            //Bean api type actual type arguments
+            Type[] beanTypeArgs = beanType.getActualTypeArguments();
+            
+            //Injection point type actual arguments
+            Type[] requiredTypeArgs = requiredType.getActualTypeArguments();
+            
+            if(beanTypeArgs.length != requiredTypeArgs.length)
+            {                
+                return false;
+            }
+            else
+            {
+                return isAssignableForParametrizedCheckArguments(beanTypeArgs, requiredTypeArgs);
+            }
+        }
 
-            if (Arrays.equals(lhsArgs,rhsArgs))
+        return false;
+    }
+    
+    private static boolean isAssignableForParametrizedCheckArguments(Type[] beanTypeArgs,
Type[] requiredTypeArgs)
+    {
+        Type requiredTypeArg = null;
+        Type beanTypeArg = null;
+        for(int i = 0; i< requiredTypeArgs.length;i++)
+        {
+            requiredTypeArg = requiredTypeArgs[i];
+            beanTypeArg = beanTypeArgs[i];
+            
+            //Required type is parametrized
+            if(ClassUtil.isParametrizedType(requiredTypeArg) && ClassUtil.isParametrizedType(beanTypeArg))
+            {
+                return check1(beanTypeArg, requiredTypeArg);
+            }
+            //Required type is wildcard
+            else if(ClassUtil.isWildCardType(requiredTypeArg))
+            {
+                return check2(beanTypeArg, requiredTypeArg);
+            }
+            //Required type is actual type
+            else if(requiredTypeArg instanceof Class && ClassUtil.isTypeVariable(beanTypeArg))
+            {
+                return check3(beanTypeArg, requiredTypeArg);
+            }
+            //Required type is Type variable
+            else if(ClassUtil.isTypeVariable(requiredTypeArg) && ClassUtil.isTypeVariable(beanTypeArg))
+            {
+                return check4(beanTypeArg, requiredTypeArg);
+            }            
+        }
+        
+        return false;
+    }
+    
+    private static boolean check1(Type beanTypeArg, Type requiredTypeArg)
+    {
+        ParameterizedType ptRequiredTypeArg = (ParameterizedType)requiredTypeArg;
+        ParameterizedType ptBeanTypeArg = (ParameterizedType)beanTypeArg;
+        
+        //Equal raw types
+        if(ptRequiredTypeArg.getRawType().equals(ptBeanTypeArg.getRawType()))
+        {
+            //Check arguments
+            Type[] actualArgsRequiredType = ptRequiredTypeArg.getActualTypeArguments();
+            Type[] actualArgsBeanType = ptRequiredTypeArg.getActualTypeArguments();
+            
+            if(actualArgsRequiredType.length > 0 && actualArgsBeanType.length
== actualArgsRequiredType.length)
+            {
+                return isAssignableForParametrizedCheckArguments(actualArgsBeanType, actualArgsRequiredType);
+            }
+            else
             {
                 return true;
             }
         }
+        
+        return false;
+    }
+    
+    private static boolean check2(Type beanTypeArg, Type requiredTypeArg)
+    {
+        WildcardType wctRequiredTypeArg = (WildcardType)requiredTypeArg;
+        Type upperBoundRequiredTypeArg =  wctRequiredTypeArg.getUpperBounds()[0];
+        Type[] lowerBoundRequiredTypeArgs =  wctRequiredTypeArg.getLowerBounds();
+        
+        if(beanTypeArg instanceof Class)
+        {
+            Class<?> clazzBeanTypeArg = (Class<?>)beanTypeArg;
+            if(upperBoundRequiredTypeArg instanceof Class)
+            {
+                Class<?> clazzUpperBoundTypeArg = (Class<?>)upperBoundRequiredTypeArg;
+                if(clazzUpperBoundTypeArg.isAssignableFrom(clazzBeanTypeArg))
+                {                                         
+                    if(lowerBoundRequiredTypeArgs.length > 0 &&  lowerBoundRequiredTypeArgs[0]
instanceof Class)
+                    {
+                        Class<?> clazzLowerBoundTypeArg = (Class<?>)lowerBoundRequiredTypeArgs[0];
+                        if(clazzBeanTypeArg.isAssignableFrom(clazzLowerBoundTypeArg))
+                        {
+                            return true;
+                        }
+                    }
+                    else
+                    {
+                        return true;
+                    }
+                    
+                }
+            }                    
+        }
+        else if(ClassUtil.isTypeVariable(beanTypeArg))
+        {
+            TypeVariable<?> tvBeanTypeArg = (TypeVariable<?>)beanTypeArg;
+            Type tvBound = tvBeanTypeArg.getBounds()[0];
+            
+            if(tvBound instanceof Class)
+            {
+                Class<?> clazzTvBound = (Class<?>)tvBound;
+                
+                if(upperBoundRequiredTypeArg instanceof Class)
+                {
+                    Class<?> clazzUpperBoundTypeArg = (Class<?>)upperBoundRequiredTypeArg;
+                    if(clazzUpperBoundTypeArg.isAssignableFrom(clazzTvBound))
+                    {                            
+                        if(lowerBoundRequiredTypeArgs.length > 0 &&  lowerBoundRequiredTypeArgs[0]
instanceof Class)
+                        {
+                            Class<?> clazzLowerBoundTypeArg = (Class<?>)lowerBoundRequiredTypeArgs[0];
+                            if(clazzTvBound.isAssignableFrom(clazzLowerBoundTypeArg))
+                            {
+                                return true;
+                            }
+                        }
+                        else
+                        {
+                            return true;
+                        }
+                        
+                    }
+                }                                    
+            }
+        }
+         
+        return false;
+    }
+    
+    private static boolean check3(Type beanTypeArg, Type requiredTypeArg)
+    {
+        Class<?> clazzRequiredType = (Class<?>)requiredTypeArg;
+        
+        TypeVariable<?> tvBeanTypeArg = (TypeVariable<?>)beanTypeArg;
+        Type tvBound = tvBeanTypeArg.getBounds()[0];
+        
+        if(tvBound instanceof Class)
+        {
+            Class<?> clazzTvBound = (Class<?>)tvBound;
+            
+            if(clazzRequiredType.isAssignableFrom(clazzTvBound))
+            {
+                return true;
+            }                    
+        }
+        
+        return false;
+    }
 
+    private static boolean check4(Type beanTypeArg, Type requiredTypeArg)
+    {
+        TypeVariable<?> tvBeanTypeArg = (TypeVariable<?>)beanTypeArg;
+        Type tvBeanBound = tvBeanTypeArg.getBounds()[0];
+        
+        TypeVariable<?> tvRequiredTypeArg = (TypeVariable<?>)requiredTypeArg;
+        Type tvRequiredBound = tvRequiredTypeArg.getBounds()[0];
+        
+        if(tvBeanBound instanceof Class && tvRequiredBound instanceof Class)
+        {
+            Class<?> clazzTvBeanBound = (Class<?>)tvBeanBound;
+            Class<?> clazzTvRequiredBound = (Class<?>)tvRequiredBound;
+            
+            if(clazzTvRequiredBound.isAssignableFrom(clazzTvBeanBound))
+            {
+                return true;
+            }                    
+        }
+        
         return false;
     }
 
+
     public static boolean classHasFieldWithName(Class<?> clazz, String fieldName)
     {
         Asserts.nullCheckForClass(clazz);
@@ -1460,4 +1678,6 @@
             return getRootException(throwable.getCause());
         }
     }
+    
+    
 }

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Dao.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Dao.java?rev=788172&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Dao.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Dao.java
Wed Jun 24 20:26:08 2009
@@ -0,0 +1,27 @@
+/*
+ * 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.test.component.inject.parametrized;
+
+public class Dao<T extends Persistent>
+{
+    public Dao<T> t;
+    
+    public Dao<?> check22;
+    
+    public Dao<? extends Persistent> check22WithBound;
+    
+    public Dao raw;
+    
+    
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Dao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Persistent.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Persistent.java?rev=788172&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Persistent.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Persistent.java
Wed Jun 24 20:26:08 2009
@@ -0,0 +1,19 @@
+/*
+ * 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.test.component.inject.parametrized;
+
+public class Persistent
+{
+
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/Persistent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/User.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/User.java?rev=788172&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/User.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/User.java
Wed Jun 24 20:26:08 2009
@@ -0,0 +1,19 @@
+/*
+ * 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.test.component.inject.parametrized;
+
+public class User extends Persistent
+{
+
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/User.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/UserDao.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/UserDao.java?rev=788172&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/UserDao.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/UserDao.java
Wed Jun 24 20:26:08 2009
@@ -0,0 +1,24 @@
+/*
+ * 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.test.component.inject.parametrized;
+
+public class UserDao extends Dao<User>
+{
+
+    public Dao<User> field1;
+    public Dao<?> field2;
+    public Dao<? extends Persistent> field3;
+    public Dao<? extends User> field4;
+    
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/UserDao.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/WithTypeVariable.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/WithTypeVariable.java?rev=788172&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/WithTypeVariable.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/WithTypeVariable.java
Wed Jun 24 20:26:08 2009
@@ -0,0 +1,21 @@
+/*
+ * 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.test.component.inject.parametrized;
+
+public class WithTypeVariable<X extends Persistent>
+{
+    public Dao<X> check4;
+
+    
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/inject/parametrized/WithTypeVariable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/parametrized/GenericClassTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/parametrized/GenericClassTest.java?rev=788172&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/parametrized/GenericClassTest.java
(added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/parametrized/GenericClassTest.java
Wed Jun 24 20:26:08 2009
@@ -0,0 +1,77 @@
+/*
+ * 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.test.unittests.inject.parametrized;
+
+import java.lang.reflect.Field;
+
+import org.apache.webbeans.test.component.inject.parametrized.Dao;
+import org.apache.webbeans.test.component.inject.parametrized.UserDao;
+import org.apache.webbeans.test.component.inject.parametrized.WithTypeVariable;
+import org.apache.webbeans.test.servlet.TestContext;
+import org.apache.webbeans.util.ClassUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class GenericClassTest extends TestContext
+{
+    public GenericClassTest()
+    {
+        super(GenericClassTest.class.getName());
+    }
+
+    @Test
+    public void testGenericClasses()
+    {
+        try
+        {
+            Field t = Dao.class.getField("t");
+            Field raw = Dao.class.getField("raw");
+            Field check22 = Dao.class.getField("check22");
+            Field check22Bound = Dao.class.getField("check22WithBound");
+            Field check4 = WithTypeVariable.class.getField("check4");
+            
+            Assert.assertFalse(ClassUtil.isAssignable(t.getGenericType() , raw.getGenericType()));
+            Assert.assertTrue(ClassUtil.isAssignable(t.getGenericType() , check4.getGenericType()));
+            Assert.assertTrue(ClassUtil.isAssignable(t.getGenericType() , check22.getGenericType()));
+            Assert.assertTrue(ClassUtil.isAssignable(t.getGenericType() , check22Bound.getGenericType()));
+            
+        }catch(Exception e)
+        {
+            e.printStackTrace();
+            fail("testGenericClasses");
+        }
+    }
+    
+    @Test
+    public void testGenericClasses2()
+    {
+        try
+        {
+            Field f1 = UserDao.class.getField("field1");
+            Field f2 = UserDao.class.getField("field2");
+            Field f3 = UserDao.class.getField("field3");
+            Field f4 = UserDao.class.getField("field4");
+            
+            Assert.assertTrue(ClassUtil.isAssignable(f1.getGenericType() , f2.getGenericType()));
+            Assert.assertTrue(ClassUtil.isAssignable(f1.getGenericType() , f3.getGenericType()));
+            Assert.assertTrue(ClassUtil.isAssignable(f1.getGenericType() , f4.getGenericType()));
+            
+        }catch(Exception e)
+        {
+            e.printStackTrace();
+            fail("testGenericClasses");
+        }
+    }
+    
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/parametrized/GenericClassTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message