[jboss-cvs] JBossAS SVN: r104375 - in projects/jboss-reflect/trunk/src: main/java/org/jboss/reflect/plugins/introspection and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 30 10:13:26 EDT 2010


Author: kabir.khan at jboss.com
Date: 2010-04-30 10:13:25 -0400 (Fri, 30 Apr 2010)
New Revision: 104375

Added:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/TypeVariableAware.java
Modified:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/ClassInfoImpl.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/ParameterizedClassInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/SecurityActions.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterizedClassInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/ClassInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/DelegateClassInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/NumberInfo.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/AbstractClassInfoTest.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericClassTest.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericMembersTest.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java
Log:
[JBREFLECT-5] Turn off caching for parameterized class infos since we don't know the classloader used to load them. Fix a problem with infinite recursion when recursive typevariable bounds are used

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/ClassInfoImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/ClassInfoImpl.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/ClassInfoImpl.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -715,4 +715,9 @@
          return tif.getTypeInfo(type);
       }
    }
+
+   public String getTypeVariable()
+   {
+      return null;
+   }
 }

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/TypeVariableAware.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/TypeVariableAware.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/TypeVariableAware.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.reflect.plugins;
+
+import org.jboss.reflect.spi.ClassInfo;
+
+/**
+ * Non-spi interface to internally set the type variable on a TypeInfo 
+ * for a parameterized type belonging to another parameterized type.
+ * This is useful for avoiding infinite recursion, see {@link ClassInfo#getTypeVariable()}
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TypeVariableAware
+{
+   /**
+    * Set the type variable
+    */
+   void setTypeVariable(String name);
+}

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -26,6 +26,7 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.GenericDeclaration;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
@@ -50,6 +51,7 @@
 import org.jboss.reflect.plugins.GenericsUtil;
 import org.jboss.reflect.plugins.MethodInfoImpl;
 import org.jboss.reflect.plugins.PackageInfoImpl;
+import org.jboss.reflect.plugins.TypeVariableAware;
 import org.jboss.reflect.spi.AnnotationInfo;
 import org.jboss.reflect.spi.AnnotationValue;
 import org.jboss.reflect.spi.ArrayInfo;
@@ -108,7 +110,9 @@
       {
          Type superClazz = clazz.getGenericSuperclass();
          if (superClazz != null)
+         {
             superType = (ClassInfo) getTypeInfo(superClazz);
+         }
       }
       return superType;
    }
@@ -152,6 +156,8 @@
          Constructor<?>[] constructors = getDeclaredConstructors(clazz);
          if (constructors != null && constructors.length > 0)
          {
+            ClassLoader requesting = SecurityActions.getClassLoaderOrSystemClassLoader(clazz);
+
             infos = new ReflectConstructorInfoImpl[constructors.length];
             for (int i = 0; i < constructors.length; ++i)
             {
@@ -165,7 +171,12 @@
                if (genericParameterTypes.length != parameterTypes.length)
                   genericParameterTypes = parameterTypes;
 
-               infos[i] = new ReflectConstructorInfoImpl(annotations, getTypeInfos(genericParameterTypes), getParameterAnnotations(constructors[i].getParameterAnnotations()), getClassInfos(constructors[i].getGenericExceptionTypes()), constructors[i].getModifiers(), (ClassInfo) getTypeInfo(constructors[i].getDeclaringClass()));
+               infos[i] = new ReflectConstructorInfoImpl(annotations, 
+                     getTypeInfos(genericParameterTypes), 
+                     getParameterAnnotations(constructors[i].getParameterAnnotations()), 
+                     getClassInfos(constructors[i].getGenericExceptionTypes()), 
+                     constructors[i].getModifiers(),
+                     (ClassInfo) getTypeInfo(constructors[i].getDeclaringClass()));
                infos[i].setConstructor(constructors[i]);
             }
          }
@@ -184,12 +195,18 @@
             Field[] fields = getDeclaredFields(clazz);
             if (fields == null || fields.length == 0)
                return null;
