openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1589179 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: config/OwbTypeVariableImpl.java config/OwbWildcardTypeImpl.java event/NotificationManager.java portable/AbstractAnnotated.java util/GenericsUtil.java
Date Tue, 22 Apr 2014 15:45:10 GMT
Author: arne
Date: Tue Apr 22 15:45:10 2014
New Revision: 1589179

URL: http://svn.apache.org/r1589179
Log:
OWB-946: Implemented generic type resolution for variables declared at method level

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbTypeVariableImpl.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbWildcardTypeImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.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/GenericsUtil.java

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbTypeVariableImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbTypeVariableImpl.java?rev=1589179&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbTypeVariableImpl.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbTypeVariableImpl.java
Tue Apr 22 15:45:10 2014
@@ -0,0 +1,123 @@
+/*
+ * 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.GenericDeclaration;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.Arrays;
+
+import org.apache.webbeans.util.Asserts;
+
+public class OwbTypeVariableImpl<G extends GenericDeclaration> implements TypeVariable<G>
+{
+
+    private String name;
+    private G genericDeclaration;
+    private Type[] bounds;
+
+    public OwbTypeVariableImpl(TypeVariable<G> typeVariable, Type... bounds)
+    {
+        name = typeVariable.getName();
+        genericDeclaration = typeVariable.getGenericDeclaration();
+        Asserts.assertNotNull(name);
+        Asserts.assertNotNull(genericDeclaration);
+        if (bounds == null || bounds.length == 0)
+        {
+            this.bounds = typeVariable.getBounds();
+        }
+        else
+        {
+            this.bounds = bounds;
+        }
+    }
+
+    @Override
+    public String getName()
+    {
+        return name;
+    }
+
+    @Override
+    public G getGenericDeclaration()
+    {
+        return genericDeclaration;
+    }
+
+    @Override
+    public Type[] getBounds()
+    {
+        return bounds.clone();
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode()
+    {
+       return Arrays.hashCode(bounds) ^ name.hashCode() ^ genericDeclaration.hashCode();
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object object)
+    {
+       if (this == object)
+       {
+          return true;
+       }
+       else if (object instanceof TypeVariable)
+       {
+          TypeVariable<?> that = (TypeVariable<?>)object;
+          return name.equals(that.getName()) && genericDeclaration.equals(that.getGenericDeclaration())
&& Arrays.equals(bounds, that.getBounds());
+       }
+       else
+       {
+          return false;
+       }
+       
+    }
+
+    public String toString()
+    {
+        StringBuilder buffer = new StringBuilder();
+        buffer.append(name);
+        if (bounds.length > 0)
+        {
+            buffer.append(" extends ");
+            boolean first = true;
+            for (Type bound: bounds)
+            {
+                if (first)
+                {
+                    first = false;
+                }
+                else
+                {
+                    buffer.append(',');
+                }
+                buffer.append(' ').append(bound);
+            }
+        }
+        return buffer.toString();
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbWildcardTypeImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbWildcardTypeImpl.java?rev=1589179&r1=1589178&r2=1589179&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbWildcardTypeImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OwbWildcardTypeImpl.java
Tue Apr 22 15:45:10 2014
@@ -44,4 +44,44 @@ public class OwbWildcardTypeImpl impleme
     {
         return lowerBounds.clone();
     }
+
+    public String toString()
+    {
+        StringBuilder buffer = new StringBuilder("?");
+        if (upperBounds.length > 0)
+        {
+            buffer.append(" extends");
+            boolean first = true;
+            for (Type upperBound: upperBounds)
+            {
+                if (first)
+                {
+                    first = false;
+                }
+                else
+                {
+                    buffer.append(',');
+                }
+                buffer.append(' ').append(upperBound);
+            }
+        }
+        if (lowerBounds.length > 0)
+        {
+            buffer.append(" super");
+            boolean first = true;
+            for (Type lowerBound: lowerBounds)
+            {
+                if (first)
+                {
+                    first = false;
+                }
+                else
+                {
+                    buffer.append(',');
+                }
+                buffer.append(' ').append(lowerBound);
+            }
+        }
+        return buffer.toString();
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=1589179&r1=1589178&r2=1589179&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
Tue Apr 22 15:45:10 2014
@@ -152,24 +152,21 @@ public final class NotificationManager
         
         Set<ObserverMethod<? super T>> matching = new HashSet<ObserverMethod<?
super T>>();
 
-        Set<Type> eventTypes = GenericsUtil.getTypeClosure(declaredEventType, eventClass);

+        Type eventType = GenericsUtil.resolveType(declaredEventType, eventClass); 
 
         Set<Type> observedTypes = observers.keySet();
 
         for (Type observedType : observedTypes)
         {
-            for (Type eventType : eventTypes)
+            if (GenericsUtil.isAssignableFrom(false, observedType, eventType))
             {
-                if (eventType.equals(observedType))
-                {
-                    Set<ObserverMethod<?>> observerMethods = observers.get(observedType);
+                Set<ObserverMethod<?>> observerMethods = observers.get(observedType);
 
-                    for (ObserverMethod<?> observerMethod : observerMethods)
-                    {
-                        matching.add((ObserverMethod<T>) observerMethod);
-                    }
-                    break;
+                for (ObserverMethod<?> observerMethod : observerMethods)
+                {
+                    matching.add((ObserverMethod<T>) observerMethod);
                 }
+                break;
             }
         }
         return matching;

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=1589179&r1=1589178&r2=1589179&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
Tue Apr 22 15:45:10 2014
@@ -155,7 +155,7 @@ abstract class AbstractAnnotated impleme
     {
         if (typeClosures == null)
         {
-            typeClosures = GenericsUtil.getTypeClosure(baseType, getOwningClass(), getDeclaringClass());
+            typeClosures = GenericsUtil.getTypeClosure(baseType, getOwningClass());
             Set<String> ignoredInterfaces = webBeansContext.getOpenWebBeansConfiguration().getIgnoredInterfaces();
             for (Iterator<Type> i = typeClosures.iterator(); i.hasNext(); )
             {

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=1589179&r1=1589178&r2=1589179&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
Tue Apr 22 15:45:10 2014
@@ -22,6 +22,7 @@ import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.GenericDeclaration;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
@@ -35,6 +36,7 @@ import java.util.Set;
 
 import org.apache.webbeans.config.OwbGenericArrayTypeImpl;
 import org.apache.webbeans.config.OwbParametrizedTypeImpl;
+import org.apache.webbeans.config.OwbTypeVariableImpl;
 import org.apache.webbeans.config.OwbWildcardTypeImpl;
 
 /**
@@ -323,7 +325,7 @@ public final class GenericsUtil
      */
     public static Type resolveType(Class<?> subclass, Field field)
     {
-        return resolveType(field.getGenericType(), subclass, field.getDeclaringClass());
+        return resolveType(field.getGenericType(), subclass);
     }
 
     /**
@@ -331,7 +333,7 @@ public final class GenericsUtil
      */
     public static Type resolveReturnType(Class<?> subclass, Method method)
     {
-        return resolveType(method.getGenericReturnType(), subclass, method.getDeclaringClass());
+        return resolveType(method.getGenericReturnType(), subclass);
     }
 
     /**
@@ -339,7 +341,7 @@ public final class GenericsUtil
      */
     public static Type[] resolveParameterTypes(Class<?> subclass, Constructor<?>
constructor)
     {
-        return resolveTypes(constructor.getGenericParameterTypes(), subclass, constructor.getDeclaringClass());
+        return resolveTypes(constructor.getGenericParameterTypes(), subclass);
     }
 
     /**
@@ -347,7 +349,7 @@ public final class GenericsUtil
      */
     public static Type[] resolveParameterTypes(Class<?> subclass, Method method)
     {
-        return resolveTypes(method.getGenericParameterTypes(), subclass, method.getDeclaringClass());
+        return resolveTypes(method.getGenericParameterTypes(), subclass);
     }
 
     /**
@@ -355,10 +357,10 @@ public final class GenericsUtil
      */
     public static Type resolveType(Type type, Class<?> subclass, Member member)
     {
-        return resolveType(type, subclass, member.getDeclaringClass());
+        return resolveType(type, subclass);
     }
 
