[jboss-cvs] JBossAS SVN: r101736 - in projects/jboss-reflect/trunk: src/main/java/org/jboss/reflect/plugins/javassist and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 2 15:06:11 EST 2010


Author: kabir.khan at jboss.com
Date: 2010-03-02 15:06:10 -0500 (Tue, 02 Mar 2010)
New Revision: 101736

Added:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistHelper.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterizedClassInfo.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistGenericClassUnitTestCase.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistGenericInterfaceUnitTestCase.java
Modified:
   projects/jboss-reflect/trunk/pom.xml
   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/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java
Log:
[JBREFLECT-5] Initial attempt at implementing generics in Javassist

Modified: projects/jboss-reflect/trunk/pom.xml
===================================================================
--- projects/jboss-reflect/trunk/pom.xml	2010-03-02 18:28:00 UTC (rev 101735)
+++ projects/jboss-reflect/trunk/pom.xml	2010-03-02 20:06:10 UTC (rev 101736)
@@ -98,6 +98,12 @@
       <version>${version.jboss.profiler.jvmti}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-log4j</artifactId>
+      <version>${version.jboss.logging.log4j}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <!-- site stuff -->

Added: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistHelper.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistHelper.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistHelper.java	2010-03-02 20:06:10 UTC (rev 101736)
@@ -0,0 +1,287 @@
+/*
+* 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.util.Arrays;
+import java.util.Stack;
+
+import org.jboss.reflect.spi.TypeInfo;
+
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.bytecode.BadBytecode;
+import javassist.bytecode.SignatureAttribute;
+import javassist.bytecode.SignatureAttribute.ClassSignature;
+import javassist.bytecode.SignatureAttribute.ClassType;
+import javassist.bytecode.SignatureAttribute.ObjectType;
+import javassist.bytecode.SignatureAttribute.TypeArgument;
+import javassist.bytecode.SignatureAttribute.TypeParameter;
+import javassist.bytecode.SignatureAttribute.TypeVariable;
+
+/**
+ * TODO This is prototype code! Once there are some tests for things like nested generics etc., it is very likely that we will need
+ * to change signatures of methods in this class as needed.
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavassistHelper
+{
+   /**
+    * Looking at the classes between clazz and search, determine the type of the type parameter with the passed in index
+    * 
+    * @param clazz the sub class
+    * @param search the parent class or interface we are searching for
+    * @param parameter the index of the type parameter we are looking for
+    * @return the type
+    */
+   static String determineType(CtClass clazz, CtClass search, int parameter)
+   {
+      Stack<CtClass> hierarchy = new Stack<CtClass>();      
+      try
+      {
+         determineHierarchy(hierarchy, clazz, search);
+      }
+      catch (NotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+      return determineType(hierarchy, parameter);
+   }
+
+   static int determineInfoIndex(TypeInfo[] actualTypeArguments, CtClass clazz, CtClass search, int parameter)
+   {
+      Stack<CtClass> hierarchy = new Stack<CtClass>();      
+      try
+      {
+         determineHierarchy(hierarchy, clazz, search);
+      }
+      catch (NotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+      return determineInfoIndex(actualTypeArguments, hierarchy, parameter);
+   }
+   
+   /**
+    * Determine the type of the parameter in the top-level class. 
+    * 
+    * @param hierarchy the hierarchy of classes as determined by {@link JavassistHelper#determineHierarchy(Stack, CtClass, CtClass)}
+    * @param parameter the index of the parameter
+    * @return the type
+    */
+   private static String determineType(Stack<CtClass> hierarchy, int parameter)
+   {
+      TypeDecider decider = new TypeDecider();
+      decider.determineType(hierarchy, parameter);
+      return decider.name;
+   }
+   
+   private static int determineInfoIndex(TypeInfo[] actualTypeArguments, Stack<CtClass> hierarchy, int parameter)
+   {
+      TypeDecider decider = new TypeDecider();
+      decider.determineType(hierarchy, parameter);
+      return decider.lastIndex;
+   }
+
+   /**
+    * Gets the ClassSignature for a class
+    * 
+    * @param clazz the CtClass
+    * @return the ClassSignature
+    */
+   static ClassSignature getClassSignature(CtClass clazz)
+   {
+      if (clazz == null)
+         throw new IllegalArgumentException("Null clazz");
+
+      SignatureAttribute signature = (SignatureAttribute)clazz.getClassFile().getAttribute(SignatureAttribute.tag);
+      if (signature == null)
+         return null;
+      String sig = signature.getSignature();
+   
+      try
+      {
+         return SignatureAttribute.toClassSignature(sig);
+      }
+      catch (BadBytecode e)
+      {
+         throw new IllegalStateException(e);
+      }
+   }
+
+   /**
+    * Figures out the path between the passed in classes
+    * 
+    * @param hierarchy receives the CtClasses that make up the hierarchy
+    * @param current the sub class
+    * @param search the parent class or interface we are searching for
+    * @throws IllegalArgumentException if any of the parameters are null
+    */
+   private static boolean determineHierarchy(Stack<CtClass> hierarchy, CtClass current, CtClass search) throws NotFoundException
+   {
+      if (hierarchy == null)
+         throw new IllegalArgumentException("Null hierarchy");
+      if (current == null)
+         throw new IllegalArgumentException("Null current");
+      if (search == null)
+         throw new IllegalArgumentException("Null search");
+   
+      if (current == null)
+         return false;
+      
+      hierarchy.push(current);
+      
+      if (current.equals(search))
+         return true;
+      
+      CtClass[] interfaces = current.getInterfaces();
+      if (search.isInterface() && interfaces != null)
+      {
+         for (int i = 0 ; i < interfaces.length ; i++)
+         {
+            boolean result = determineHierarchy(hierarchy, interfaces[i], search);
+            if (result)
+               return true;
+         }
+      }
+      
+      CtClass superClass = current.getSuperclass();
+      boolean result = determineHierarchy(hierarchy, superClass, search);
+      if (result)
+         return true;
+      
+      hierarchy.pop();
+      return false;
+   }
+   
+   /**
+    * Finds the TypeArgument used for the parent class/interface
+    * 
+    * @param parent the parent class or interface
+    * @param classSig the signature of the "current" class, i.e. the child of <code>parent</code>/
+    * @param index the index of the type parameter in the parent class
+    * @return the found TypeArgument
+    * @throws IllegalArgumentException if the index is greater than the length of TypeArguments found in the classSig, or if any of the parameters are null  
+    */
+   private static TypeArgument findSuperClassOrInterfaceArguments(CtClass parent, ClassSignature classSig, int index)
+   {
+      if (parent == null)
+         throw new IllegalArgumentException();
+      TypeArgument[] arguments = null; 
+      if (parent.isInterface())
+      {
+         ClassType[] types = classSig.getInterfaces();
+         for (int i = 0 ; i < types.length ; i++)
+         {
+            if (types[i].getName().equals(parent.getName()))
+            {
+               arguments = types[i].getTypeArguments();
+               break;
+            }
+         }
+         if (arguments == null)
+            throw new IllegalStateException("Could not find " + parent.getName() + " in " + Arrays.toString(types));
+      }
+      else
+      {
+         arguments =  classSig.getSuperClass().getTypeArguments();
+      }
+      
+      if (arguments.length <= index)
+         throw new IllegalArgumentException("Argument " + index + " requested, but only " + arguments.length + " exist");
+      return arguments[index];
+   }
+
+
+   private static class TypeDecider
+   {
+      int lastIndex;
+      CtClass last = null;
+      String name;
+      
+      private void determineType(Stack<CtClass> hierarchy, int parameter)
+      {
+         //TODO This should maybe return the full ObjectType instead
+         CtClass clazz = null;
+         
+         TypeParameter targetType = null;
+         lastIndex = parameter;
+         while (true)
+         {
+            if (hierarchy.empty())
+               break;
+            last = clazz;
+            clazz = hierarchy.pop();
+            
+            ClassSignature classSig = getClassSignature(clazz);
+            if (classSig != null)
+            {
+               TypeParameter[] typeParameters = classSig.getParameters();
+      
+               if (last == null)
+               {
+                  if (typeParameters.length <= parameter)
+                     throw new IllegalArgumentException("Parameter " + parameter + " requested, but only " + typeParameters.length + " exist.");
+                  targetType = typeParameters[parameter];
+               }
+               else
+               {
+                  TypeArgument argument = findSuperClassOrInterfaceArguments(last, classSig, lastIndex);
+                  ObjectType type = argument.getType();
+                  if (type == null)
+                     continue;
+                  if (type instanceof ClassType)
+                  {
+                     name = ((ClassType) type).getName();
+                     return;
+                  }
+                     
+                  String name = null; 
+                  if (type instanceof TypeVariable)
+                     name= ((TypeVariable)type).getName();
+
+                  for (int i = 0 ; i < typeParameters.length ; i++)
+                  {
+                     if (typeParameters[i].getName().equals(name))
+                     {
+                        lastIndex = i;
+                        targetType = typeParameters[i];
+                        break;
+                     }
+                  }
+               }
+            }
+            else
+            {
+               break;
+            }
+         }
+         if (targetType != null)
+         {
+            //TODO also check interfaces
+             name = ((ClassType)targetType.getClassBound()).getName();
+             return;
+         }
+      }
+   }
+}

Added: 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	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterizedClassInfo.java	2010-03-02 20:06:10 UTC (rev 101736)
@@ -0,0 +1,162 @@
+/*
+* 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.util.Collection;
+import java.util.Map;
+
+import javassist.CtClass;
+import javassist.bytecode.SignatureAttribute.ClassSignature;
+import javassist.bytecode.SignatureAttribute.TypeArgument;
+
+import org.jboss.reflect.plugins.ClassInfoImpl;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.DelegateClassInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavassistParameterizedClassInfo extends DelegateClassInfo
+{
+
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 2;
+   
+   /** The factory */
+   private final JavassistTypeInfoFactoryImpl factory;
+   
+   private final TypeArgument[] typeArguments;
+   
+   private volatile TypeInfo[] typeArgumentInfos = ClassInfoImpl.UNKNOWN_TYPES; 
+   
+   JavassistParameterizedClassInfo(JavassistTypeInfoFactoryImpl factory, ClassInfo delegate, TypeArgument[] typeArguments)
+   {
+      super(delegate);
+      this.factory = factory;
+      this.typeArguments = typeArguments;
+   }
+   
+   public JavassistParameterizedClassInfo(JavassistTypeInfoFactoryImpl factory, ClassInfo delegate, TypeInfo[] typeArgumentInfos)
+   {
+      this(factory, delegate, (TypeArgument[])null);
+      this.typeArgumentInfos = typeArgumentInfos;
+   }
+   
+   @Override
+   public TypeInfoFactory getTypeInfoFactory()
+   {
+      return factory;
+   }
+
+   @Override
+   public TypeInfo[] getActualTypeArguments()
+   {
+      if (typeArgumentInfos == ClassInfoImpl.UNKNOWN_TYPES && typeArguments.length > 0)
+      {
+         try
+         {
+            TypeInfo[] infos = new TypeInfo[typeArguments.length];
+            for (int i = 0 ; i < typeArguments.length ; i++)
+            {
+               infos[i] = (TypeInfo)factory.get(typeArguments[i].getType().toString(), delegate.getClassLoader());
+            }
+            typeArgumentInfos = infos;
+         }
+         catch (ClassNotFoundException e)
+         {
+            // AutoGenerated
+            throw new RuntimeException(e);
+         }
+      }
+         
+      return typeArgumentInfos;
+   }
+
+   @Override
+   public TypeInfo getComponentType()
+   {
+      return findTypeInfo(Collection.class.getName(), 0, CollectionTypeChecker.INSTANCE);
+   }
+
+   @Override
+   public TypeInfo getKeyType()
+   {
+      return findTypeInfo(Map.class.getName(), 0, MapTypeChecker.INSTANCE);
+   }
+
+   @Override
+   public TypeInfo getValueType()
+   {
+      return findTypeInfo(Map.class.getName(), 1, MapTypeChecker.INSTANCE);
+   }
+   
+   private TypeInfo findTypeInfo(String target, int parameter, TypeChecker checker)
+   {
+      ClassSignature sig = JavassistHelper.getClassSignature(((JavassistTypeInfo)delegate).getCtClass());
+      if (sig == null)
+         return delegate.getComponentType();
+      
+      if (!checker.check(this))
+         return null;
+
+      try
+      {
+         CtClass ctClass = ((JavassistTypeInfo)delegate).getCtClass();
+         CtClass collection = ctClass.getClassPool().get(target);
+         int index = JavassistHelper.determineInfoIndex(getActualTypeArguments(), ((JavassistTypeInfo)delegate).getCtClass(), collection, parameter);
+         return getActualTypeArguments()[index];
+      }
+      catch (Exception e1)
+      {
+         throw new RuntimeException(e1);
+      }
+   }
+
+   private static interface TypeChecker
+   {
+      boolean check(JavassistParameterizedClassInfo info);
+   }
+   
+   private static class MapTypeChecker implements TypeChecker
+   {
+      final static MapTypeChecker INSTANCE = new MapTypeChecker();
+
+      public boolean check(JavassistParameterizedClassInfo info)
+      {
+         return info.isMap();
+      }
+   }
+   
+   private static class CollectionTypeChecker implements TypeChecker
+   {
+      final static CollectionTypeChecker INSTANCE = new CollectionTypeChecker();
+
+      public boolean check(JavassistParameterizedClassInfo info)
+      {
+         return info.isCollection();
+      }
+   }
+}

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-03-02 18:28:00 UTC (rev 101735)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java	2010-03-02 20:06:10 UTC (rev 101736)
@@ -24,8 +24,12 @@
 import java.io.IOException;
 import java.lang.reflect.Array;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
 import java.util.Collection;
 import java.util.Map;
