openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r939095 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/portable/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/newtests/concepts/apiTypes/tests/ test/java/...
Date Wed, 28 Apr 2010 21:17:29 GMT
Author: gerdogdu
Date: Wed Apr 28 21:17:26 2010
New Revision: 939095

URL: http://svn.apache.org/viewvc?rev=939095&view=rev
Log:
More strong Api type checking. Now, ParametrizedType variables are constitued for superclass/interfaces
type variables.

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeanTypeSetResolver.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/InjectorofMethod1Bean.java
  (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/MethodTypeProduces1.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbParametrizedTypeImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/apiTypes/tests/ApiTypeTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/clazz/ClazzTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/TypedComponentTest.java

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeanTypeSetResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeanTypeSetResolver.java?rev=939095&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeanTypeSetResolver.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeanTypeSetResolver.java
Wed Apr 28 21:17:26 2010
@@ -0,0 +1,246 @@
+/*
+ * 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.config;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.webbeans.util.ClassUtil;
+
+public class BeanTypeSetResolver
+{
+    /**Starting type*/
+    private final Type beanType;
+    
+    /**Hierarchy of the types*/
+    private Set<Type> hierarchy = new HashSet<Type>();
+    
+    public BeanTypeSetResolver(Type beanType)
+    {
+        this.beanType = beanType;
+    }
+    
+    /**
+     * Starts the type hierarchy configuration.
+     */
+    public void startConfiguration()
+    {
+        if(this.beanType == Object.class)
+        {
+            return;
+        }
+        
+        else if(ClassUtil.isParametrizedType(beanType))
+        {
+            parametrizedClassConfiguration((ParameterizedType)this.beanType);
+        }
+        else 
+        {
+            if(beanType instanceof Class)
+            {
+                normalClassConfiguration((Class<?>)this.beanType);
+   
+            }            
+        }
+    }
+    
+    /**
+     * Normal class configuration.
+     */
+    private void normalClassConfiguration(Class<?> beanClass)
+    {
+        //Bean class contains TypeVariables
+        if(ClassUtil.isDefinitionConstainsTypeVariables(beanClass))
+        {
+            //TypeVariables
+            OwbParametrizedTypeImpl pt = new OwbParametrizedTypeImpl(beanClass.getDeclaringClass(),beanClass);
+            TypeVariable<?>[] tvs = beanClass.getTypeParameters();
+            for(TypeVariable<?> tv : tvs)
+            {
+                pt.addTypeArgument(tv);
+            }
+            
+            this.hierarchy.add(pt);
+        }
+        //Normal Bean class
+        else
+        {
+            //Add this normal class
+            this.hierarchy.add(beanClass);            
+        }
+        
+        
+        //Look for super class
+        Type superClass = beanClass.getGenericSuperclass();
+        
+        if(superClass != null)
+        {
+            if(superClass != Object.class)
+            {
+                BeanTypeSetResolver superResolver = new BeanTypeSetResolver(superClass);
+                superResolver.startConfiguration();
+                this.hierarchy.addAll(superResolver.getHierarchy());
+            }            
+        }
+        
+        //Look for interfaces
+        Type[] interfaces = beanClass.getGenericInterfaces();
+        for(Type interfaceType : interfaces)
+        {
+            BeanTypeSetResolver superResolver = new BeanTypeSetResolver(interfaceType);
+            superResolver.startConfiguration();
+            this.hierarchy.addAll(superResolver.getHierarchy());            
+        }
+    }
+    
+    /**
+     * Bean class is a parametrized.
+     * @param parametrizedClass parametrized class
+     */
+    private void parametrizedClassConfiguration(ParameterizedType parametrizedClass)
+    {
+        //Add this parametrized type
+        this.hierarchy.add(parametrizedClass);
+        
+        //Get raw type
+        Class<?> rawType = (Class<?>)parametrizedClass.getRawType();
+        
+        //Look for super class
+        Type superClassGeneric = rawType.getGenericSuperclass();
+        
+        if(superClassGeneric != null)
+        {
+            boolean configured = false;
+
+            //Super class is a parametrized
+            if(ClassUtil.isParametrizedType(superClassGeneric))
+            {
+                //Resolve Type Arguments
+                this.hierarchy.add(resolveTypeArguments(parametrizedClass , (ParameterizedType)superClassGeneric));
+                configured = true;
+            }
+            //Super class is a normal
+            else
+            {
+                this.hierarchy.add(superClassGeneric);
+            }
+            
+            //Get super class hiearchy
+            BeanTypeSetResolver superResolver = new BeanTypeSetResolver(superClassGeneric);
+            superResolver.startConfiguration();
+            this.hierarchy.addAll(superResolver.getHierarchy());     
+            if(configured)
+            {
+                this.hierarchy.remove(superClassGeneric);
+            }
+        }
+                
+        //Interfaces here
+        Type[] superInterfacesGeneric = rawType.getGenericInterfaces();
+        
+        //Iterate over interfaces
+        for(Type superInterfaceGeneric : superInterfacesGeneric)
+        {
+            boolean configured = false;
+            
+            if(ClassUtil.isParametrizedType(superInterfaceGeneric))
+            {
+                //Resolve Type Arguments
+                this.hierarchy.add(resolveTypeArguments(parametrizedClass , (ParameterizedType)superInterfaceGeneric));
+                configured = true;
+            }
+            else
+            {
+                this.hierarchy.add(superInterfaceGeneric);
+            }   
+            
+            //Interface hierachy
+            BeanTypeSetResolver superResolver = new BeanTypeSetResolver(superInterfaceGeneric);
+            superResolver.startConfiguration();
+            this.hierarchy.addAll(superResolver.getHierarchy());
+            if(configured)
+            {
+                this.hierarchy.remove(superInterfaceGeneric);
+            }            
+        }        
+    }
+    
+    /**
+     * Configures type variables with actual parameters.
+     * @param beanClass parametrized bean class
+     * @param superClass parametrized super class
+     * @return parametrized type
+     */
+    private OwbParametrizedTypeImpl resolveTypeArguments(ParameterizedType beanClass, ParameterizedType
superClass)
+    {
+        OwbParametrizedTypeImpl ptImpl = new OwbParametrizedTypeImpl(superClass.getOwnerType(),superClass.getRawType());
+        
+        //Bean class type parameters
+        TypeVariable<?>[] beanClassTypeVariables = ClassUtil.getClass(beanClass).getTypeParameters();
+        //Bean class actual type arguments
+        Type[] beanClassArgs = beanClass.getActualTypeArguments();
+
+                                                                           
+            //Super class type arguments
+            Type[] superClassArgs = superClass.getActualTypeArguments();
+            for(Type superClassArg : superClassArgs)
+            {
+                boolean found = false;
+                for(int i = 0 ; i< beanClassTypeVariables.length ; i++)
+                {
+                    TypeVariable<?> beanClassTypeVariable  = beanClassTypeVariables[i];
+                    Type beanClassArg = beanClassArgs[i];
+                
+                    //If TypeVariable replace with actual type
+                    if(ClassUtil.isTypeVariable(superClassArg) && superClassArg.equals(beanClassTypeVariable))
+                    {
+                        ptImpl.addTypeArgument(beanClassArg);
+                        found = true;
+                        break;
+                    }
+                }
+
+                if(!found)
+                {
+                    if(ClassUtil.isParametrizedType(superClassArg))
+                    {
+                        ptImpl.addTypeArgument(resolveTypeArguments(beanClass, (ParameterizedType)superClassArg));
+                    }
+                    else
+                    {
+                        ptImpl.addTypeArgument(superClassArg);
+                    }                    
+                }
+            }
+        
+        return ptImpl;
+    }
+    
+    /**
+     * Gets hierarchy.
+     * @return hierarchy
+     */
+    public Set<Type> getHierarchy()
+    {
+        return this.hierarchy;
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeanTypeSetResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbParametrizedTypeImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbParametrizedTypeImpl.java?rev=939095&r1=939094&r2=939095&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbParametrizedTypeImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbParametrizedTypeImpl.java
Wed Apr 28 21:17:26 2010
@@ -20,34 +20,51 @@ package org.apache.webbeans.config;
 
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 public class OwbParametrizedTypeImpl implements ParameterizedType
 {
-    private final Class<?> clazz;
+    private final Type owner;
     
-    public OwbParametrizedTypeImpl(Class<?> clazz)
+    private final Type rawType;
+    
+    private final List<Type> types = new ArrayList<Type>();
+    
+    public OwbParametrizedTypeImpl(Type owner, Type raw)
     {
-        this.clazz = clazz;
+        this.owner = owner;
+        this.rawType = raw;
     }
     
     @Override
     public Type[] getActualTypeArguments()
     {
-        return clazz.getTypeParameters();
+        return this.types.toArray(new Type[0]);
+    }
+    
+    public void addTypeArgument(Type type)
+    {
+        this.types.add(type);
     }
 
     @Override
     public Type getOwnerType()
     {
-        return null;
+        return this.owner;
     }
 
     @Override
     public Type getRawType()
     {
-        return this.clazz;
+        return this.rawType;
     }
 
+    
+    
     /* (non-Javadoc)
      * @see java.lang.Object#hashCode()
      */
@@ -56,7 +73,9 @@ public class OwbParametrizedTypeImpl imp
     {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((clazz == null) ? 0 : clazz.hashCode());
+        result = prime * result + Arrays.hashCode(getActualTypeArguments());
+        result = prime * result + ((owner == null) ? 0 : owner.hashCode());
+        result = prime * result + ((rawType == null) ? 0 : rawType.hashCode());
         return result;
     }
 
@@ -73,13 +92,46 @@ public class OwbParametrizedTypeImpl imp
         if (getClass() != obj.getClass())
             return false;
         OwbParametrizedTypeImpl other = (OwbParametrizedTypeImpl) obj;
-        if (clazz == null)
+        if (!Arrays.equals(getActualTypeArguments(), other.getActualTypeArguments()))
+            return false;
+        if (owner == null)
         {
-            if (other.clazz != null)
+            if (other.owner != null)
                 return false;
         }
-        else if (!clazz.equals(other.clazz))
+        else if (!owner.equals(other.owner))
+            return false;
+        if (rawType == null)
+        {
+            if (other.rawType != null)
+                return false;
+        }
+        else if (!rawType.equals(other.rawType))
             return false;
         return true;
     }
+
+    public String toString()
+    {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append(((Class<?>)this.rawType).getSimpleName());
+        Type[] actualTypes = getActualTypeArguments();
+        if(actualTypes.length > 0)
+        {
+            buffer.append("<");
+            int length = actualTypes.length;
+            for(int i=0;i<length;i++)
+            {
+                buffer.append(actualTypes[i].toString());
+                if(i != actualTypes.length-1)
+                {
+                    buffer.append(",");
+                }
+            }
+            
+            buffer.append(">");
+        }
+        
+        return buffer.toString();
+    }
 }

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=939095&r1=939094&r2=939095&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
Wed Apr 28 21:17:26 2010
@@ -46,6 +46,7 @@ abstract class AbstractAnnotated impleme
     protected AbstractAnnotated(Type baseType)
     {
         this.baseType = baseType;
+        this.typeClosures.add(Object.class);
         ClassUtil.setTypeHierarchy(this.typeClosures, this.baseType);
     }
 

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=939095&r1=939094&r2=939095&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
Wed Apr 28 21:17:26 2010
@@ -45,8 +45,7 @@ import javax.enterprise.event.Event;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.inject.Provider;
 
-import org.apache.webbeans.config.OWBLogConst;
-import org.apache.webbeans.config.OwbParametrizedTypeImpl;
+import org.apache.webbeans.config.BeanTypeSetResolver;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.logger.WebBeansLogger;
 
@@ -784,16 +783,24 @@ public final class ClassUtil
 
         return true;
     }