+            
+            ClassLoader requesting = SecurityActions.getClassLoaderOrSystemClassLoader(clazz);
 
             ReflectFieldInfoImpl[] infos = new ReflectFieldInfoImpl[fields.length];
             for (int i = 0; i < fields.length; ++i)
             {
                AnnotationValue[] annotations = getAnnotations(fields[i]);
-               infos[i] = new ReflectFieldInfoImpl(annotations, fields[i].getName(), getTypeInfo(fields[i].getGenericType()), fields[i].getModifiers(), (ClassInfo) getTypeInfo(fields[i].getDeclaringClass()));
+               infos[i] = new ReflectFieldInfoImpl(annotations, 
+                     fields[i].getName(), 
+                     getTypeInfo(fields[i].getGenericType()), 
+                     fields[i].getModifiers(), 
+                     (ClassInfo) getTypeInfo(fields[i].getDeclaringClass()));
                infos[i].setField(fields[i]);
             }
 
@@ -210,11 +227,20 @@
             if (methods == null || methods.length == 0)
                return null;
 
+            ClassLoader requesting = SecurityActions.getClassLoaderOrSystemClassLoader(clazz);
+
             ReflectMethodInfoImpl[] infos = new ReflectMethodInfoImpl[methods.length];
             for (int i = 0; i < methods.length; ++i)
             {
                AnnotationValue[] annotations = getAnnotations(methods[i]);
-               infos[i] = new ReflectMethodInfoImpl(annotations, methods[i].getName(), getTypeInfo(methods[i].getGenericReturnType()), getTypeInfos(methods[i].getGenericParameterTypes()), getParameterAnnotations(methods[i].getParameterAnnotations()), getClassInfos(methods[i].getGenericExceptionTypes()), methods[i].getModifiers(), (ClassInfo) getTypeInfo(methods[i].getDeclaringClass()));
+               infos[i] = new ReflectMethodInfoImpl(annotations, 
+                     methods[i].getName(), 
+                     getTypeInfo(methods[i].getGenericReturnType()),
+                     getTypeInfos(methods[i].getGenericParameterTypes()), 
+                     getParameterAnnotations(methods[i].getParameterAnnotations()), 
+                     getClassInfos(methods[i].getGenericExceptionTypes()), 
+                     methods[i].getModifiers(), 
+                     (ClassInfo) getTypeInfo(methods[i].getDeclaringClass()));
                infos[i].setMethod(methods[i]);
             }
             return infos;
@@ -484,7 +510,22 @@
       return result;
    }
 
+   
+   /**
+    * Overrides the {@link WeakTypeCache#getParameterizedType(ParameterizedType)}
+    * method so that parameterized types are not cached when getTypeInfo(Type) is called
+    * with a ParameterizedType with no information about the classloader.
+    * 
+    * @param type the parameterized type
+    * @return the parameterized type info
+    */
    @Override
+   protected TypeInfo getParameterizedType(ParameterizedType type)
+   {
+      return instantiate(type);
+   }
+
+   @Override
    protected TypeInfo instantiate(ParameterizedType type)
    {
       Class<?> rawType = (Class<?>) type.getRawType();
@@ -494,6 +535,15 @@
       return new ParameterizedClassInfo(this, rawTypeInfo, type);
    }
 