-    public static Type resolveType(Type type, Type actualType, Type declaringType)
+    public static Type resolveType(Type type, Type actualType)
     {
         if (type instanceof Class)
         {
@@ -367,25 +369,25 @@ public final class GenericsUtil
         else if (type instanceof ParameterizedType)
         {
             ParameterizedType parameterizedType = (ParameterizedType)type;
-            Type[] resolvedTypeArguments = resolveTypes(parameterizedType.getActualTypeArguments(),
actualType, declaringType);
+            Type[] resolvedTypeArguments = resolveTypes(parameterizedType.getActualTypeArguments(),
actualType);
             return new OwbParametrizedTypeImpl(parameterizedType.getOwnerType(), parameterizedType.getRawType(),
resolvedTypeArguments);
         }
         else if (type instanceof TypeVariable)
         {
             TypeVariable<?> variable = (TypeVariable<?>)type;
-            return resolveTypeVariable(variable, declaringType, actualType);
+            return resolveTypeVariable(variable, actualType);
         }
         else if (type instanceof WildcardType)
         {
             WildcardType wildcardType = (WildcardType)type;
-            Type[] upperBounds = resolveTypes(wildcardType.getUpperBounds(), actualType,
declaringType);
-            Type[] lowerBounds = resolveTypes(wildcardType.getLowerBounds(), actualType,
declaringType);
+            Type[] upperBounds = resolveTypes(wildcardType.getUpperBounds(), actualType);
+            Type[] lowerBounds = resolveTypes(wildcardType.getLowerBounds(), actualType);
             return new OwbWildcardTypeImpl(upperBounds, lowerBounds);
         }
         else if (type instanceof GenericArrayType)
         {
             GenericArrayType arrayType = (GenericArrayType)type;
-            return createArrayType(resolveType(arrayType.getGenericComponentType(), actualType,
declaringType));
+            return createArrayType(resolveType(arrayType.getGenericComponentType(), actualType));
         }
         else
         {
@@ -393,12 +395,12 @@ public final class GenericsUtil
         }
     }
     
-    public static Type[] resolveTypes(Type[] types, Type actualType, Type declaringType)
+    public static Type[] resolveTypes(Type[] types, Type actualType)
     {
         Type[] resolvedTypeArguments = new Type[types.length];
         for (int i = 0; i < types.length; i++)
         {
-            resolvedTypeArguments[i] = resolveType(types[i], actualType, declaringType);
+            resolvedTypeArguments[i] = resolveType(types[i], actualType);
         }
         return resolvedTypeArguments;
     }
@@ -408,14 +410,9 @@ public final class GenericsUtil
         return getTypeClosure(type, type);
     }
 
