[jboss-cvs] JBossAS SVN: r110311 - 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 Jan 10 08:48:10 EST 2011
Author: alesj
Date: 2011-01-10 08:48:09 -0500 (Mon, 10 Jan 2011)
New Revision: 110311
Added:
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/Obligation.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/UML.java
Modified:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfoFactoryImpl.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/AnnotatedClassInfoTest.java
Log:
[JBREFLECT-139]; fix cycle instantiation
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfoFactoryImpl.java 2011-01-10 13:39:59 UTC (rev 110310)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfoFactoryImpl.java 2011-01-10 13:48:09 UTC (rev 110311)
@@ -31,24 +31,11 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javassist.bytecode.Descriptor;
-import javassist.bytecode.SignatureAttribute;
-import javassist.bytecode.SignatureAttribute.ArrayType;
-import javassist.bytecode.SignatureAttribute.BaseType;
-import javassist.bytecode.SignatureAttribute.ClassType;
-import javassist.bytecode.SignatureAttribute.ObjectType;
-import javassist.bytecode.SignatureAttribute.TypeArgument;
-
-import org.jboss.reflect.plugins.AnnotationAttributeImpl;
-import org.jboss.reflect.plugins.AnnotationHelper;
-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.TypeVariableAware;
+import org.jboss.reflect.plugins.*;
import org.jboss.reflect.plugins.bytecode.bytes.BytecodePrimitive;
import org.jboss.reflect.plugins.bytecode.bytes.ClassBytes;
import org.jboss.reflect.plugins.bytecode.bytes.ClassBytesFactory;
@@ -57,22 +44,23 @@
import org.jboss.reflect.plugins.bytecode.bytes.MethodBytes;
import org.jboss.reflect.plugins.bytecode.bytes.asm.AsmClassBytesFactory;
import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
-import org.jboss.reflect.spi.AnnotationInfo;
-import org.jboss.reflect.spi.AnnotationValue;
-import org.jboss.reflect.spi.ArrayInfo;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.DelegateClassInfo;
-import org.jboss.reflect.spi.NumberInfo;
-import org.jboss.reflect.spi.PrimitiveInfo;
-import org.jboss.reflect.spi.TypeInfo;
-import org.jboss.reflect.spi.TypeInfoFactory;
+import org.jboss.reflect.spi.*;
import org.jboss.util.collection.WeakClassCache;
+import javassist.bytecode.Descriptor;
+import javassist.bytecode.SignatureAttribute;
+import javassist.bytecode.SignatureAttribute.ArrayType;
+import javassist.bytecode.SignatureAttribute.BaseType;
+import javassist.bytecode.SignatureAttribute.ClassType;
+import javassist.bytecode.SignatureAttribute.ObjectType;
+import javassist.bytecode.SignatureAttribute.TypeArgument;
+
/**
- * A javassist type factory.
+ * A bytecode type factory.
* TODO: need to fix the cl stuff
*
- * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*
* @version $Revision: 105101 $
*/
@@ -80,6 +68,9 @@
{
private final ClassBytesFactory classBytesFactory = AsmClassBytesFactory.INSTANCE;
+ /** Tmp invocation results */
+ private static ThreadLocal<Map<ClassBytes, TypeInfo>> results = new ThreadLocal<Map<ClassBytes, TypeInfo>>();
+
private volatile ClassLoaderFinder finder;
public BytecodeTypeInfoFactoryImpl()
@@ -141,59 +132,92 @@
protected TypeInfo instantiate(String name, ClassBytes classBytes, Class<?> clazz)
{
- if (classBytes.getComponentType() != null)
+ boolean start = false;
+ Map<ClassBytes, TypeInfo> tmp = results.get();
+ if (tmp == null)
{
- try
- {
- TypeInfo componentType = getTypeInfo(classBytes.getComponentType().getTypeInfoName(), classBytes.getClassLoader());
- //TypeInfo componentType = getTypeInfo(classBytes.getComponentType());
- return new BytecodeArrayInfoImpl(this, classBytes, clazz, componentType);
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException(e);
- }
+ start = true;
+ tmp = new HashMap<ClassBytes, TypeInfo>();
+ results.set(tmp);
}
- //TODO handle arrays
- if (classBytes.isAnnotation())
+ // if we return here, it means we're already in a loop,
+ // hence no need to cleanup
+ TypeInfo cached = tmp.get(classBytes);
+ if (cached != null)
+ return cached;
+
+ try
{
- BytecodeAnnotationInfo result = new BytecodeAnnotationInfo(this, name, classBytes, clazz);
- MethodBytes[] methods = classBytes.getDeclaredMethodBytes();
- AnnotationAttributeImpl[] atttributes = new AnnotationAttributeImpl[methods.length];
- for (int i = 0 ; i < methods.length ; i++)
+ if (classBytes.getComponentType() != null)
{
try
{
- atttributes[i] = new AnnotationAttributeImpl(methods[i].getName(), getTypeInfo(BytecodeSignatureKey.getReturnType(methods[i]), classBytes.getClassLoader()), null);
+ TypeInfo componentType = getTypeInfo(classBytes.getComponentType().getTypeInfoName(), classBytes.getClassLoader());
+ BytecodeArrayInfoImpl arrayInfo = new BytecodeArrayInfoImpl(this, classBytes, clazz, componentType);
+ tmp.put(classBytes, arrayInfo);
+ return arrayInfo;
}
catch (ClassNotFoundException e)
{
- throw new RuntimeException("Error reading attribute " + methods[i].getName() + " for " + classBytes.getJvmName());
+ throw new RuntimeException(e);
}
}
- result.setAttributes(atttributes);
- return result;
+ //TODO handle arrays
+ else if (classBytes.isAnnotation())
+ {
+ BytecodeAnnotationInfo result = new BytecodeAnnotationInfo(this, name, classBytes, clazz);
+ tmp.put(classBytes, result);
- }
- else if (classBytes.isEnum())
- {
- BytecodeEnumInfo enumInfo = new BytecodeEnumInfo(this, name, classBytes, clazz);
- FieldBytes[] fields = classBytes.getDeclaredFieldBytes();
- List<EnumConstantInfoImpl> constants = new ArrayList<EnumConstantInfoImpl>();
- for (FieldBytes field : fields)
+ MethodBytes[] methods = classBytes.getDeclaredMethodBytes();
+ AnnotationAttributeImpl[] atttributes = new AnnotationAttributeImpl[methods.length];
+ for (int i = 0 ; i < methods.length ; i++)
+ {
+ try
+ {
+ atttributes[i] = new AnnotationAttributeImpl(methods[i].getName(), getTypeInfo(BytecodeSignatureKey.getReturnType(methods[i]), classBytes.getClassLoader()), null);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Error reading attribute " + methods[i].getName() + " for " + classBytes.getJvmName());
+ }
+ }
+ result.setAttributes(atttributes);
+
+ return result;
+
+ }
+ else if (classBytes.isEnum())
{
- if (field.isEnumConstant())
+ BytecodeEnumInfo enumInfo = new BytecodeEnumInfo(this, name, classBytes, clazz);
+ tmp.put(classBytes, enumInfo);
+
+ FieldBytes[] fields = classBytes.getDeclaredFieldBytes();
+ List<EnumConstantInfoImpl> constants = new ArrayList<EnumConstantInfoImpl>();
+ for (FieldBytes field : fields)
{
- AnnotationValue[] annotations = getAnnotations(field);
- constants.add(new EnumConstantInfoImpl(field.getName(), enumInfo, annotations));
+ if (field.isEnumConstant())
+ {
+ AnnotationValue[] annotations = getAnnotations(field);
+ constants.add(new EnumConstantInfoImpl(field.getName(), enumInfo, annotations));
+ }
}
+ enumInfo.setEnumConstants(constants.toArray(new EnumConstantInfoImpl[constants.size()]));
+
+ return enumInfo;
}
- enumInfo.setEnumConstants(constants.toArray(new EnumConstantInfoImpl[constants.size()]));
- return enumInfo;
+ else
+ {
+ BytecodeTypeInfo typeInfo = new BytecodeTypeInfo(this, name, classBytes, clazz);
+ tmp.put(classBytes, typeInfo);
+ return typeInfo;
+ }
}
-
- return new BytecodeTypeInfo(this, name, classBytes, clazz);
+ finally
+ {
+ if (start)
+ results.remove();
+ }
}
@@ -216,7 +240,7 @@
/**
* Gets the type info for a class
*
- * @param type the type
+ * @param name the type
* @return the type info
*/
public TypeInfo getTypeInfo(String name, ClassLoader cl) throws ClassNotFoundException
@@ -588,7 +612,6 @@
* Gets the type info for a javassist generic class type
*
* @param loader the class loader of the raw class
- * @param parameterloaders the class of the
* @param type the class type
* @param spy used to determine actual types of type variables
* @return the type info
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 2011-01-10 13:39:59 UTC (rev 110310)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/introspection/IntrospectionTypeInfoFactoryImpl.java 2011-01-10 13:48:09 UTC (rev 110311)
@@ -22,61 +22,34 @@
package org.jboss.reflect.plugins.introspection;
import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.GenericArrayType;
-import java.lang.reflect.GenericDeclaration;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
-import java.lang.reflect.WildcardType;
+import java.lang.reflect.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.jboss.reflect.plugins.AnnotationAttributeImpl;
-import org.jboss.reflect.plugins.AnnotationHelper;
-import org.jboss.reflect.plugins.AnnotationInfoImpl;
-import org.jboss.reflect.plugins.AnnotationValueFactory;
-import org.jboss.reflect.plugins.ArrayInfoImpl;
-import org.jboss.reflect.plugins.ClassInfoHelper;
-import org.jboss.reflect.plugins.ClassInfoImpl;
-import org.jboss.reflect.plugins.ConstructorInfoImpl;
-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.TypeVariableAware;
-import org.jboss.reflect.spi.AnnotationInfo;
-import org.jboss.reflect.spi.AnnotationValue;
-import org.jboss.reflect.spi.ArrayInfo;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.InterfaceInfo;
-import org.jboss.reflect.spi.NumberInfo;
-import org.jboss.reflect.spi.PrimitiveInfo;
-import org.jboss.reflect.spi.TypeInfo;
-import org.jboss.reflect.spi.TypeInfoFactory;
+import org.jboss.reflect.plugins.*;
+import org.jboss.reflect.spi.*;
import org.jboss.util.collection.WeakTypeCache;
/**
* An introspection type factory.
*
* @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
public class IntrospectionTypeInfoFactoryImpl extends WeakTypeCache<TypeInfo> implements TypeInfoFactory, AnnotationHelper, ClassInfoHelper
{
final static AnnotationValue[] NO_ANNOTATIONS = new AnnotationValue[0];
+ /** Tmp invocation results */
+ private static ThreadLocal<Map<Class<?>, TypeInfo>> results = new ThreadLocal<Map<Class<?>, TypeInfo>>();
+
IntrospectionTypeInfoFactoryImpl()
{
}
@@ -465,52 +438,93 @@
@Override
protected TypeInfo instantiate(Class<?> clazz)
{
- ClassInfoImpl result;
- if (clazz.isArray())
+ boolean start = false;
+ Map<Class<?>, TypeInfo> tmp = results.get();
+ if (tmp == null)
{
- TypeInfo componentType = getTypeInfo(clazz.getComponentType());
- result = new ArrayInfoImpl(componentType);
+ start = true;
+ tmp = new HashMap<Class<?>, TypeInfo>();
+ results.set(tmp);
}
- else if (clazz.isEnum())
+
+ // if we return here, it means we're already in a loop,
+ // hence no need to cleanup
+ TypeInfo cached = tmp.get(clazz);
+ if (cached != null)
+ return cached;
+
+ try
{
- EnumInfoImpl enumInfoImpl = new EnumInfoImpl(clazz.getName(), clazz.getModifiers());
- result = enumInfoImpl;
- Field[] fields = clazz.getFields();
-
- List<EnumConstantInfoImpl> constants = new ArrayList<EnumConstantInfoImpl>();
- for (Field field : fields)
+ ClassInfoImpl result;
+ if (clazz.isArray())
{
- if (field.isEnumConstant())
+ TypeInfo componentType = getTypeInfo(clazz.getComponentType());
+ result = new ArrayInfoImpl(componentType);
+ init(result, clazz);
+ }
+ else if (clazz.isEnum())
+ {
+ EnumInfoImpl enumInfoImpl = new EnumInfoImpl(clazz.getName(), clazz.getModifiers());
+ result = enumInfoImpl;
+ init(result, clazz);
+
+ Field[] fields = clazz.getFields();
+ List<EnumConstantInfoImpl> constants = new ArrayList<EnumConstantInfoImpl>();
+ for (Field field : fields)
{
- AnnotationValue[] annotations = getAnnotations(field);
- constants.add(new EnumConstantInfoImpl(field.getName(), enumInfoImpl, annotations));
+ if (field.isEnumConstant())
+ {
+ AnnotationValue[] annotations = getAnnotations(field);
+ constants.add(new EnumConstantInfoImpl(field.getName(), enumInfoImpl, annotations));
+ }
}
+ enumInfoImpl.setEnumConstants(constants.toArray(new EnumConstantInfoImpl[constants.size()]));
}
- enumInfoImpl.setEnumConstants(constants.toArray(new EnumConstantInfoImpl[constants.size()]));
- }
- else if (clazz.isAnnotation())
- {
- result = new AnnotationInfoImpl(clazz.getName(), clazz.getModifiers());
- Method[] methods = getDeclaredMethods(clazz);
- AnnotationAttributeImpl[] atttributes = new AnnotationAttributeImpl[methods.length];
- for (int i = 0 ; i < methods.length ; i++)
+ else if (clazz.isAnnotation())
{
- atttributes[i] = new AnnotationAttributeImpl(methods[i].getName(), getTypeInfo(methods[i].getReturnType()), null);
+ result = new AnnotationInfoImpl(clazz.getName(), clazz.getModifiers());
+ init(result, clazz);
+
+ Method[] methods = getDeclaredMethods(clazz);
+ AnnotationAttributeImpl[] atttributes = new AnnotationAttributeImpl[methods.length];
+ for (int i = 0 ; i < methods.length ; i++)
+ {
+ atttributes[i] = new AnnotationAttributeImpl(methods[i].getName(), getTypeInfo(methods[i].getReturnType()), null);
+ }
+ ((AnnotationInfoImpl)result).setAttributes(atttributes);
}
- ((AnnotationInfoImpl)result).setAttributes(atttributes);
+ else
+ {
+ result = new ReflectClassInfoImpl(clazz.getName());
+ init(result, clazz);
+ }
+
+ return result;
}
- else
+ finally
{
- result = new ReflectClassInfoImpl(clazz.getName());
+ if (start)
+ results.remove();
}
+ }
+
+ /**
+ * Initialize default configuration.
+ *
+ * @param result the result
+ * @param clazz the class
+ */
+ private void init(ClassInfoImpl result, Class<?> clazz)
+ {
+ Map<Class<?>, TypeInfo> tmp = results.get();
+ tmp.put(clazz, result);
+
result.setType(clazz);
result.setTypeInfoFactory(this);
result.setClassInfoHelper(this);
result.setAnnotationHelper(this);
- return result;
}
-
/**
* Overrides the {@link WeakTypeCache#getParameterizedType(ParameterizedType)}
* method so that parameterized types are not cached when getTypeInfo(Type) is called
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 2011-01-10 13:39:59 UTC (rev 110310)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java 2011-01-10 13:48:09 UTC (rev 110311)
@@ -31,16 +31,19 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtField;
-import javassist.CtMember;
-import javassist.CtMethod;
-import javassist.CtPrimitiveType;
-import javassist.Modifier;
+import org.jboss.reflect.plugins.*;
+import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
+import org.jboss.reflect.plugins.javassist.classpool.ClassPoolFactory;
+import org.jboss.reflect.plugins.javassist.classpool.DefaultClassPoolFactory;
+import org.jboss.reflect.spi.*;
+import org.jboss.util.JBossStringBuilder;
+import org.jboss.util.collection.WeakClassCache;
+
+import javassist.*;
import javassist.NotFoundException;
import javassist.bytecode.Descriptor;
import javassist.bytecode.SignatureAttribute;
@@ -50,34 +53,12 @@
import javassist.bytecode.SignatureAttribute.ObjectType;
import javassist.bytecode.SignatureAttribute.TypeArgument;
-import org.jboss.reflect.plugins.AnnotationAttributeImpl;
-import org.jboss.reflect.plugins.AnnotationHelper;
-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.TypeVariableAware;
-import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
-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.ArrayInfo;
-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;
-import org.jboss.reflect.spi.PrimitiveInfo;
-import org.jboss.reflect.spi.TypeInfo;
-import org.jboss.util.JBossStringBuilder;
-import org.jboss.util.collection.WeakClassCache;
-
/**
* A javassist type factory.
* TODO: need to fix the cl stuff
*
* @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*
* @version $Revision$
*/
@@ -85,6 +66,9 @@
{
private static ClassPoolFactory poolFactory = DefaultClassPoolFactory.getInstance();
+ /** Tmp invocation results */
+ private static ThreadLocal<Map<CtClass, TypeInfo>> results = new ThreadLocal<Map<CtClass, TypeInfo>>();
+
JavassistTypeInfoFactoryImpl()
{
}
@@ -173,17 +157,35 @@
protected TypeInfo instantiate(CtClass ctClass, Class<?> clazz)
{
+ boolean start = false;
+ Map<CtClass, TypeInfo> tmp = results.get();
+ if (tmp == null)
+ {
+ start = true;
+ tmp = new HashMap<CtClass, TypeInfo>();
+ results.set(tmp);
+ }
+
+ // if we return here, it means we're already in a loop,
+ // hence no need to cleanup
+ TypeInfo cached = tmp.get(ctClass);
+ if (cached != null)
+ return cached;
+
try
{
if (ctClass.isArray())
{
TypeInfo componentType = getTypeInfo(ctClass.getComponentType());
- return new JavassistArrayInfoImpl(this, ctClass, clazz, componentType);
+ TypeInfo result = new JavassistArrayInfoImpl(this, ctClass, clazz, componentType);
+ tmp.put(ctClass, result);
+ return result;
}
-
- if (ctClass.isAnnotation())
+ else if (ctClass.isAnnotation())
{
JavassistAnnotationInfo result = new JavassistAnnotationInfo(this, ctClass, clazz);
+ tmp.put(ctClass, result);
+
CtMethod[] methods = ctClass.getDeclaredMethods();
AnnotationAttributeImpl[] atttributes = new AnnotationAttributeImpl[methods.length];
for (int i = 0 ; i < methods.length ; i++)
@@ -191,12 +193,14 @@
atttributes[i] = new AnnotationAttributeImpl(methods[i].getName(), getTypeInfo(methods[i].getReturnType()), null);
}
result.setAttributes(atttributes);
+
return result;
-
}
else if (ctClass.isEnum())
{
JavassistEnumInfo enumInfo = new JavassistEnumInfo(this, ctClass, clazz);
+ tmp.put(ctClass, enumInfo);
+
CtField[] fields = ctClass.getFields();
List<EnumConstantInfoImpl> constants = new ArrayList<EnumConstantInfoImpl>();
for (CtField field : fields)
@@ -208,15 +212,25 @@
}
}
enumInfo.setEnumConstants(constants.toArray(new EnumConstantInfoImpl[constants.size()]));
+
return enumInfo;
}
-
- return new JavassistTypeInfo(this, ctClass, clazz);
+ else
+ {
+ TypeInfo result = new JavassistTypeInfo(this, ctClass, clazz);
+ tmp.put(ctClass, result);
+ return result;
+ }
}
catch (NotFoundException e)
{
throw new RuntimeException(e);
}
+ finally
+ {
+ if (start)
+ results.remove();
+ }
}
/**
@@ -328,7 +342,7 @@
/**
* Gets the type info for a class
*
- * @param type the type
+ * @param name the type
* @return the type info
*/
public TypeInfo getTypeInfo(String name, ClassLoader cl) throws ClassNotFoundException
@@ -424,7 +438,6 @@
* Get the information for a class
*
* @param ctClass the class
- * @param clazz the class
* @return the info
*/
protected TypeInfo get(CtClass ctClass)
@@ -799,7 +812,6 @@
* Gets the type info for a javassist generic class type
*
* @param loader the class loader of the raw class
- * @param parameterloaders the class of the
* @param type the class type
* @param spy used to determine actual types of type variables
* @return the type info
Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/Obligation.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/Obligation.java (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/Obligation.java 2011-01-10 13:48:09 UTC (rev 110311)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.test.classinfo.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+ at UML(identifier="MD_ObligationCode")
+public enum Obligation
+{
+ CONDITIONAL,
+ @UML(identifier="optional", obligation=CONDITIONAL)
+ OPTIONAL,
+ @UML(identifier="mandatory", obligation=CONDITIONAL)
+ MANDATORY,
+ FORBIDDEN
+}
Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/UML.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/UML.java (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/support/UML.java 2011-01-10 13:48:09 UTC (rev 110311)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.test.classinfo.support;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+ at Documented
+ at Retention(RUNTIME)
+ at Target({TYPE, FIELD, METHOD})
+public @interface UML
+{
+ String identifier();
+
+ Obligation obligation() default Obligation.MANDATORY;
+}
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/AnnotatedClassInfoTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/AnnotatedClassInfoTest.java 2011-01-10 13:39:59 UTC (rev 110310)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/AnnotatedClassInfoTest.java 2011-01-10 13:48:09 UTC (rev 110311)
@@ -25,49 +25,15 @@
import java.lang.annotation.Documented;
import java.util.HashSet;
-import org.jboss.reflect.spi.AnnotatedInfo;
-import org.jboss.reflect.spi.AnnotationInfo;
-import org.jboss.reflect.spi.AnnotationValue;
-import org.jboss.reflect.spi.ArrayInfo;
-import org.jboss.reflect.spi.ArrayValue;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.ClassValue;
-import org.jboss.reflect.spi.ConstructorInfo;
-import org.jboss.reflect.spi.EnumValue;
-import org.jboss.reflect.spi.FieldInfo;
-import org.jboss.reflect.spi.MethodInfo;
-import org.jboss.reflect.spi.ParameterInfo;
-import org.jboss.reflect.spi.PrimitiveInfo;
-import org.jboss.reflect.spi.PrimitiveValue;
+import org.jboss.reflect.spi.*;
import org.jboss.reflect.spi.StringValue;
-import org.jboss.reflect.spi.TypeInfo;
-import org.jboss.reflect.spi.TypeInfoFactory;
-import org.jboss.reflect.spi.Value;
import org.jboss.test.ContainerTest;
-import org.jboss.test.classinfo.support.AnnotatedClass;
-import org.jboss.test.classinfo.support.AnnotatedClassHierarchyWithInheritedAnnotations;
-import org.jboss.test.classinfo.support.AnnotatedClassHierarchyWithNotInheritedAnnotations;
-import org.jboss.test.classinfo.support.AnnotatedClassHierarchyWithNotInheritedAnnotations2;
-import org.jboss.test.classinfo.support.AnnotatedSubClass;
-import org.jboss.test.classinfo.support.AnnotationWithClass;
-import org.jboss.test.classinfo.support.AnotherAnnotation;
-import org.jboss.test.classinfo.support.ClassInfoParameterAnnotationsNotAllParametersAnnotated;
-import org.jboss.test.classinfo.support.ClassWithAnnotationWithClass;
-import org.jboss.test.classinfo.support.ClassWithAnnotationWithClassArray;
-import org.jboss.test.classinfo.support.ClassWithAnnotationWithInterfaceArray;
-import org.jboss.test.classinfo.support.ClassWithAnnotationWithPrimitiveClass;
-import org.jboss.test.classinfo.support.ComplexAnnotation;
-import org.jboss.test.classinfo.support.ExpectedAnnotations;
-import org.jboss.test.classinfo.support.JDK14ExpectedAnnotations;
-import org.jboss.test.classinfo.support.JDK50ExpectedAnnotations;
-import org.jboss.test.classinfo.support.NoAnnotationsBean;
-import org.jboss.test.classinfo.support.SimpleAnnotation;
-import org.jboss.test.classinfo.support.TestEnum;
-import org.jboss.test.classinfo.support.ValueAnnotation;
+import org.jboss.test.classinfo.support.*;
/**
*
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision$
*/
public abstract class AnnotatedClassInfoTest extends ContainerTest
@@ -422,6 +388,14 @@
assertSame(getTypeInfoFactory().getTypeInfo(SimpleAnnotation.class), constructorParams[1].getAnnotations()[0].getAnnotationType());
}
+ public void testCycle() throws Throwable
+ {
+ ClassInfo info = getClassInfo(UML.class);
+ Annotation[] annotations = info.getUnderlyingAnnotations();
+ assertNotNull(annotations);
+ assertEquals(3, annotations.length);
+ }
+
private void checkNoAnnotations(AnnotatedInfo info)
{
assertNull(info.getAnnotation("x"));
More information about the jboss-cvs-commits
mailing list