+   protected <D extends GenericDeclaration> TypeInfo getTypeVariable(TypeVariable<D> type)
+   {
+      TypeInfo info = super.getTypeVariable(type);
+      if (info instanceof TypeVariableAware)
+         ((TypeVariableAware)info).setTypeVariable(type.getName());
+      return info;
+   }
+
+   
    @Override
    protected void generate(Class<?> clazz, TypeInfo result)
    {

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/ParameterizedClassInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/ParameterizedClassInfo.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/ParameterizedClassInfo.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -24,6 +24,7 @@
 import java.lang.reflect.ParameterizedType;
 
 import org.jboss.reflect.plugins.ClassInfoImpl;
+import org.jboss.reflect.plugins.TypeVariableAware;
 import org.jboss.reflect.spi.ClassInfo;
 import org.jboss.reflect.spi.DelegateClassInfo;
 import org.jboss.reflect.spi.TypeInfo;
@@ -36,7 +37,7 @@
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @version $Revision: 1.1 $
  */
-public class ParameterizedClassInfo extends DelegateClassInfo
+public class ParameterizedClassInfo extends DelegateClassInfo implements TypeVariableAware
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 2;
@@ -62,6 +63,8 @@
    /** The key type */
    private transient TypeInfo valueType = ClassInfoImpl.UNKNOWN_TYPE;
    
+   private volatile String typeVariable;
+   
    /**
     * Create a new ParameterizedClassInfo.
     *
@@ -77,6 +80,16 @@
       this.parameterizedType = parameterizedType;
    }
 
+   public void setTypeVariable(String typeVariable)
+   {
+      this.typeVariable = typeVariable; 
+   }
+   
+   public String getTypeVariable()
+   {
+      return typeVariable;
+   }
+
    @Override
    public TypeInfoFactory getTypeInfoFactory()
    {

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/SecurityActions.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/SecurityActions.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/SecurityActions.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -24,6 +24,8 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
+import org.apache.tools.ant.taskdefs.Classloader;
+
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
@@ -66,4 +68,26 @@
          return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
       }
    }
+   
+   static ClassLoader getClassLoaderOrSystemClassLoader(Class<?> clazz)
+   {
+      ClassLoader loader = getClassLoader(clazz);
+      if (loader != null)
+         return loader;
+      
+      if (System.getSecurityManager() == null)
+         return ClassLoader.getSystemClassLoader();
+      return AccessController.doPrivileged(GetSystemClassLoaderAction.INSTANCE);
+   }
+   
+   static class GetSystemClassLoaderAction implements PrivilegedAction<ClassLoader>
+   {
+      private final static GetSystemClassLoaderAction INSTANCE = new GetSystemClassLoaderAction();
+      
+      public ClassLoader run()
+      {
+         return ClassLoader.getSystemClassLoader();
+      }
+      
+   }
 }

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterizedClassInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterizedClassInfo.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterizedClassInfo.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -21,16 +21,21 @@
 */ 
 package org.jboss.reflect.plugins.javassist;
 
+import java.lang.reflect.GenericDeclaration;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 import javassist.CtClass;
 import javassist.bytecode.SignatureAttribute.ClassSignature;
 import javassist.bytecode.SignatureAttribute.TypeArgument;
 
 import org.jboss.reflect.plugins.ClassInfoImpl;
+import org.jboss.reflect.plugins.TypeVariableAware;
 import org.jboss.reflect.spi.ClassInfo;
 import org.jboss.reflect.spi.ConstructorInfo;
 import org.jboss.reflect.spi.DelegateClassInfo;
@@ -46,7 +51,7 @@
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
-public class JavassistParameterizedClassInfo extends DelegateClassInfo
+public class JavassistParameterizedClassInfo extends DelegateClassInfo implements TypeVariableAware
 {
 
    /** The serialVersionUID */
@@ -61,6 +66,8 @@
    /** The factory to be used to lazily load up the type infos for the type arguments */
    private final LazyTypeArgumentFactory lazyTypeArgumentFactory;
    
+   private volatile String typeVariable;
+   
    /**
     * Constructor
     * 
@@ -101,6 +108,16 @@
          lazyTypeArgumentFactory = new FromClassFileTypeArgumentFactory(typeArguments, spy, classLoader);
    }
    
+   public void setTypeVariable(String typeVariable)
+   {
+      this.typeVariable = typeVariable; 
+   }
+   
+   public String getTypeVariable()
+   {
+      return typeVariable;
+   }
+   
    @Override
    public TypeInfoFactory getTypeInfoFactory()
    {
@@ -166,31 +183,49 @@
    @Override
    public void toShortString(JBossStringBuilder buffer)
    {
-      appendTypeGenericInfo(this, buffer);
+      appendTypeGenericInfo(this, buffer, null);
    }
 
-   private void appendTypeGenericInfo(TypeInfo info, JBossStringBuilder buffer)
+   private void appendTypeGenericInfo(TypeInfo info, JBossStringBuilder buffer, Set<String> doneTypeVariables)
    {
       boolean first = true;
-  
-      buffer.append(info.getName());
+
+      ClassInfo cinfo = null;
       if (info instanceof ClassInfo)
       {
-         ClassInfo cinfo = (ClassInfo)info;
+         cinfo = (ClassInfo)info;
+         if (cinfo.getTypeVariable() != null)
+         {
+            if (doneTypeVariables == null)
+               doneTypeVariables = new HashSet<String>();
+            else if (doneTypeVariables.contains(cinfo.getTypeVariable()))
+               return;
+            doneTypeVariables.add(cinfo.getTypeVariable());
+         }
+      }
+      
+      buffer.append(info.getName());
+      if (cinfo != null)
+      {
          if (cinfo.getActualTypeArguments().length > 0)
          {
-            buffer.append("<");
+            JBossStringBuilder params = new JBossStringBuilder();
+            params.append("<");
             for (TypeInfo arg : cinfo.getActualTypeArguments())
             {
                if (!first)
-                  buffer.append(", ");
+                  params.append(", ");
                else
                   first = false;
                   
-               appendTypeGenericInfo(arg, buffer);
+               appendTypeGenericInfo(arg, params, doneTypeVariables);
                
             }
-            buffer.append(">");
+            if (params.length() > 0)
+            {
+               params.append(">");
+               buffer.append(params.toString());
+            }
          }
       }
    }
@@ -269,7 +304,7 @@
       public ClassLoader getClassLoader()
       {
          return delegate.getClassLoader();
-      } 
+      }
    }
    
    /**
@@ -329,6 +364,5 @@
             sm.checkPermission(JavassistTypeInfo.GET_CLASSLOADER_PERMISSION);
          return classLoader;
       }
-      
    }
 }

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -1323,4 +1323,9 @@
       else
          return clazz.getName();
    }
+
+   public String getTypeVariable()
+   {
+      return null;
+   }
 }

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -53,6 +53,7 @@
 import org.jboss.reflect.plugins.AnnotationValueImpl;
 import org.jboss.reflect.plugins.EnumConstantInfoImpl;
 import org.jboss.reflect.plugins.GenericsUtil;
+import org.jboss.reflect.plugins.TypeVariableAware;
 import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
 import org.jboss.reflect.plugins.javassist.classpool.ClassPoolFactory;
 import org.jboss.reflect.plugins.javassist.classpool.DefaultClassPoolFactory;
@@ -777,26 +778,12 @@
     */
    protected TypeInfo getParameterizedType(ParameterizedType type)
    {
-      
-      //Look in the cache first
-      String genericName = GenericsUtil.getGenericName(type);
-      ClassLoader cl = GenericsUtil.findClassLoader(type);
-      Map<String, WeakReference<TypeInfo>> cache = getClassLoaderCache(cl);
-      TypeInfo info = getFromCache(genericName, cache);
-      if (info != null)
-         return info;
-      
       //Create the parameterized type info
       Class<?> rawType = (Class<?>) type.getRawType();
       ClassInfo raw = (ClassInfo)getTypeInfo(rawType);
       Type[] types = type.getActualTypeArguments();
       
-      info = new JavassistParameterizedClassInfo(this, raw, types);
-      
-      //Cache the parameterized type info
-      cache.put(genericName, new WeakReference<TypeInfo>(info));
-      
-      return info;
+      return new JavassistParameterizedClassInfo(this, raw, types);
    }
 
    /**
@@ -821,7 +808,10 @@
       }
       else if (type instanceof javassist.bytecode.SignatureAttribute.TypeVariable)
       {
-         return getTypeInfo(loader, spy.getTypeBound((javassist.bytecode.SignatureAttribute.TypeVariable)type), spy);
+         TypeInfo typeInfo = getTypeInfo(loader, spy.getTypeBound((javassist.bytecode.SignatureAttribute.TypeVariable)type), spy);
+         if (typeInfo instanceof TypeVariableAware)
+            ((TypeVariableAware)typeInfo).setTypeVariable(((javassist.bytecode.SignatureAttribute.TypeVariable)type).getName());
+         return typeInfo;
       }
       
       //Should not happen

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/ClassInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/ClassInfo.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/ClassInfo.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -165,4 +165,13 @@
     * @return the package
     */
    PackageInfo getPackage();
+   
+   /**
+    * Gets the type variable if we are a parameterized type which is part of a 
+    * parameterized type and there is a type variable for this type. This is
+    * useful in avoiding infinite recursion
+    * 
+    * @return the type variable
+    */
+   String getTypeVariable();
 }

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/DelegateClassInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/DelegateClassInfo.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/DelegateClassInfo.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -22,7 +22,10 @@
 package org.jboss.reflect.spi;
 
 import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
 
+import org.jboss.reflect.plugins.TypeVariableAware;
 import org.jboss.util.JBossStringBuilder;
 
 /**
@@ -354,6 +357,12 @@
    @Override
    public boolean equals(Object obj)
    {
+      return equals(obj, null);
+   }
+
+   
+   public boolean equals(Object obj, Set<String> doneTypeVariables)
+   {
       if (obj == this)
          return true;
       
@@ -365,12 +374,21 @@
       if (other instanceof DelegateClassInfo)
          otherDelegate = ((DelegateClassInfo) other).delegate;
       
-      if (delegate.equals(otherDelegate) == false)
+      if (!equalTypeInfos(delegate, otherDelegate, doneTypeVariables))
          return false;
       
       // We are equal to the raw type (seems hacky?)
       if (other instanceof DelegateClassInfo == false)
          return true;
+
+      if (getTypeVariable() != null)
+      {
+         if (doneTypeVariables == null)
+            doneTypeVariables = new HashSet<String>();
+         else if (doneTypeVariables.contains(getTypeVariable()))
+            return true;
+         doneTypeVariables.add(getTypeVariable());
+      }
       
       TypeInfo[] typeArguments = getActualTypeArguments();
       TypeInfo[] otherTypeArguments = other.getActualTypeArguments();
@@ -379,11 +397,33 @@
       
       for (int i = 0; i < typeArguments.length; ++i)
       {
-         if (typeArguments[i].equals(otherTypeArguments[i]) == false)
+         if (!equalTypeInfos(typeArguments[i], otherTypeArguments[i], doneTypeVariables))
             return false;
       }
       return true;
    }
+   
+   private boolean equalTypeInfos(TypeInfo infoA, TypeInfo infoB, Set<String> doneTypeVariables)
+   {
+      if (infoA instanceof DelegateClassInfo)
+      {
+         if (!((DelegateClassInfo)infoA).equals(infoB, doneTypeVariables))
+         return false;
+      }
+      else if (infoB instanceof DelegateClassInfo)
+      {
+         if (!((DelegateClassInfo)infoB).equals(infoA, doneTypeVariables))
+            return false;
+      }
+      else if (infoA.equals(infoB) == false)
+         return false;
+      return true;
+   }
+   
+   public String getTypeVariable()
+   {
+      return delegate.getTypeVariable();
+   }
 
    @Override
    public void toShortString(JBossStringBuilder buffer)

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/NumberInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/NumberInfo.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/NumberInfo.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -348,4 +348,9 @@
    {
       buffer.append(name);
    }
+
+   public String getTypeVariable()
+   {
+      return null;
+   }
 }

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/BeanInfoCacheTestCase.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -126,7 +126,7 @@
    {
       BeanInfo beanInfo = getConfiguration().getBeanInfo(typeInfo);
       ClassInfo typeInfo2 = beanInfo.getClassInfo();
-      assertSame(typeInfo, typeInfo2);
+      assertSameTypeInfos(typeInfo, typeInfo2);
    }
 
    private void assertClassInfo(ClassInfo typeInfo, String className, ClassLoader cl) throws Exception

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/AbstractClassInfoTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/AbstractClassInfoTest.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/AbstractClassInfoTest.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -614,6 +614,74 @@
       }
    }
    
+   /**
+    * Checks that the type infos are the same. If they are not parameterized types, does an assertSame().
+    * If they are parameterized types, does an assertEquals() on the parameterized types, before recursively
+    * going through the raw type and actual type arguments and invoking assertSame()/assertEquals() as 
+    * appropriate.
+    * 
+    */
+   protected void assertSameTypeInfos(TypeInfo typeA, TypeInfo typeB)
+   {
+      assertSameTypeInfos(typeA, typeB, new HashSet<String>());
+   }
+   
+   private void assertSameTypeInfos(TypeInfo typeA, TypeInfo typeB, Set<String> doneTypeVariahles)
+   {
+      typeA.toString();
+      typeB.toString();
+      if (typeA instanceof ClassInfo)
+      {
+         ClassInfo infoA = (ClassInfo)typeA;
+         ClassInfo infoB = assertInstanceOf(typeB, ClassInfo.class);
+         
+         if (infoA.getRawType() == infoA)
+         {
+            //Not a paramerized type, check same
+            assertSame(infoB, infoB.getRawType());
+            assertSame(infoB, infoA);
+         }
+         else
+         {
+            if (infoA.getTypeVariable() != null || infoB.getTypeVariable() != null)
+            {
+               assertEquals(infoA.getTypeVariable(), infoB.getTypeVariable());
+               if (doneTypeVariahles.contains(infoA.getTypeVariable()))
+                  return;
+               doneTypeVariahles.add(infoA.getTypeVariable());
+            }
+               
+            //Parameterized types
+            assertEquals(infoA, infoB);
+            assertSameTypeInfos(infoA.getRawType(), infoB.getRawType(), doneTypeVariahles);
+
+            TypeInfo[] argsA = infoA.getActualTypeArguments();
+            TypeInfo[] argsB = infoB.getActualTypeArguments();
+            
+            if (argsA != null)
+               assertNotNull(argsB);
+            if (argsB != null)
+               assertNotNull(argsA);
+            if (argsA == null)
+            {
+               assertNull(argsB);
+               return;
+            }
+            
+            assertEquals(argsA.length, argsB.length);
+            for (int i = 0 ; i < argsA.length ; i++)
+            {
+               assertSameTypeInfos(argsA[i], argsB[i], doneTypeVariahles);
+            }
+         }
+      }
+      else
+      {
+         //Some other type info
+         assertSame(typeA, typeB);
+      }
+   }
+   
    protected abstract TypeInfoFactory getTypeInfoFactory();
    
    protected void configureLogging()

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericClassTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericClassTest.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericClassTest.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -329,7 +329,7 @@
       TypeInfo infoB = getTypeInfoFactory().getTypeInfo(typeB);
       
       assertEquals(infoB, info);
-      assertSame(infoB, info);
+      assertSameTypeInfos(infoB, info);
    }
 
    public static <T> T signatureSimpleTypeVariable()