-
+    
+    /**
+     * See specification 5.2.3.
+     * @param beanType bean type
+     * @param requiredType required type
+     * @return true if assignable
+     */
     public static boolean isAssignable(Type beanType, Type requiredType)
     {
         Asserts.assertNotNull(beanType, "beanType parameter can not be null");
         Asserts.assertNotNull(requiredType, "requiredType parameter can not be null");
-
+        
+        //Bean abd required types are ParametrizedType
         if (beanType instanceof ParameterizedType && requiredType instanceof ParameterizedType)
         {
             return isAssignableForParametrized((ParameterizedType) beanType, (ParameterizedType)
requiredType);
         }
+        //Both type is class type
         else if (beanType instanceof Class && requiredType instanceof Class)
         {
             Class<?> clzBeanType = (Class<?>)beanType;
@@ -811,6 +818,7 @@ public final class ClassUtil
             
             return clzReqType.equals(clzBeanType);
         }
+        //Bean type is Parametrized and required type is class type
         else if(beanType instanceof ParameterizedType && requiredType instanceof
Class)
         {
             boolean ok = true;
@@ -853,6 +861,7 @@ public final class ClassUtil
             
             return ok;
         }
+        //Bean type is class and required type is parametrized
         else if(beanType instanceof Class && requiredType instanceof ParameterizedType)
         {
             Class<?> clazzBeanType = (Class<?>)beanType;
@@ -986,6 +995,12 @@ public final class ClassUtil
         return false;
     }
     
+    /**
+     * Check parametrized type actual type arguments.
+     * @param beanTypeArgs bean type actual type arguments
+     * @param requiredTypeArgs required type actual type arguments.
+     * @return true if assignment applicable
+     */
     private static boolean isAssignableForParametrizedCheckArguments(Type[] beanTypeArgs,
Type[] requiredTypeArgs)
     {
         Type requiredTypeArg = null;
@@ -995,7 +1010,7 @@ public final class ClassUtil
             requiredTypeArg = requiredTypeArgs[i];
             beanTypeArg = beanTypeArgs[i];
             
-            //Required type is parametrized
+            //Required type is parametrized and bean type is parametrized
             if(ClassUtil.isParametrizedType(requiredTypeArg) && ClassUtil.isParametrizedType(beanTypeArg))
             {
                 return checkBeanAndRequiredTypeisParametrized(beanTypeArg, requiredTypeArg);
@@ -1005,16 +1020,18 @@ public final class ClassUtil
             {
                 return checkRequiredTypeisWildCard(beanTypeArg, requiredTypeArg);
             }
-            //Required type is actual type
+            //Required type is actual type and bean type is type variable
             else if(requiredTypeArg instanceof Class && ClassUtil.isTypeVariable(beanTypeArg))
             {
                 return checkRequiredTypeIsClassAndBeanTypeIsVariable(beanTypeArg, requiredTypeArg);
             }
-            //Required type is Type variable
+            //Required type is Type variable and bean type is type variable
             else if(ClassUtil.isTypeVariable(requiredTypeArg) && ClassUtil.isTypeVariable(beanTypeArg))
             {
                 return checkBeanTypeAndRequiredIsTypeVariable(beanTypeArg, requiredTypeArg);
             }      
+            
+            //Both type is actual type
             else if((beanTypeArg instanceof Class) && (requiredTypeArg instanceof
Class))
             {
                 if(isClassAssignable((Class<?>)requiredTypeArg,(Class<?>)beanTypeArg))
@@ -1022,6 +1039,7 @@ public final class ClassUtil
                     return true;
                 }
             }
+            //Bean type is actual type and required type is type variable
             else if((beanTypeArg instanceof Class) && (ClassUtil.isTypeVariable(requiredTypeArg)))
             {
                 return checkRequiredTypeIsTypeVariableAndBeanTypeIsClass(beanTypeArg, requiredTypeArg);
@@ -1031,6 +1049,13 @@ public final class ClassUtil
         return false;
     }
     
+    /**
+     * Check parametrized bean type and parametrized
+     * required types.
+     * @param beanTypeArg parametrized bean type
+     * @param requiredTypeArg parametrized required type
+     * @return true if types are assignables
+     */
     public static boolean checkBeanAndRequiredTypeisParametrized(Type beanTypeArg, Type requiredTypeArg)
     {
         ParameterizedType ptRequiredTypeArg = (ParameterizedType)requiredTypeArg;
@@ -1056,6 +1081,15 @@ public final class ClassUtil
         return false;
     }
     
+    /**
+     * Check bean type and required type.
+     * <p>
+     * Required type is a wildcard type.
+     * </p>
+     * @param beanTypeArg bean type
+     * @param requiredTypeArg required type
+     * @return true if contdition satisfies
+     */
     public static boolean checkRequiredTypeisWildCard(Type beanTypeArg, Type requiredTypeArg)
     {
         WildcardType wctRequiredTypeArg = (WildcardType)requiredTypeArg;
@@ -1067,22 +1101,28 @@ public final class ClassUtil
             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))
+                Class<?> clazzUpperBoundTypeArg = (Class<?>)upperBoundRequiredTypeArg;
               
+                if(clazzUpperBoundTypeArg != Object.class)
+                {
+                    if(clazzUpperBoundTypeArg.isAssignableFrom(clazzBeanTypeArg))
+                    {                                         
+                        if(lowerBoundRequiredTypeArgs.length > 0 &&  lowerBoundRequiredTypeArgs[0]
instanceof Class)
                         {
-                            return true;
+                            Class<?> clazzLowerBoundTypeArg = (Class<?>)lowerBoundRequiredTypeArgs[0];
+                            
+                            if(clazzLowerBoundTypeArg != Object.class)
+                            {
+                                if(!clazzBeanTypeArg.isAssignableFrom(clazzLowerBoundTypeArg))
+                                {
+                                    return false;
+                                }                                
+                            }
                         }
                     }
                     else
                     {
-                        return true;
+                        return false;
                     }
-                    
                 }
             }                    
         }