-    public static Set<Type> getTypeClosure(Type actualType, Class<?> declaringClass)
+    public static Set<Type> getTypeClosure(Type actualType)
     {
-        Type type = declaringClass;
-        if (declaringClass.getTypeParameters().length > 0)
-        {
-            type = getParameterizedType(declaringClass);
-        }
-        return getTypeClosure(type, actualType, declaringClass);
+        return getTypeClosure(actualType, actualType);
     }
 
     /**
@@ -461,8 +458,14 @@ public final class GenericsUtil
      * @param declaringClass the class declaring the type
      * @return the type closure
      */
-    public static Set<Type> getTypeClosure(Type type, Type actualType, Class<?>
declaringClass)
+    public static Set<Type> getTypeClosure(Type type, Type actualType)
     {
+        Class<?> rawType = getRawType(type);
+        Class<?> actualRawType = getRawType(actualType);
+        if (rawType.isAssignableFrom(actualRawType) && rawType != actualRawType)
+        {
+            return getTypeClosure(actualType, type);
+        }
         if (type instanceof Class)
         {
             Class<?> classType = (Class<?>)type;
@@ -474,35 +477,26 @@ public final class GenericsUtil
         }
         Set<Type> typeClosure = new HashSet<Type>();
         typeClosure.add(Object.class);
-        fillTypeHierarchy(typeClosure, type, actualType, declaringClass);
+        fillTypeHierarchy(typeClosure, type, actualType);
         return typeClosure;
     }
 
