[jboss-cvs] JBossAS SVN: r104975 - in projects/jboss-reflect/trunk/src: test/java/org/jboss/test/plugins/javassist/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 19 05:33:27 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-05-19 05:33:27 -0400 (Wed, 19 May 2010)
New Revision: 104975
Modified:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java
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/JavassistMethodInfo.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/JavassistTypeVariableSpy.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/test/JavassistHelperTestCase.java
Log:
[JBREFLECT-124] Cache class and methos signatures so we don't have to keep parsing them
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java 2010-05-19 07:37:00 UTC (rev 104974)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java 2010-05-19 09:33:27 UTC (rev 104975)
@@ -28,6 +28,7 @@
import javassist.CtBehavior;
import javassist.CtClass;
import javassist.NotFoundException;
+import javassist.bytecode.SignatureAttribute.ClassSignature;
import javassist.bytecode.SignatureAttribute.MethodSignature;
import org.jboss.reflect.plugins.AnnotationHelper;
@@ -67,6 +68,10 @@
private transient volatile boolean initializedModifiers;
private transient volatile int modifiers;
+
+ private transient volatile boolean initializedMethodSignature;
+
+ private transient volatile MethodSignature methodSignature;
public JavassistAnnotatedParameterInfo(AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtBehavior ctBehavior)
{
@@ -133,7 +138,7 @@
try
{
- MethodSignature sig = JavassistHelper.getMethodSignature(ctBehavior);
+ MethodSignature sig = getMethodSignature();
if (sig != null && sig.getParameterTypes().length == ctBehavior.getParameterTypes().length)
{
parameterTypes = JavassistHelper.createParameterTypes(ctBehavior, sig, typeInfo);
@@ -279,4 +284,14 @@
typeInfo.clearMethodCache();
}
+ protected MethodSignature getMethodSignature()
+ {
+ if (!initializedMethodSignature)
+ {
+ methodSignature = JavassistHelper.getMethodSignature(ctBehavior);
+ initializedMethodSignature = true;
+ }
+ return methodSignature;
+ }
+
}
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java 2010-05-19 07:37:00 UTC (rev 104974)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java 2010-05-19 09:33:27 UTC (rev 104975)
@@ -121,7 +121,7 @@
return Modifier.isVolatile(getModifiers());
}
- public ClassInfo getDeclaringClass()
+ public JavassistTypeInfo getDeclaringClass()
{
return typeInfo;
}
@@ -135,7 +135,7 @@
ObjectType type = JavassistHelper.getFieldSignature(ctField);
if (type != null)
{
- ClassSignature sig = JavassistHelper.getClassSignature(ctField.getDeclaringClass());
+ ClassSignature sig = getDeclaringClass().getClassSignature();
fieldType = typeInfo.getFactory().getTypeInfo(typeInfo.getClassLoaderInternal(), type, JavassistTypeVariableSpy.createForField(sig));
}
else
Modified: 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 2010-05-19 07:37:00 UTC (rev 104974)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistHelper.java 2010-05-19 09:33:27 UTC (rev 104975)
@@ -43,6 +43,8 @@
import javassist.bytecode.SignatureAttribute.TypeParameter;
import javassist.bytecode.SignatureAttribute.TypeVariable;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.InterfaceInfo;
import org.jboss.reflect.spi.TypeInfo;
/**
@@ -61,9 +63,9 @@
* @param parameter the index of the type parameter we are looking for
* @return the generic type
*/
- static ClassType determineType(CtClass clazz, CtClass search, int parameter)
+ static ClassType determineType(ClassInfo clazz, ClassInfo search, int parameter)
{
- Stack<CtClass> hierarchy = new Stack<CtClass>();
+ Stack<ClassInfo> hierarchy = new Stack<ClassInfo>();
try
{
determineHierarchy(hierarchy, clazz, search);
@@ -73,7 +75,7 @@
throw new RuntimeException(e);
}
return determineType(hierarchy, parameter);
- }
+ }
/**
* Looking at the classes between clazz and search, determine the type of the type parameter with the passed in index
@@ -84,9 +86,9 @@
* @param parameter the index of the type parameter we are looking for
* @return the type
*/
- static TypeInfo determineInfoIndex(TypeInfo[] actualTypeArguments, CtClass clazz, CtClass search, int parameter)
+ static TypeInfo determineInfoIndex(TypeInfo[] actualTypeArguments, ClassInfo clazz, ClassInfo search, int parameter)
{
- Stack<CtClass> hierarchy = new Stack<CtClass>();
+ Stack<ClassInfo> hierarchy = new Stack<ClassInfo>();
try
{
determineHierarchy(hierarchy, clazz, search);
@@ -208,7 +210,7 @@
throw new IllegalArgumentException("Unhandled type " + type);
}
}
-
+
/**
* Determine the type of the parameter in the top-level class.
*
@@ -216,14 +218,14 @@
* @param parameter the index of the parameter
* @return the type
*/
- private static ClassType determineType(Stack<CtClass> hierarchy, int parameter)
+ private static ClassType determineType(Stack<ClassInfo> hierarchy, int parameter)
{
TypeDecider decider = new TypeDecider();
decider.determineType(hierarchy, parameter);
return decider.classType;
}
-
- private static int determineInfoIndex(TypeInfo[] actualTypeArguments, Stack<CtClass> hierarchy, int parameter)
+
+ private static int determineInfoIndex(TypeInfo[] actualTypeArguments, Stack<ClassInfo> hierarchy, int parameter)
{
TypeDecider decider = new TypeDecider();
decider.determineType(hierarchy, parameter);
@@ -268,17 +270,17 @@
* @param typeInfo the javassist type info
* @return the parameter types
*/
- public static TypeInfo[] createParameterTypes(final CtBehavior behavior, final MethodSignature sig, final JavassistTypeInfo typeInfo)
+ public static TypeInfo[] createParameterTypes(final CtBehavior behavior, final MethodSignature sig, final JavassistClassInfo typeInfo)
{
SignatureAttribute.Type[] types = sig.getParameterTypes();
TypeInfo[] parameterTypes = new TypeInfo[types.length];
for (int i = 0 ; i < types.length ; i++)
- parameterTypes[i] = typeInfo.getFactory().getTypeInfo(typeInfo.getClassLoaderInternal(), types[i], JavassistTypeVariableSpy.createForBehavior(behavior, sig));
+ parameterTypes[i] = typeInfo.getFactory().getTypeInfo(typeInfo.getClassLoaderInternal(), types[i], JavassistTypeVariableSpy.createForBehavior(typeInfo.getClassSignature(), sig));
return parameterTypes;
}
/**
- * Gets the ClassSignature for a method/constructor
+ * Gets the MethodSignature for a method/constructor
*
* @param behaviour the method/constructor
* @return the ClassSignature
@@ -334,30 +336,29 @@
/**
* Figures out the path between the passed in classes
*
- * @param hierarchy receives the CtClasses that make up the hierarchy. This parameter may be null, in which
+ * @param hierarchy receives the ClassInfos that make up the hierarchy. This parameter may be null, in which
* case is does not receive the classes
* @param current the sub class
* @param search the parent class or interface we are searching for
* @return true if the current inherits from search
* @throws IllegalArgumentException if current or search is null
*/
- public static boolean determineHierarchy(Stack<CtClass> hierarchy, CtClass current, CtClass search) throws NotFoundException
+ public static boolean determineHierarchy(Stack<ClassInfo> hierarchy, ClassInfo current, ClassInfo search) throws NotFoundException
{
if (current == null)
throw new IllegalArgumentException("Null current");
if (search == null)
throw new IllegalArgumentException("Null search");
-
+
if (hierarchy != null)
hierarchy.push(current);
-
if (current == null)
return false;
if (current.equals(search))
return true;
- CtClass[] interfaces = current.getInterfaces();
+ InterfaceInfo[] interfaces = current.getGenericInterfaces();
if (search.isInterface() && interfaces != null)
{
for (int i = 0 ; i < interfaces.length ; i++)
@@ -370,9 +371,9 @@
}
}
- CtClass superClass = current.getSuperclass();
+ ClassInfo superClass = current.getGenericSuperclass();
if (superClass == null)
- return false;
+ return false;
boolean result = determineHierarchy(hierarchy, superClass, search);
if (result)
@@ -392,7 +393,7 @@
* @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)
+ private static TypeArgument findSuperClassOrInterfaceArguments(ClassInfo parent, ClassSignature classSig, int index)
{
if (parent == null)
throw new IllegalArgumentException();
@@ -421,16 +422,22 @@
return arguments[index];
}
-
private static class TypeDecider
{
int lastIndex;
- CtClass last = null;
+ ClassInfo last = null;
ClassType classType;
- private void determineType(Stack<CtClass> hierarchy, int parameter)
+ private ClassSignature getClassSignature(ClassInfo info)
{
- CtClass clazz = null;
+ if (info instanceof JavassistClassInfo)
+ return ((JavassistClassInfo)info).getClassSignature();
+ return null;
+ }
+
+ private void determineType(Stack<ClassInfo> hierarchy, int parameter)
+ {
+ ClassInfo clazz = null;
TypeParameter targetType = null;
lastIndex = parameter;
@@ -442,48 +449,43 @@
clazz = hierarchy.pop();
ClassSignature classSig = getClassSignature(clazz);
- if (classSig != null)
+ if (classSig == null)
+ break;
+
+ TypeParameter[] typeParameters = classSig.getParameters();
+
+ if (last == 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)
{
- if (typeParameters.length <= parameter)
- throw new IllegalArgumentException("Parameter " + parameter + " requested, but only " + typeParameters.length + " exist.");
- targetType = typeParameters[parameter];
+ classType = (ClassType)type;
+ return;
}
- else
+
+ String name = null;
+ if (type instanceof TypeVariable)
+ name= ((TypeVariable)type).getName();
+
+ for (int i = 0 ; i < typeParameters.length ; i++)
{
- TypeArgument argument = findSuperClassOrInterfaceArguments(last, classSig, lastIndex);
- ObjectType type = argument.getType();
- if (type == null)
- continue;
- if (type instanceof ClassType)
+ if (typeParameters[i].getName().equals(name))
{
- //name = ((ClassType) type).getName();
- classType = (ClassType)type;
- return;
+ lastIndex = i;
+ targetType = typeParameters[i];
+ break;
}
-
- 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)
{
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java 2010-05-19 07:37:00 UTC (rev 104974)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java 2010-05-19 09:33:27 UTC (rev 104975)
@@ -95,11 +95,11 @@
try
{
CtMethod ctMethod = (CtMethod)ctBehavior;
- MethodSignature sig = JavassistHelper.getMethodSignature(ctMethod);
+ MethodSignature sig = getMethodSignature();
if (sig != null)
{
if (sig.getReturnType() instanceof BaseType == false)
- return typeInfo.getFactory().getTypeInfo(typeInfo.getClassLoaderInternal(), sig.getReturnType(), JavassistTypeVariableSpy.createForBehavior(ctMethod, sig));
+ return typeInfo.getFactory().getTypeInfo(typeInfo.getClassLoaderInternal(), sig.getReturnType(), JavassistTypeVariableSpy.createForBehavior(((JavassistClassInfo)getDeclaringClass()).getClassSignature(), sig));
}
CtClass clazz = ctMethod.getReturnType();
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-05-19 07:37:00 UTC (rev 104974)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterizedClassInfo.java 2010-05-19 09:33:27 UTC (rev 104975)
@@ -49,7 +49,7 @@
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @version $Revision: 1.1 $
*/
-public class JavassistParameterizedClassInfo extends DelegateClassInfo implements TypeVariableAware
+public class JavassistParameterizedClassInfo extends DelegateClassInfo implements TypeVariableAware, JavassistClassInfo
{
/** The serialVersionUID */
@@ -142,24 +142,24 @@
@Override
public TypeInfo getComponentType()
{
- return findTypeInfo(Collection.class.getName(), 0, CollectionTypeChecker.INSTANCE);
+ return findTypeInfo(JavassistTypeInfo.COLLECTION, 0, CollectionTypeChecker.INSTANCE);
}
@Override
public TypeInfo getKeyType()
{
- return findTypeInfo(Map.class.getName(), 0, MapTypeChecker.INSTANCE);
+ return findTypeInfo(JavassistTypeInfo.MAP, 0, MapTypeChecker.INSTANCE);
}
@Override
public TypeInfo getValueType()
{
- return findTypeInfo(Map.class.getName(), 1, MapTypeChecker.INSTANCE);
+ return findTypeInfo(JavassistTypeInfo.MAP, 1, MapTypeChecker.INSTANCE);
}
- private TypeInfo findTypeInfo(String target, int parameter, TypeChecker checker)
+ private TypeInfo findTypeInfo(ClassInfo target, int parameter, TypeChecker checker)
{
- ClassSignature sig = JavassistHelper.getClassSignature(((JavassistTypeInfo)delegate).getCtClass());
+ ClassSignature sig = getClassSignature();
if (sig == null)
return delegate.getComponentType();
@@ -168,9 +168,7 @@
try
{
- CtClass ctClass = ((JavassistTypeInfo)delegate).getCtClass();
- CtClass collection = ctClass.getClassPool().get(target);
- return JavassistHelper.determineInfoIndex(getActualTypeArguments(), ((JavassistTypeInfo)delegate).getCtClass(), collection, parameter);
+ return JavassistHelper.determineInfoIndex(getActualTypeArguments(), this, target, parameter);
}
catch (Exception e1)
{
@@ -363,4 +361,19 @@
return classLoader;
}
}
+
+ public ClassSignature getClassSignature()
+ {
+ return ((JavassistTypeInfo)delegate).getClassSignature();
+ }
+
+ public ClassLoader getClassLoaderInternal()
+ {
+ return ((JavassistClassInfo)delegate).getClassLoaderInternal();
+ }
+
+ public JavassistTypeInfoFactoryImpl getFactory()
+ {
+ return factory;
+ }
}
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-05-19 07:37:00 UTC (rev 104974)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java 2010-05-19 09:33:27 UTC (rev 104975)
@@ -68,13 +68,28 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision$
*/
-public class JavassistTypeInfo extends JavassistInheritableAnnotationHolder implements MutableClassInfo, InterfaceInfo
+public class JavassistTypeInfo extends JavassistInheritableAnnotationHolder implements MutableClassInfo, InterfaceInfo, JavassistClassInfo
{
/** The serialVersionUID */
private static final long serialVersionUID = -5072033691434335775L;
/** The get classloader permission */
protected static final RuntimePermission GET_CLASSLOADER_PERMISSION = new RuntimePermission("getClassLoader");
+
+ static final JavassistTypeInfo COLLECTION, MAP;
+ static
+ {
+ JavassistTypeInfoFactory factory = new JavassistTypeInfoFactory();
+ try
+ {
+ COLLECTION = (JavassistTypeInfo)factory.getTypeInfo(Collection.class);
+ MAP = (JavassistTypeInfo)factory.getTypeInfo(Map.class);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
/** The factory */
private JavassistTypeInfoFactoryImpl factory;
@@ -136,7 +151,11 @@
private transient volatile InterfaceInfo[] interfaces = ClassInfoImpl.UNKNOWN_INTERFACES;
+ private transient volatile boolean initializedClassSignature;
+
+ private transient volatile ClassSignature classSignature;
+
/**
* Create a new JavassistTypeInfo.
*
@@ -220,7 +239,7 @@
return getClassLoaderInternal();
}
- ClassLoader getClassLoaderInternal()
+ public ClassLoader getClassLoaderInternal()
{
return JavassistUtil.getClassLoader(ctClass);
}
@@ -254,9 +273,9 @@
{
if (genericSuperClass == ClassInfoImpl.UNKNOWN_CLASS)
{
- ClassSignature classSig = JavassistHelper.getClassSignature(ctClass);
+ ClassSignature classSig = getClassSignature();
- if (classSig != null)
+ if (getClassSignature() != null)
{
ClassType type = classSig.getSuperClass();
genericSuperClass = (ClassInfo)factory.getTypeInfo(getClassLoaderInternal(), type, JavassistTypeVariableSpy.createForClass(classSig));
@@ -303,7 +322,7 @@
{
InterfaceInfo[] infos = new InterfaceInfo[getInterfaces().length];
- ClassSignature classSig = JavassistHelper.getClassSignature(ctClass);
+ ClassSignature classSig = getClassSignature();
if (classSig != null)
{
@@ -503,7 +522,7 @@
{
try
{
- isCollection = JavassistHelper.determineHierarchy(null, ctClass, ctClass.getClassPool().get(Collection.class.getName()));
+ isCollection = JavassistHelper.determineHierarchy(null, this, COLLECTION);
}
catch (NotFoundException e)
{
@@ -519,7 +538,7 @@
{
try
{
- isMap = JavassistHelper.determineHierarchy(null, ctClass, ctClass.getClassPool().get(Map.class.getName()));
+ isMap = JavassistHelper.determineHierarchy(null, this, MAP);
}
catch (NotFoundException e)
{
@@ -528,7 +547,7 @@
}
return isMap;
}
-
+
public boolean isAnnotation()
{
return getCtClass().isAnnotation();
@@ -639,7 +658,7 @@
*
* @return the factory
*/
- protected JavassistTypeInfoFactoryImpl getFactory()
+ public JavassistTypeInfoFactoryImpl getFactory()
{
return factory;
}
@@ -850,7 +869,7 @@
if (componentType == ClassInfoImpl.UNKNOWN_TYPE)
{
- componentType = findTypeInfo(Collection.class.getName(), 0);
+ componentType = findTypeInfo(COLLECTION, 0);
}
return componentType;
}
@@ -862,7 +881,7 @@
if (keyType == ClassInfoImpl.UNKNOWN_TYPE)
{
- keyType = findTypeInfo(Map.class.getName(), 0);
+ keyType = findTypeInfo(MAP, 0);
}
return keyType;
}
@@ -874,19 +893,17 @@
if (valueType == ClassInfoImpl.UNKNOWN_TYPE)
{
- valueType = findTypeInfo(Map.class.getName(), 1);
+ valueType = findTypeInfo(MAP, 1);
}
return valueType;
}
- private TypeInfo findTypeInfo(String target, int parameter)
+ private TypeInfo findTypeInfo(ClassInfo iface, int parameter)
{
try
{
- CtClass collection = ctClass.getClassPool().get(target);
- ClassType type = JavassistHelper.determineType(ctClass, collection, parameter);
- ClassSignature sig = JavassistHelper.getClassSignature(ctClass);
- return factory.getTypeInfo(getClassLoaderInternal(), type, JavassistTypeVariableSpy.createForClass(sig));
+ ClassType type = JavassistHelper.determineType(this, iface, parameter);
+ return factory.getTypeInfo(getClassLoaderInternal(), type, JavassistTypeVariableSpy.createForClass(getClassSignature()));
}
catch (Exception e1)
{
@@ -1345,4 +1362,14 @@
{
return null;
}
+
+ public ClassSignature getClassSignature()
+ {
+ if (!initializedClassSignature)
+ {
+ classSignature = JavassistHelper.getClassSignature(getCtClass());
+ initializedClassSignature = true;
+ }
+ return classSignature;
+ }
}
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeVariableSpy.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeVariableSpy.java 2010-05-19 07:37:00 UTC (rev 104974)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeVariableSpy.java 2010-05-19 09:33:27 UTC (rev 104975)
@@ -41,13 +41,13 @@
/**
* Create a JavassistTypeVariableSpy for a method or constructor
*
- * @param behavior the CtBehavior of the method or constructor
+ * @param classSig the signature of the declaring class
* @param sig the method signature
* @return the JavassistTypeVariableSpy
*/
- static JavassistTypeVariableSpy createForBehavior(CtBehavior behavior, MethodSignature sig)
+ static JavassistTypeVariableSpy createForBehavior(ClassSignature classSig, MethodSignature sig)
{
- return new MethodTypeVariable(behavior.getDeclaringClass(), sig);
+ return new MethodTypeVariable(classSig, sig);
}
/**
@@ -107,12 +107,12 @@
private static class MethodTypeVariable extends JavassistTypeVariableSpy
{
- protected final CtClass clazz;
+ protected final ClassSignature classSig;
private final MethodSignature sig;
- MethodTypeVariable(CtClass clazz, MethodSignature sig)
+ MethodTypeVariable(ClassSignature classSig, MethodSignature sig)
{
- this.clazz = clazz;
+ this.classSig = classSig;
this.sig = sig;
}
@@ -123,7 +123,6 @@
if (type != null)
return type;
- ClassSignature classSig = JavassistHelper.getClassSignature(clazz);
type = getTypeFromTypeParameters(tv, classSig.getParameters());
if (type != null)
return type;
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/test/JavassistHelperTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/test/JavassistHelperTestCase.java 2010-05-19 07:37:00 UTC (rev 104974)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/test/JavassistHelperTestCase.java 2010-05-19 09:33:27 UTC (rev 104975)
@@ -34,6 +34,10 @@
import junit.framework.Test;
import org.jboss.reflect.plugins.javassist.JavassistHelper;
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfo;
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.TypeInfo;
import org.jboss.test.AbstractTestDelegate;
import org.jboss.test.ContainerTest;
import org.jboss.test.plugins.javassist.support.Interface;
@@ -47,6 +51,8 @@
*/
public class JavassistHelperTestCase extends ContainerTest
{
+ JavassistTypeInfoFactory factory = new JavassistTypeInfoFactory();
+
public JavassistHelperTestCase(String name)
{
super(name);
@@ -57,72 +63,72 @@
return suite(JavassistHelperTestCase.class);
}
- public void testClassExtendsClass() throws Exception
+ public void testClassExtendsClass() throws Throwable
{
- CtClass object = loadCtClass(Object.class);
- CtClass number = loadCtClass(Number.class);
- CtClass lng = loadCtClass(Long.class);
+ JavassistTypeInfo object = loadJavassistClassInfo(Object.class);
+ JavassistTypeInfo number = loadJavassistClassInfo(Number.class);
+ ClassInfo lng = loadClassInfo(Long.class);
assertTrue(JavassistHelper.determineHierarchy(null, lng, number));
assertTrue(JavassistHelper.determineHierarchy(null, lng, object));
assertTrue(JavassistHelper.determineHierarchy(null, number, object));
}
- public void testDetermineHierarchyClassImplementsInterfaceDirectly() throws Exception
+ public void testDetermineHierarchyClassImplementsInterfaceDirectly() throws Throwable
{
- CtClass number = loadCtClass(Number.class);
- CtClass seri = loadCtClass(Serializable.class);
+ JavassistTypeInfo number = loadJavassistClassInfo(Number.class);
+ JavassistTypeInfo seri = loadJavassistClassInfo(Serializable.class);
assertTrue(JavassistHelper.determineHierarchy(null, number, seri));
}
- public void testDetermineHierarchyClassImplementsInterfaceViaSuperclass() throws Exception
+ public void testDetermineHierarchyClassImplementsInterfaceViaSuperclass() throws Throwable
{
- CtClass numberChild = loadCtClass(NumberChild.class);
- CtClass seri = loadCtClass(Serializable.class);
+ JavassistTypeInfo numberChild = loadJavassistClassInfo(NumberChild.class);
+ JavassistTypeInfo seri = loadJavassistClassInfo(Serializable.class);
assertTrue(JavassistHelper.determineHierarchy(null, numberChild, seri));
}
- public void testDetermineHierarchyClassDoesNotExtendSuperclass() throws Exception
+ public void testDetermineHierarchyClassDoesNotExtendSuperclass() throws Throwable
{
- CtClass numberChild = loadCtClass(NumberChild.class);
- CtClass seri = loadCtClass(String.class);
+ JavassistTypeInfo numberChild = loadJavassistClassInfo(NumberChild.class);
+ JavassistTypeInfo seri = loadJavassistClassInfo(String.class);
assertFalse(JavassistHelper.determineHierarchy(null, numberChild, seri));
}
- public void testDetermineHierarchyClassDoesNotExtendInterface() throws Exception
+ public void testDetermineHierarchyClassDoesNotExtendInterface() throws Throwable
{
- CtClass numberChild = loadCtClass(NumberChild.class);
- CtClass collection = loadCtClass(Collection.class);
+ JavassistTypeInfo numberChild = loadJavassistClassInfo(NumberChild.class);
+ JavassistTypeInfo collection = loadJavassistClassInfo(Collection.class);
assertFalse(JavassistHelper.determineHierarchy(null, numberChild, collection));
}
- public void testClassSignatureNormalClass() throws Exception
+ public void testClassSignatureNormalClass() throws Throwable
{
- CtClass coll = loadCtClass(StringCollection.class);
- ClassSignature sig = JavassistHelper.getClassSignature(coll);
+ JavassistTypeInfo coll = loadJavassistClassInfo(StringCollection.class);
+ ClassSignature sig = coll.getClassSignature();
assertNotNull(sig);
}
- public void testClassSignatureArrayClass() throws Exception
+ public void testClassSignatureArrayClass() throws Throwable
{
- CtClass collArray = ClassPool.getDefault().get(StringCollection.class.getName() + "[]");
- ClassSignature sig = JavassistHelper.getClassSignature(collArray);
+ JavassistTypeInfo coll = loadJavassistClassInfo(StringCollection[].class);
+ ClassSignature sig = coll.getClassSignature();
assertNull(sig);
}
- public void testClassSignaturePrimitive() throws Exception
+ public void testClassSignaturePrimitive() throws Throwable
{
- ClassSignature sig = JavassistHelper.getClassSignature(CtPrimitiveType.booleanType);
- assertNull(sig);
+ TypeInfo info = factory.getTypeInfo(Boolean.TYPE);
+ assertFalse(info instanceof ClassInfo);
}
- public void testClassSignatureFrozenClass() throws Exception
+ public void testClassSignatureFrozenClass() throws Throwable
{
CtClass clazz = ClassPool.getDefault().makeClass(Interface.class.getName() + "Impl");
- clazz.addInterface(loadCtClass(Interface.class));
+ clazz.addInterface(ClassPool.getDefault().get(Interface.class.getName()));
clazz.getClassFile().addAttribute(new SignatureAttribute(clazz.getClassFile().getConstPool(), "Ljava/lang/Object;Lorg/jboss/test/plugins/javassist/support/Interface<Ljava/lang/String;>;"));
AbstractTestDelegate delegate = getDelegate();
@@ -148,10 +154,15 @@
assertNotNull(sig);
}
- private CtClass loadCtClass(Class<?> clazz) throws NotFoundException
+ private ClassInfo loadClassInfo(Class<?> clazz)
{
- return ClassPool.getDefault().get(clazz.getName());
+ TypeInfo info = factory.getTypeInfo(clazz);
+ return assertInstanceOf(info, ClassInfo.class);
}
-
+ private JavassistTypeInfo loadJavassistClassInfo(Class<?> clazz) throws Throwable
+ {
+ TypeInfo info = factory.getTypeInfo(clazz);
+ return assertInstanceOf(info, JavassistTypeInfo.class);
+ }
}
More information about the jboss-cvs-commits
mailing list