+import java.util.Stack;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javassist.CannotCompileException;
@@ -36,10 +40,14 @@
 import javassist.CtNewConstructor;
 import javassist.CtNewMethod;
 import javassist.NotFoundException;
+import javassist.bytecode.SignatureAttribute.ClassSignature;
+import javassist.bytecode.SignatureAttribute.ClassType;
 
+import org.jboss.reflect.plugins.ClassInfoImpl;
 import org.jboss.reflect.plugins.PackageInfoImpl;
 import org.jboss.reflect.plugins.TypeInfoAttachments;
 import org.jboss.reflect.plugins.ValueConvertor;
+import org.jboss.reflect.plugins.introspection.ParameterizedClassInfo;
 import org.jboss.reflect.spi.AnnotationValue;
 import org.jboss.reflect.spi.Body;
 import org.jboss.reflect.spi.ClassInfo;
@@ -53,6 +61,8 @@
 import org.jboss.reflect.spi.TypeInfoFactory;
 import org.jboss.util.JBossStringBuilder;
 
+import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
+
 /**
  * JavassistTypeInfo.
  * 
@@ -99,7 +109,22 @@
    
    /** The attachments */
    private transient TypeInfoAttachments attachments;
+   
+   /** The generic super class */
+   private volatile ClassInfo genericSuperClass = ClassInfoImpl.UNKNOWN_CLASS;
 