-    private static void fillTypeHierarchy(Set<Type> set, Type type, Type actualType,
Type declaringType)
+    private static void fillTypeHierarchy(Set<Type> set, Type type, Type actualType)
     {
         if (type == null)
         {
            return;
         }
-        if (declaringType instanceof Class)
-        {
-            Class<?> declaringClass = (Class<?>)declaringType;
-            TypeVariable<?>[] typeParameters = declaringClass.getTypeParameters();
-            if (typeParameters.length > 0)
-            {
-                declaringType = new OwbParametrizedTypeImpl(declaringClass.getDeclaringClass(),
declaringClass, typeParameters);
-            }
-        }
-        Type resolvedType = GenericsUtil.resolveType(type, actualType, declaringType);
+        Type resolvedType = GenericsUtil.resolveType(type, actualType);
         set.add(resolvedType);
-        Class<?> resolvedClass = GenericsUtil.getRawType(resolvedType, actualType,
declaringType);
+        Class<?> resolvedClass = GenericsUtil.getRawType(resolvedType, actualType);
         if (resolvedClass.getSuperclass() != null)
         {
-            fillTypeHierarchy(set, resolvedClass.getGenericSuperclass(), resolvedClass.getGenericSuperclass(),
resolvedType);
+            fillTypeHierarchy(set, resolvedClass.getGenericSuperclass(), resolvedType);
         }
         for (Type interfaceType: resolvedClass.getGenericInterfaces())
         {
-            fillTypeHierarchy(set, interfaceType, interfaceType, resolvedType);
+            fillTypeHierarchy(set, interfaceType, resolvedType);
         }
     }
 
@@ -525,10 +519,10 @@ public final class GenericsUtil
 
     public static <T> Class<T> getRawType(Type type)
     {
-        return getRawType(type, null, null);
+        return getRawType(type, null);
     }
 