@@ -655,7 +655,7 @@
       TypeInfo typeInfo1 = getTypeInfoFactory().getTypeInfo(getGenericReturnType("signatureCollectionBoolean"));
       TypeInfo typeInfo2 = getTypeInfoFactory().getTypeInfo(getGenericReturnType("signatureCollectionBoolean"));
       assertEquals(typeInfo1, typeInfo2);
-      assertSame(typeInfo1, typeInfo2);
+      assertSameTypeInfos(typeInfo1, typeInfo2);
    }
    
    public static Collection<Long> signatureCollectionLong() 
@@ -677,7 +677,7 @@
       InterfaceInfo[] interfaceInfos = ((ClassInfo)getTypeInfoFactory().getTypeInfo(ClassInfoGenericImplementsCollectionComplex.class)).getGenericInterfaces();
       assertEquals(1, interfaceInfos.length);
       assertEquals(typeInfo, interfaceInfos[0]);
-      assertSame(typeInfo, interfaceInfos[0]);
+      assertSameTypeInfos(typeInfo, interfaceInfos[0]);
    }
    
    public void testCachedParameterizedClassInfoGenericSuperclass() throws Throwable
@@ -689,7 +689,7 @@
       assertEquals(1, classInfo2.getActualTypeArguments().length);
       
       assertEquals(classInfo1.getActualTypeArguments()[0], classInfo2.getActualTypeArguments()[0]);