@@ -1097,30 +1137,46 @@ public final class ClassUtil
                 
                 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))
+                    Class<?> clazzUpperBoundTypeArg = (Class<?>)upperBoundRequiredTypeArg;
                   
+                    if(clazzUpperBoundTypeArg != Object.class && clazzTvBound !=
Object.class)
+                    {
+                        if(clazzUpperBoundTypeArg.isAssignableFrom(clazzTvBound))
+                        {                            
+                            if(lowerBoundRequiredTypeArgs.length > 0 &&  lowerBoundRequiredTypeArgs[0]
instanceof Class)
                             {
-                                return true;
+                                Class<?> clazzLowerBoundTypeArg = (Class<?>)lowerBoundRequiredTypeArgs[0];
+                                
+                                if(clazzLowerBoundTypeArg != Object.class)
+                                {
+                                    if(!clazzTvBound.isAssignableFrom(clazzLowerBoundTypeArg))
+                                    {
+                                        return false;
+                                    }                                    
+                                }
                             }
                         }
                         else
                         {
-                            return true;
+                            return false;
                         }
-                        
                     }
                 }                                    
             }
         }
          
-        return false;
+        return true;
     }
     
+    /**
+     * Checking bean type and required type.
+     * <p>
+     * Required type is class and bean type is
+     * a type variable.
+     * </p>
+     * @param beanTypeArg bean type 
+     * @param requiredTypeArg required type
+     * @return true if condition satisfy
+     */
     public static boolean checkRequiredTypeIsClassAndBeanTypeIsVariable(Type beanTypeArg,
Type requiredTypeArg)
     {
         Class<?> clazzRequiredType = (Class<?>)requiredTypeArg;
@@ -1132,13 +1188,16 @@ public final class ClassUtil
         {
             Class<?> clazzTvBound = (Class<?>)tvBound;
             
-            if(clazzRequiredType.isAssignableFrom(clazzTvBound))
+            if(clazzTvBound != Object.class)
             {
-                return true;
-            }                    
+                if(!clazzTvBound.isAssignableFrom(clazzRequiredType))
+                {
+                    return false;
+                }                                    
+            }            
         }
         