-    static <T> Class<T> getRawType(Type type, Type actualType, Type declaringType)
+    static <T> Class<T> getRawType(Type type, Type actualType)
     {
         if (type instanceof Class)
         {
@@ -537,24 +531,24 @@ public final class GenericsUtil
         else if (type instanceof ParameterizedType)
         {
             ParameterizedType parameterizedType = (ParameterizedType)type;
-            return getRawType(parameterizedType.getRawType(), actualType, declaringType);
+            return getRawType(parameterizedType.getRawType(), actualType);
         }
         else if (type instanceof TypeVariable)
         {
             TypeVariable<?> typeVariable = (TypeVariable<?>)type;
-            Type mostSpecificType = getMostSpecificType(getRawTypes(typeVariable.getBounds(),
actualType, declaringType), typeVariable.getBounds());
-            return getRawType(mostSpecificType, actualType, declaringType);
+            Type mostSpecificType = getMostSpecificType(getRawTypes(typeVariable.getBounds(),
actualType), typeVariable.getBounds());
+            return getRawType(mostSpecificType, actualType);
         }
         else if (type instanceof WildcardType)
         {
             WildcardType wildcardType = (WildcardType)type;
-            Type mostSpecificType = getMostSpecificType(getRawTypes(wildcardType.getUpperBounds(),
actualType, declaringType), wildcardType.getUpperBounds());
-            return getRawType(mostSpecificType, actualType, declaringType);
+            Type mostSpecificType = getMostSpecificType(getRawTypes(wildcardType.getUpperBounds(),
actualType), wildcardType.getUpperBounds());
+            return getRawType(mostSpecificType, actualType);
         }
         else if (type instanceof GenericArrayType)
         {
             GenericArrayType arrayType = (GenericArrayType)type;
-            return getRawType(createArrayType(getRawType(arrayType.getGenericComponentType(),
actualType, declaringType)), actualType, declaringType);
+            return getRawType(createArrayType(getRawType(arrayType.getGenericComponentType(),
actualType)), actualType);
         }
         else
         {
@@ -564,7 +558,7 @@ public final class GenericsUtil
 
     private static Type getRawType(Type[] types, Type actualType, Type declaringType)
     {
-        Class<?>[] rawTypes = getRawTypes(types, actualType, declaringType);
+        Class<?>[] rawTypes = getRawTypes(types, actualType);
         Class<?>[] classTypes = getClassTypes(rawTypes);
         if (classTypes.length > 0)
         {
@@ -578,15 +572,15 @@ public final class GenericsUtil
 
     private static <T> Class<T>[] getRawTypes(Type[] types)
     {
-        return getRawTypes(types, null, null);
+        return getRawTypes(types, null);
     }
 
-    private static <T> Class<T>[] getRawTypes(Type[] types, Type actualType,
Type declaringType)
+    private static <T> Class<T>[] getRawTypes(Type[] types, Type actualType)
     {
         Class<T>[] rawTypes = new Class[types.length];
         for (int i = 0; i < types.length; i++)
         {
-            rawTypes[i] = getRawType(types[i], actualType, declaringType);
+            rawTypes[i] = getRawType(types[i], actualType);
         }
         return rawTypes;
     }
@@ -619,24 +613,24 @@ public final class GenericsUtil
         return classTypes.toArray(new Class[classTypes.size()]);
     }
 
-    private static Type resolveTypeVariable(TypeVariable<?> variable, Type declaringType,
Type actualType)
+    private static Type resolveTypeVariable(TypeVariable<?> variable, Type actualType)
     {
-        if (declaringType == null || actualType == null)
+        if (actualType == null)
         {
             return variable;
         }
-        Class<?> declaringClass = getRawType(declaringType);
+        Class<?> declaringClass = getDeclaringClass(variable.getGenericDeclaration());
         Class<?> actualClass = getRawType(actualType);
         if (actualClass == declaringClass)
         {
-            return resolveTypeVariable(variable, getParameterizedType(declaringType), getParameterizedType(actualType));
+            return resolveTypeVariable(variable, variable.getGenericDeclaration(), getParameterizedType(actualType));
         }
         else if (actualClass.isAssignableFrom(declaringClass))
         {
             Class<?> directSubclass = getDirectSubclass(declaringClass, actualClass);
             Type[] typeArguments = resolveTypeArguments(directSubclass, actualType);
             Type directSubtype = new OwbParametrizedTypeImpl(directSubclass.getDeclaringClass(),
directSubclass, typeArguments);
-            return resolveTypeVariable(variable, declaringType, directSubtype);
+            return resolveTypeVariable(variable, directSubtype);
         }
         else // if (declaringClass.isAssignableFrom(actualClass))
         { 
@@ -653,7 +647,7 @@ public final class GenericsUtil
                 Type[] typeArguments = resolveTypeArguments(getParameterizedType(actualType),
genericSupertype);
                 genericSuperclass = new OwbParametrizedTypeImpl(genericSupertype.getOwnerType(),
genericSupertype.getRawType(), typeArguments);
             }
-            Type resolvedType = resolveTypeVariable(variable, declaringType, genericSuperclass);
+            Type resolvedType = resolveTypeVariable(variable, genericSuperclass);
             if (resolvedType instanceof TypeVariable)
             {
                 TypeVariable<?> resolvedTypeVariable = (TypeVariable<?>)resolvedType;
@@ -671,23 +665,63 @@ public final class GenericsUtil
         }
     }
 
-    private static Type resolveTypeVariable(TypeVariable<?> variable, ParameterizedType
type1, ParameterizedType type2)
+    private static Class<?> getDeclaringClass(GenericDeclaration declaration)
     {
-        Type resolvedType = variable;
-        int index = getIndex(type1, variable);
-        if (index >= 0)
+        if (declaration instanceof Class)
         {
-            resolvedType = type2.getActualTypeArguments()[index];
+            return (Class<?>)declaration;
+        }
+        else if (declaration instanceof Member)
+        {
+            return ((Member)declaration).getDeclaringClass();
         }
         else
         {
-            index = getIndex(type2, variable);
+            throw new IllegalArgumentException("Unsupported type " + declaration.getClass());
+        }
+    }
+
+    private static Type resolveTypeVariable(TypeVariable<?> variable, GenericDeclaration
declaration, ParameterizedType type)
+    {
+        int index = getIndex(declaration, variable);
+        if (declaration instanceof Class)
+        {
             if (index >= 0)
             {
-                resolvedType = type1.getActualTypeArguments()[index];
+                return type.getActualTypeArguments()[index];
+            }
+            else
+            {
+                index = getIndex(type, variable);
+                if (index >= 0)
+                {
+                    return declaration.getTypeParameters()[index];
+                }
+            }
+        }
+        else
+        {
+            Type[] resolvedBounds = resolveTypes(declaration.getTypeParameters()[index].getBounds(),
type);
+            return new OwbTypeVariableImpl<GenericDeclaration>((TypeVariable<GenericDeclaration>)variable,
resolvedBounds);
+        }
+        return variable;
+    }
+    
+    private static int getIndex(GenericDeclaration declaration, TypeVariable<?> variable)
+    {
+        Type[] typeParameters = declaration.getTypeParameters();
+        for (int i = 0; i < typeParameters.length; i++)
+        {
+            if (typeParameters[i] instanceof TypeVariable)
+            {
+                TypeVariable<?> variableArgument = (TypeVariable<?>)typeParameters[i];
+                if (variableArgument.getName().equals(variable.getName()))
+                {
+                    return i;
+                }
             }
         }
-        return resolvedType;
+        return -1;
     }
     
     private static int getIndex(ParameterizedType type, TypeVariable<?> variable)



Mime
View raw message