-      assertSame(classInfo1.getActualTypeArguments()[0], classInfo2.getActualTypeArguments()[0]);
+      assertSameTypeInfos(classInfo1.getActualTypeArguments()[0], classInfo2.getActualTypeArguments()[0]);
    }
 
    public void testCachedParameterizedClassInfoComponentType() throws Throwable
@@ -699,7 +699,7 @@
       
       assertEquals(1, classInfo.getActualTypeArguments().length);
       assertEquals(classInfo.getActualTypeArguments()[0], componentType);
-      assertSame(classInfo.getActualTypeArguments()[0], componentType);
+      assertSameTypeInfos(classInfo.getActualTypeArguments()[0], componentType);
    }
 
    public void testCachedParameterizedClassInfoKeyValueType() throws Throwable
@@ -710,9 +710,9 @@
       
       assertEquals(2, classInfo.getActualTypeArguments().length);
       assertEquals(classInfo.getActualTypeArguments()[0], keyType);
-      assertSame(classInfo.getActualTypeArguments()[0], keyType);
+      assertSameTypeInfos(classInfo.getActualTypeArguments()[0], keyType);
       assertEquals(classInfo.getActualTypeArguments()[1], valueType);
-      assertSame(classInfo.getActualTypeArguments()[1], valueType);
+      assertSameTypeInfos(classInfo.getActualTypeArguments()[1], valueType);
    }
    
    public void testNotGenericClassInfoActualTypeArguments() throws Throwable

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericMembersTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericMembersTest.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericMembersTest.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -425,6 +425,15 @@
       Method m = getMethod(clazz, name);
       MethodInfo minfo = getMethodInfo(info, name);
       