-        return false;
+        return true;
     }
     
     public static boolean checkRequiredTypeIsTypeVariableAndBeanTypeIsClass(Type beanTypeArg,
Type requiredTypeArg)
@@ -1175,7 +1234,7 @@ public final class ClassUtil
             Class<?> clazzTvBeanBound = (Class<?>)tvBeanBound;
             Class<?> clazzTvRequiredBound = (Class<?>)tvRequiredBound;
             
-            if(clazzTvRequiredBound.isAssignableFrom(clazzTvBeanBound))
+            if(clazzTvBeanBound.isAssignableFrom(clazzTvRequiredBound))
             {
                 return true;
             }                    
@@ -1613,42 +1672,13 @@ public final class ClassUtil
 
     public static Set<Type> setTypeHierarchy(Set<Type> set, Type clazz)
     {
-        Class<?> raw = getClazz(clazz);
+        BeanTypeSetResolver resolver = new BeanTypeSetResolver(clazz);
+        resolver.startConfiguration();
+        set.addAll(resolver.getHierarchy());
         
-        if (raw == null) 
-        {
-            return null;
-        }
-        
-        set.add(clazz);
-        if(ClassUtil.isDefinitionConstainsTypeVariables(raw))
-        {
-            set.add(new OwbParametrizedTypeImpl(raw));
-        }
-
-		Type sc = null;
-		try
-		{
-			sc = raw.getGenericSuperclass();
-		}
-		catch (Exception e)
-		{
-			logger.warn(OWBLogConst.WARN_0008, raw.getName(), e.getClass().getName(), e.getMessage());
-		}
-
-		if (sc != null)
-        {
-            setTypeHierarchy(set, sc);
-        }
-
-        Type[] interfaces = raw.getGenericInterfaces();
-        for (Type cl : interfaces)
-        {            
-            setTypeHierarchy(set, cl);
-        }
-
         return set;
     }
