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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 15 11:55:36 EDT 2010


Author: kabir.khan at jboss.com
Date: 2010-03-15 11:55:34 -0400 (Mon, 15 Mar 2010)
New Revision: 102411

Added:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/GenericsUtil.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/SecurityActions.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/WildcardNumberInfo.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/WildcardTypeInfo.java
Removed:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SecurityActions.java
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/javassist/JavassistParameterizedClassInfo.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/DelegateClassInfo.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericClassTest.java
Log:
[JBREFLECT-5] Wildcard types

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/GenericsUtil.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/GenericsUtil.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/GenericsUtil.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -0,0 +1,115 @@
+/*
+* 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 java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.WildcardType;
+
+/**
+ * Common methods needed by both the javassist and introspection implementations 
+ * for figuring out generics.
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class GenericsUtil
+{
+   /**
+    * Create the name of the generic type
+    * 
+    *  @param type the generic type
+    *  @return the name
+    */
+   public static String getGenericName(Type type)
+   {
+      StringBuilder sb = new StringBuilder();
+      appendTypeGenericInfo(type, sb);
+      return sb.toString();
+   }
+
+   protected static void appendTypeGenericInfo(Type type, StringBuilder sb)
+   {
+      if (type instanceof Class)
+      {
+         sb.append(((Class<?>)type).getName());
+      }
+      else if (type instanceof WildcardType)
+      {
+         WildcardType wtype = (WildcardType)type;
+         Type[] lower = wtype.getLowerBounds();
+         Type[] upper = wtype.getUpperBounds();
+         
+         if (lower.length > 0)
+         {
+            sb.append("? super ");
+            appendTypeGenericInfo(lower[0], sb);
+         }
+         else if (upper.length > 0)
+         {
+            sb.append("? extends ");
+            appendTypeGenericInfo(upper[0], sb);
+         }
+      }
+      else if (type instanceof ParameterizedType)
+      {
+         ParameterizedType ptype = (ParameterizedType)type;
+         appendTypeGenericInfo(ptype.getRawType(), sb);
+         sb.append("<");
+         Type[] types = ptype.getActualTypeArguments();
+         for (int i = 0 ; i < types.length ; i++)
+         {
+            if (i > 0)
+               sb.append(", ");
+            appendTypeGenericInfo(types[i], sb);
+         }
+         sb.append(">");
+      }
+      else
+      {
+         //TODO This might need implementing once we test wildcards
+         throw new IllegalArgumentException("Unhandled type " + type.getClass().getName());
+      }
+   }
+   
+   public static ClassLoader findClassLoader(Type type)
+   {
+      if (type instanceof Class)
+         return SecurityActions.getClassLoader((Class<?>)type);
+      if (type instanceof ParameterizedType)
+      {
+         return findClassLoader(((ParameterizedType)type).getRawType());
+      }
+      if (type instanceof WildcardType)
+      {
+         WildcardType wtype = (WildcardType)type;
+         if (wtype.getUpperBounds().length > 0)
+            return findClassLoader(wtype.getUpperBounds()[0]);
+         if (wtype.getLowerBounds().length > 0)
+            return findClassLoader(wtype.getLowerBounds()[0]);
+      }
+      
+      
+      throw new IllegalArgumentException(type.getClass().getName() + " is not handled yet");
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/SecurityActions.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/SecurityActions.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/SecurityActions.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -0,0 +1,70 @@
+/*
+* 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 java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+   
+   interface GetClassLoaderAction 
+   {
+      ClassLoader getClassLoader(Class<?> clazz);
+      
+      GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(Class<?> clazz)
+         {
+            return clazz.getClassLoader();
+         }};
+
+     GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(final Class<?> clazz)
+         {
+            return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+               public ClassLoader run()
+               {
+                  return clazz.getClassLoader();
+               }});
+         }};
+   }
+   
+   static ClassLoader getClassLoader(Class<?> clazz)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return GetClassLoaderAction.NON_PRIVILEGED.getClassLoader(clazz);
+      }
+      else
+      {
+         return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
+      }
+   }
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/WildcardNumberInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/WildcardNumberInfo.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/WildcardNumberInfo.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -0,0 +1,56 @@
+/*
+* 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.NumberInfo;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * TypeInfo for a generic type with numeric bounds
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class WildcardNumberInfo extends NumberInfo
+{
+   private static final long serialVersionUID = 1L;
+
+   private final String name;
+   
+   public WildcardNumberInfo(String name, NumberInfo info)
+   {
+      super(info.ordinal(), info.getType());
+      this.name = name;
+   }
+
+   @Override
+   public void toShortString(JBossStringBuilder buffer)
+   {
+      buffer.append(name);
+   }
+
+   @Override
+   protected void toString(JBossStringBuilder buffer)
+   {
+      buffer.append(name);
+   }
+}

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/WildcardTypeInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/WildcardTypeInfo.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/WildcardTypeInfo.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -0,0 +1,58 @@
+/*
+* 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;
+import org.jboss.reflect.spi.DelegateClassInfo;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * Type info for a wildcard type
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class WildcardTypeInfo extends DelegateClassInfo
+{
+   private static final long serialVersionUID = 1L;
+   
+   private final String name;
+   
+   public WildcardTypeInfo(String name, ClassInfo delegate)
+   {
+      super(delegate);
+      this.name = name;
+   }
+
+   @Override
+   public void toShortString(JBossStringBuilder buffer)
+   {
+      buffer.append(name);
+   }
+
+   @Override
+   protected void toString(JBossStringBuilder buffer)
+   {
+      buffer.append("name=").append(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-03-15 15:51:11 UTC (rev 102410)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -22,6 +22,7 @@
 package org.jboss.reflect.plugins.introspection;
 
 import java.lang.annotation.Annotation;
+import java.lang.ref.WeakReference;
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
@@ -30,6 +31,7 @@
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Collection;
@@ -46,8 +48,11 @@
 import org.jboss.reflect.plugins.EnumConstantInfoImpl;
 import org.jboss.reflect.plugins.EnumInfoImpl;
 import org.jboss.reflect.plugins.FieldInfoImpl;
+import org.jboss.reflect.plugins.GenericsUtil;
 import org.jboss.reflect.plugins.MethodInfoImpl;
 import org.jboss.reflect.plugins.PackageInfoImpl;
+import org.jboss.reflect.plugins.WildcardNumberInfo;
+import org.jboss.reflect.plugins.WildcardTypeInfo;
 import org.jboss.reflect.spi.AnnotationInfo;
 import org.jboss.reflect.spi.AnnotationValue;
 import org.jboss.reflect.spi.ArrayInfo;
@@ -703,4 +708,32 @@
       // Not generic
       return Object.class;
    }
+
+   @Override
+   protected TypeInfo getWildcardType(WildcardType type)
+   {
+      //Look in the cache first
+      String genericName = GenericsUtil.getGenericName(type);
+      ClassLoader cl = GenericsUtil.findClassLoader(type);
+      Map<String, TypeInfo> cache = getClassLoaderCache(cl);
+      TypeInfo info = cache.get(genericName);
+      if (info != null)
+         return info;
+      
+      //Create the wildcard type info
+      Type bound = type.getLowerBounds().length > 0 ? type.getLowerBounds()[0] : type.getUpperBounds()[0];
+      ClassInfo raw = (ClassInfo)getTypeInfo(bound);
+      if (raw instanceof NumberInfo)
+         info = new WildcardNumberInfo(genericName, (NumberInfo)raw);
+      else
+         info = new WildcardTypeInfo(genericName, raw);
+      
+      //Cache the wildcard type info
+      cache.put(genericName, info);
+      
+      return info;
+
+   }
+   
+   
 }

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-03-15 15:51:11 UTC (rev 102410)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterizedClassInfo.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -66,11 +66,6 @@
       this.typeArgumentInfos = typeArgumentInfos;
    }
    
-   public ClassInfo getDelegate()
-   {
-      return delegate;
-   }
-   
    @Override
    public TypeInfoFactory getTypeInfoFactory()
    {

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-03-15 15:51:11 UTC (rev 102410)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -25,6 +25,7 @@
 import java.lang.ref.WeakReference;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.lang.reflect.WildcardType;
 import java.util.Map;
 
 import javassist.CtClass;
@@ -42,11 +43,15 @@
 import org.jboss.reflect.plugins.AnnotationValueFactory;
 import org.jboss.reflect.plugins.AnnotationValueImpl;
 import org.jboss.reflect.plugins.EnumConstantInfoImpl;
+import org.jboss.reflect.plugins.GenericsUtil;
+import org.jboss.reflect.plugins.WildcardNumberInfo;
+import org.jboss.reflect.plugins.WildcardTypeInfo;
 import org.jboss.reflect.plugins.javassist.classpool.ClassPoolFactory;
 import org.jboss.reflect.plugins.javassist.classpool.DefaultClassPoolFactory;
 import org.jboss.reflect.spi.AnnotationInfo;
 import org.jboss.reflect.spi.AnnotationValue;
 import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.DelegateClassInfo;
 import org.jboss.reflect.spi.MutableClassInfo;
 import org.jboss.reflect.spi.MutableTypeInfoFactory;
 import org.jboss.reflect.spi.NumberInfo;
@@ -377,9 +382,9 @@
                if(compare(((JavassistTypeInfo)result).getCtClass(), (ClassInfo) result))
                   return result;
             }
-            else if (result instanceof JavassistParameterizedClassInfo)
+            else if (result instanceof DelegateClassInfo)
             {
-               ClassInfo info = ((JavassistParameterizedClassInfo)result).getDelegate();
+               ClassInfo info = ((DelegateClassInfo)result).getDelegate();
                if (info instanceof JavassistTypeInfo)
                   if(compare(((JavassistTypeInfo)info).getCtClass(),  info))
                      return result;
@@ -537,7 +542,8 @@
          return getTypeInfo((Class<?>) type);
       else if (type instanceof ParameterizedType)
          return getParameterizedType((ParameterizedType)type);
-
+      else if (type instanceof WildcardType)
+         return getWildcardType((WildcardType)type);
       // TODO JBREFLECT-5 getTypeInfo + NumberInfo
       throw new org.jboss.util.NotImplementedException("getTypeInfo");
    }
@@ -575,10 +581,6 @@
          }
          return annotationValues;
       }
-//      catch (ClassNotFoundException e)
-//      {
-//         throw new RuntimeException(e);
-//      }
       catch (Throwable t)
       {
          throw new RuntimeException(t);
@@ -643,17 +645,15 @@
    {
       
       //Look in the cache first
-      String genericName = getGenericName(type);
-      Class<?> rawType = (Class<?>) type.getRawType();
-      ClassLoader cl = SecurityActions.getClassLoader(rawType);
-      if (cl == null)
-         cl = Thread.currentThread().getContextClassLoader();
+      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();
       TypeInfo[] typeInfos = new TypeInfo[types.length];
@@ -733,40 +733,36 @@
       throw new IllegalStateException("Unhandled type " + type);
    }
 
-   
-   
-   protected String getGenericName(ParameterizedType type)
+   protected TypeInfo getWildcardType(WildcardType type)
    {
-      StringBuilder sb = new StringBuilder();
-      appendTypeGenericInfo(type, sb);
-      return sb.toString();
+      //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 wildcard type info
+      Type bound = type.getLowerBounds().length > 0 ? type.getLowerBounds()[0] : type.getUpperBounds()[0];
+      ClassInfo raw = (ClassInfo)getTypeInfo(bound);
+      if (raw instanceof NumberInfo)
+         info = new WildcardNumberInfo(genericName, (NumberInfo)raw);
+      else
+         info = new WildcardTypeInfo(genericName, raw);
+      
+      //Cache the wildcard type info
+      cache.put(genericName, new WeakReference<TypeInfo>(info));
+      
+      return info;
    }
-
-   protected void appendTypeGenericInfo(Type type, StringBuilder sb)
+   
+   @Override
+   protected Map<String, WeakReference<TypeInfo>> getClassLoaderCache(ClassLoader cl)
    {
-      if (type instanceof Class)
-      {
-         sb.append(((Class<?>)type).getName());
-      }
-      else if (type instanceof ParameterizedType)
-      {
-         ParameterizedType ptype = (ParameterizedType)type;
-         appendTypeGenericInfo(ptype.getRawType(), sb);
-         sb.append("<");
-         Type[] types = ptype.getActualTypeArguments();
-         for (int i = 0 ; i < types.length ; i++)
-         {
-            if (i > 0)
-               sb.append(", ");
-            appendTypeGenericInfo(types[i], sb);
-         }
-         sb.append(">");
-      }
-      else
-      {
-         //TODO This might need implementing once we test wildcards
-         throw new IllegalArgumentException("Unhandled type " + type.getClass().getName());
-      }
+      if (cl == null)
+         cl = Thread.currentThread().getContextClassLoader();
+      return super.getClassLoaderCache(cl);
    }
 
    protected String getGenericName(ObjectType type)
@@ -804,5 +800,4 @@
          throw new IllegalArgumentException("Unhandled type " + type.getClass().getName());
       }
    }
-
 }

Deleted: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SecurityActions.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SecurityActions.java	2010-03-15 15:51:11 UTC (rev 102410)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/SecurityActions.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -1,70 +0,0 @@
-/*
-* 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.javassist;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * 
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-class SecurityActions
-{
-   
-   interface GetClassLoaderAction 
-   {
-      ClassLoader getClassLoader(Class<?> clazz);
-      
-      GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
-
-         public ClassLoader getClassLoader(Class<?> clazz)
-         {
-            return clazz.getClassLoader();
-         }};
-
-     GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
-
-         public ClassLoader getClassLoader(final Class<?> clazz)
-         {
-            return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
-
-               public ClassLoader run()
-               {
-                  return clazz.getClassLoader();
-               }});
-         }};
-   }
-   
-   static ClassLoader getClassLoader(Class<?> clazz)
-   {
-      if (System.getSecurityManager() == null)
-      {
-         return GetClassLoaderAction.NON_PRIVILEGED.getClassLoader(clazz);
-      }
-      else
-      {
-         return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
-      }
-   }
-}

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-03-15 15:51:11 UTC (rev 102410)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/spi/DelegateClassInfo.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -102,6 +102,11 @@
          throw new IllegalArgumentException("Null delegate");
       this.delegate = delegate;
    }
+   
+   public ClassInfo getDelegate()
+   {
+      return delegate;
+   }
 
    public TypeInfoFactory getTypeInfoFactory()
    {

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-03-15 15:51:11 UTC (rev 102410)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericClassTest.java	2010-03-15 15:55:34 UTC (rev 102411)
@@ -282,6 +282,37 @@
       assertComponentType(ClassInfoGenericExtendsCollectionComplex.class, type.getActualTypeArguments()[0]);
    }
 
+   public static Collection<?> signatureCollectionUnboundedWildcard() 
+   {
+      return null;
+   }
+
+   public void testComponentTypeCollectionUnboundedWildcard() throws Throwable
+   {
+      assertComponentType("signatureCollectionUnboundedWildcard", Object.class);
+   }
+
+   public static Collection<? extends Long> signatureCollectionUpperBoundedWildcard() 
+   {
+      return null;
+   }
+   
+   public void testComponentTypeCollectionUpperBoundedWildcard() throws Throwable
+   {
+      assertComponentType("signatureCollectionUpperBoundedWildcard", Long.class);
+   }
+
+   public static Collection<? super Long> signatureCollectionLowerBoundedWildcard() 
+   {
+      return null;
+   }
+   
+   public void testComponentTypeCollectionLowerBoundedWildcard() throws Throwable
+   {
+      assertComponentType("signatureCollectionLowerBoundedWildcard", Long.class);
+   }
+
+   
    public void testComponentTypeExtendsCollectionAndChangesParameter() throws Throwable
    {
       assertComponentType(ClassInfoGenericExtendsCollectionAndChangesParameter.class, Object.class);
@@ -379,11 +410,59 @@
       assertKeyValueType(ClassInfoGenericExtendsMapComplex.class, type.getActualTypeArguments()[0], type.getActualTypeArguments()[1]);
    }
 
+   public static Map<?, ?> signatureMapUnboundedWildcard() 
+   {
+      return null;
+   }
+
+   public void testKeyValueTypeMapUnboundedWildcard() throws Throwable
+   {
+      assertKeyValueType("signatureMapUnboundedWildcard", Object.class, Object.class);
+   }
+
+   public static Map<? extends String, ? extends Long> signatureMapUpperBoundedWildcard() 
+   {
+      return null;
+   }
+   
+   public void testKeyValueTypeMapUpperBoundedWildcard() throws Throwable
+   {
+      assertKeyValueType("signatureMapUpperBoundedWildcard", String.class, Long.class);
+   }
+
+   public static Map<? super String, ? super Long> signatureMapLowerBoundedWildcard() 
+   {
+      return null;
+   }
+   
+   public void testKeyValueTypeMapLowerBoundedWildcard() throws Throwable
+   {
+      assertKeyValueType("signatureMapLowerBoundedWildcard", String.class, Long.class);
+   }
+
    public void testKeyValueTypeExtendsMapAndChangesParameters() throws Throwable
    {
       assertKeyValueType(ClassInfoGenericExtendsMapAndChangesParameters.class, Object.class, Object.class);
    }
    
+   public static Map<? extends String, ? extends String> signatureMapCachedWildcard() 
+   {
+      return null;
+   }
+   
+   public void testKeyValueTypeMapCachedWildcard() throws Throwable
+   {
+      Type type = getGenericReturnType("signatureMapCachedWildcard");
+      TypeInfo typeInfo = getTypeInfoFactory().getTypeInfo(type);
+      assertNotNull(typeInfo);
+      assertTrue(typeInfo.isMap());
+      ClassInfo info = assertInstanceOf(typeInfo, ClassInfo.class);
+      TypeInfo key = info.getKeyType();
+      TypeInfo value = info.getValueType();
+//      assertEquals("? extends java.lang.String", key.getName());
+      assertSame(key, value);
+   }
+
    public static ClassInfoGenericExtendsMapAndChangesParameters<Float, Double> signatureMapChangesParameter() 
    {
       return null;
@@ -507,7 +586,6 @@
       ClassInfo keyType = (ClassInfo)((ClassInfo)getTypeInfoFactory().getTypeInfo(ClassInfoGenericImplementsMapComplex.class)).getKeyType();
       ClassInfo valueType = (ClassInfo)((ClassInfo)getTypeInfoFactory().getTypeInfo(ClassInfoGenericImplementsMapComplex.class)).getValueType();
       
-//      Map<List<Class<String>>, Map<String, Class<String>>>
       assertEquals(2, classInfo.getActualTypeArguments().length);
       assertEquals(classInfo.getActualTypeArguments()[0], keyType);
       assertSame(classInfo.getActualTypeArguments()[0], keyType);




More information about the jboss-cvs-commits mailing list