+      //Debug testing stuff
+      
+      Method A = getMethod(clazz, name);
+      Method B = getMethod(clazz, name);
+      
+      assertEquals(A.getGenericReturnType(), B.getGenericReturnType());
+      
+      // Debug end
+      
       assertTypeAgainstRawReflect(m.getGenericReturnType(), minfo.getReturnType());
       
       Type[] parameterTypes = m.getGenericParameterTypes();
@@ -436,7 +445,7 @@
       }
       
       assertEquals(m.getGenericReturnType(), parameterTypes[0]);
-      assertSame(minfo.getReturnType(), parameterInfos[0]);
+      assertSameTypeInfos(minfo.getReturnType(), parameterInfos[0]);
 
       if (!generic)
       {
@@ -470,7 +479,7 @@
       }
       
       assertEquals(parameterTypes[1], parameterTypes[2]);
-      assertSame(parameterInfos[1], parameterInfos[2]);
+      assertSameTypeInfos(parameterInfos[1], parameterInfos[2]);
 
       if (!generic)
       {

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java	2010-04-30 14:01:01 UTC (rev 104374)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java	2010-04-30 14:13:25 UTC (rev 104375)
@@ -72,6 +72,8 @@
       suite.addTest(JavassistParameterizedClassInfoClassLoaderCachingTestCase.suite());
       suite.addTest(IntrospectionParameterizedClassInfoClassLoaderArgumentsTestCase.suite());
       suite.addTest(JavassistParameterizedClassInfoClassLoaderArgumentsTestCase.suite());
+      suite.addTest(IntrospectionClassInfoWithArrayMembersTestCase.suite());
+      suite.addTest(JavassistClassInfoWithArrayMembersTestCase.suite());
 
       return suite;
    }




More information about the jboss-cvs-commits mailing list