+
     
     
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/apiTypes/tests/ApiTypeTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/apiTypes/tests/ApiTypeTest.java?rev=939095&r1=939094&r2=939095&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/apiTypes/tests/ApiTypeTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/apiTypes/tests/ApiTypeTest.java
Wed Apr 28 21:17:26 2010
@@ -43,7 +43,7 @@ public class ApiTypeTest extends Abstrac
         DefinitionUtil.defineApiTypes(bean, ApiTypeBean.class);
         
         Set<Type> type = bean.getTypes();
-        Assert.assertEquals(7, type.size());
+        Assert.assertEquals(5, type.size());
     }
 
 }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java?rev=939095&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java
Wed Apr 28 21:17:26 2010
@@ -0,0 +1,71 @@
+/*
+ * 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.promethods;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+
+import junit.framework.Assert;
+
+import org.apache.webbeans.component.ManagedBean;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.promethods.beans.InjectorofMethod1Bean;
+import org.apache.webbeans.newtests.promethods.beans.MethodTypeProduces1;
+import org.junit.Test;
+
+public class MethodProducer1Test extends AbstractUnitTest
+{
+    public MethodProducer1Test()
+    {
+        
+    }
+    
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testPersonProducer()
+    {
+        Collection<URL> beanXmls = new ArrayList<URL>();
+        
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(MethodTypeProduces1.class);
+        beanClasses.add(InjectorofMethod1Bean.class);
+        
+        startContainer(beanClasses, beanXmls);      
+        
+        Set<Bean<?>> beans = getBeanManager().getBeans("injectorofMethod1Bean");
+        Assert.assertNotNull(beans);        
+        Bean<InjectorofMethod1Bean> bean = (Bean<InjectorofMethod1Bean>)beans.iterator().next();
+        
+        Assert.assertTrue(bean instanceof ManagedBean);
+        
+        CreationalContext<InjectorofMethod1Bean> ctx = getBeanManager().createCreationalContext(bean);
+        
+        Object reference = getBeanManager().getReference(bean, InjectorofMethod1Bean.class,
ctx);
+        Assert.assertNotNull(reference);
+        
+        Assert.assertTrue(reference instanceof InjectorofMethod1Bean);
+        
+        shutDownContainer();
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/MethodProducer1Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/InjectorofMethod1Bean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/InjectorofMethod1Bean.java?rev=939095&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/InjectorofMethod1Bean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/InjectorofMethod1Bean.java
Wed Apr 28 21:17:26 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.promethods.beans;
+
+import java.util.ArrayList;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@Named
+public class InjectorofMethod1Bean
+{
+    public @Inject @Named("ProMethodParameterized3") ArrayList<String> pt3;
+    
+    public ArrayList<String> getPt3()
+    {
+        return this.pt3;
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/InjectorofMethod1Bean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/MethodTypeProduces1.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/MethodTypeProduces1.java?rev=939095&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/MethodTypeProduces1.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/MethodTypeProduces1.java
Wed Apr 28 21:17:26 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.promethods.beans;
+
+import java.util.ArrayList;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+
+public class MethodTypeProduces1<T>
+{
+    @Produces @Dependent @Named("ProMethodParameterized3") 
+    ArrayList<T> methodPT3() 
+    {
+        return new ArrayList<T>();
+    }
+} 

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/promethods/beans/MethodTypeProduces1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/clazz/ClazzTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/clazz/ClazzTest.java?rev=939095&r1=939094&r2=939095&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/clazz/ClazzTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/clazz/ClazzTest.java
Wed Apr 28 21:17:26 2010
@@ -30,7 +30,7 @@ public class ClazzTest
         Set<Type> set = new HashSet<Type>();
         ClassUtil.setTypeHierarchy(set, Student.class);
 
-        Assert.assertEquals(8, set.size());
+        Assert.assertEquals(5, set.size());
 
     }
 
@@ -41,7 +41,7 @@ public class ClazzTest
 
         ClassUtil.setTypeHierarchy(set, Student2.class);
 
-        Assert.assertEquals(6, set.size());
+        Assert.assertEquals(4, set.size());
 
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/TypedComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/TypedComponentTest.java?rev=939095&r1=939094&r2=939095&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/TypedComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/TypedComponentTest.java
Wed Apr 28 21:17:26 2010
@@ -24,6 +24,7 @@ import javax.enterprise.inject.spi.BeanM
 import junit.framework.Assert;
 
 import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.test.TestContext;
 import org.apache.webbeans.test.component.service.ITyped;
 import org.apache.webbeans.test.component.service.TypedComponent;
@@ -51,9 +52,8 @@ public class TypedComponentTest extends 
     {
         clear();
         defineManagedBean(TypedComponent.class);
-        List<AbstractOwbBean<?>> list = getComponents();
 
-        Set<Bean<?>> beans= getManager().resolveByType(TypedComponentTest.class.getDeclaredField("s").getType(),
new Default()
+        Set<Bean<?>> beans= InjectionResolver.getInstance().implResolveByType(TypedComponentTest.class.getDeclaredField("s").getGenericType(),
new Default()
         {
 
             public Class<? extends Annotation> annotationType()



Mime
View raw message