+   /** The generic interfaces */
+   private volatile InterfaceInfo[] genericInterfaces = ClassInfoImpl.UNKNOWN_INTERFACES;
+
+   /** The component type if this is a collection */
+   private volatile TypeInfo componentType = ClassInfoImpl.UNKNOWN_TYPE;
+   
+   /** The key type if this is a Map */
+   private volatile TypeInfo keyType = ClassInfoImpl.UNKNOWN_TYPE;
+   
+   /** The value type if this is a Map */
+   private volatile TypeInfo valueType = ClassInfoImpl.UNKNOWN_TYPE;
+   
    /**
     * Create a new JavassistTypeInfo.
     * 
@@ -202,8 +227,27 @@
 
    public ClassInfo getGenericSuperclass()
    {
-      // TODO JBREFLECT-5 getGenericSuperclass
-      throw new org.jboss.util.NotImplementedException("getGenericSuperclass");
+      if (genericSuperClass == ClassInfoImpl.UNKNOWN_CLASS)
+      {
+         ClassSignature classSig = JavassistHelper.getClassSignature(ctClass);
+
+         ClassType type = classSig.getSuperClass();
+         String name = type.getName();
+         //TypeArgument[] arguments = type.getTypeArguments();
+         
+         ClassInfo delegate;
+         try
+         {
+            delegate = (ClassInfo)factory.get(name, getClassLoader());
+         }
+         catch (ClassNotFoundException e)
+         {
+            throw new IllegalStateException(e);
+         }
+         genericSuperClass = new JavassistParameterizedClassInfo(factory, delegate, type.getTypeArguments()); 
+      }
+         
+      return genericSuperClass;   
    }
 
    public InterfaceInfo[] getInterfaces()
@@ -226,8 +270,31 @@
 
    public InterfaceInfo[] getGenericInterfaces()
    {
-      // TODO JBREFLECT-5 getGenericInterfaces
-      throw new org.jboss.util.NotImplementedException("getGenericInterfaces");
+      if (genericInterfaces == ClassInfoImpl.UNKNOWN_INTERFACES)
+      {
+         InterfaceInfo[] infos = new InterfaceInfo[getInterfaces().length];
+         
+         ClassSignature classSig = JavassistHelper.getClassSignature(ctClass);
+         ClassType[] types = classSig.getInterfaces();
+         for (int i = 0 ; i < types.length ; i++)
+         {
+            String name = types[i].getName();
+            
+            ClassInfo delegate;
+            try
+            {
+               delegate = (ClassInfo)factory.get(name, getClassLoader());
+            }
+            catch (ClassNotFoundException e)
+            {
+               throw new IllegalStateException(e);
+            }
+            infos[i] = new JavassistParameterizedClassInfo(factory, delegate, types[i].getTypeArguments());
+         }         
+         
+         genericInterfaces = infos;
+      }
+      return genericInterfaces;
    }
 
    public MutableConstructorInfo[] getDeclaredConstructors()
@@ -702,19 +769,54 @@
 
    public TypeInfo getComponentType()
    {
-      return null;
+      if (!isCollection())
+         return null;
+      
+      if (componentType == ClassInfoImpl.UNKNOWN_TYPE)
+      {
+         componentType = findTypeInfo(Collection.class.getName(), 0);
+      }
+      return componentType;
    }
 
    public TypeInfo getKeyType()
    {
-      return null;
+      if (!isMap())
+         return null;
+      
+      if (keyType == ClassInfoImpl.UNKNOWN_TYPE)
+      {
+         keyType = findTypeInfo(Map.class.getName(), 0);
+      }
+      return keyType;
    }
 
    public TypeInfo getValueType()
    {
-      return null;
+      if (!isMap())
+         return null;
+      
+      if (valueType == ClassInfoImpl.UNKNOWN_TYPE)
+      {
+         valueType = findTypeInfo(Map.class.getName(), 1);
+      }
+      return valueType;
    }
 
+   private TypeInfo findTypeInfo(String target, int parameter)
+   {
+      try
+      {
+         CtClass collection = ctClass.getClassPool().get(target);
+         String componentName = JavassistHelper.determineType(ctClass, collection, parameter);
+         return getTypeInfoFactory().getTypeInfo(componentName, getClassLoader());
+      }
+      catch (Exception e1)
+      {
+         throw new RuntimeException(e1);
+      }
+   }
+   
    public PackageInfo getPackage()
    {
       if (packageInfo == null)
@@ -768,7 +870,7 @@
       return attachments.getAttachment(attachmentName);
    }
    
-    CtClass getCtClass()
+   CtClass getCtClass()
    {
       return ctClass;
    }
@@ -1085,4 +1187,5 @@
          throw new org.jboss.reflect.spi.CannotCompileException(e.toString());
       }
    }
+
 }

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-02 18:28:00 UTC (rev 101735)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java	2010-03-02 20:06:10 UTC (rev 101736)
@@ -41,6 +41,7 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.ref.WeakReference;
+import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.Map;
 
@@ -505,11 +506,34 @@
    {
       if (type instanceof Class)
          return getTypeInfo((Class<?>) type);
+      else if (type instanceof ParameterizedType)
+         return getParameterizedType((ParameterizedType)type);
 
       // TODO JBREFLECT-5 getTypeInfo + NumberInfo
       throw new org.jboss.util.NotImplementedException("getTypeInfo");
    }
 
+   private TypeInfo getParameterizedType(ParameterizedType type)
+   {
+      Class<?> rawType = (Class<?>)type.getRawType();
+      ClassInfo raw = (ClassInfo)getTypeInfo(rawType);
+      Type[] types = type.getActualTypeArguments();
+      TypeInfo[] typeInfos = new TypeInfo[types.length];
+      for (int i = 0 ; i < typeInfos.length ; i++)
+      {
+         try
+         {
+//            if (types[i].)
+            typeInfos[i] = getTypeInfo(types[i]);
+         }
+         catch (Exception e)
+         {
+            throw new IllegalStateException(e);
+         }
+      }
+      return new JavassistParameterizedClassInfo(this, raw, typeInfos);
+   }
+   
    public AnnotationValue[] getAnnotations(Object obj)
    {
       try

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-03-02 18:28:00 UTC (rev 101735)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoTestSuite.java	2010-03-02 20:06:10 UTC (rev 101736)
@@ -59,7 +59,9 @@
       suite.addTest(IntrospectionAnnotatedClassInfoTestCase.suite());
       suite.addTest(JavassistAnnotatedClassInfoTestCase.suite());
       suite.addTest(IntrospectionGenericInterfaceUnitTestCase.suite());
+      suite.addTest(JavassistGenericInterfaceUnitTestCase.suite());
       suite.addTest(IntrospectionGenericClassUnitTestCase.suite());
+      suite.addTest(JavassistGenericClassUnitTestCase.suite());
       suite.addTest(FieldAccessRestrictionTestCase.suite());
       suite.addTest(MethodAccessRestrictionTestCase.suite());
 

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistGenericClassUnitTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistGenericClassUnitTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistGenericClassUnitTestCase.java	2010-03-02 20:06:10 UTC (rev 101736)
@@ -0,0 +1,57 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classinfo.test;
+
+import junit.framework.Test;
+
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.PackageInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * Javassist ClassInfo Test Case.
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 45663 $
+ */
+public class JavassistGenericClassUnitTestCase extends ClassInfoGenericClassTest
+{
+   public static Test suite()
+   {
+      return suite(JavassistGenericClassUnitTestCase.class);
+   }
+   
+   public JavassistGenericClassUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new JavassistTypeInfoFactory();
+   }
+
+   protected void assertPackageAnnotations(Package pkg, PackageInfo packageInfo) throws Throwable
+   {
+      // TODO JBREFLECT-1 this is broken for javassist
+   }
+}
\ No newline at end of file

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistGenericInterfaceUnitTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistGenericInterfaceUnitTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/JavassistGenericInterfaceUnitTestCase.java	2010-03-02 20:06:10 UTC (rev 101736)
@@ -0,0 +1,57 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.classinfo.test;
+
+import junit.framework.Test;
+
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.PackageInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * Javassist ClassInfo Test Case.
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 45663 $
+ */
+public class JavassistGenericInterfaceUnitTestCase extends ClassInfoGenericInterfaceTest
+{
+   public static Test suite()
+   {
+      return suite(JavassistGenericInterfaceUnitTestCase.class);
+   }
+   
+   public JavassistGenericInterfaceUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   protected TypeInfoFactory getTypeInfoFactory()
+   {
+      return new JavassistTypeInfoFactory();
+   }
+
+   protected void assertPackageAnnotations(Package pkg, PackageInfo packageInfo) throws Throwable
+   {
+      // TODO JBREFLECT-1 this is broken for javassist
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list