[jboss-cvs] JBossAS SVN: r105183 - in projects/jboss-reflect/branches/kabir_wip/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
Mon May 24 17:10:02 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-05-24 17:10:01 -0400 (Mon, 24 May 2010)
New Revision: 105183
Modified:
projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/ClassInfoEqualizer.java
projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java
projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java
projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java
projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterInfo.java
projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/LazyJavassistClassInfo.java
projects/jboss-reflect/branches/kabir_wip/src/test/java/org/jboss/test/classinfo/test/AbstractClassInfoTest.java
projects/jboss-reflect/branches/kabir_wip/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericMembersTest.java
Log:
More changes
Modified: projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/ClassInfoEqualizer.java
===================================================================
--- projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/ClassInfoEqualizer.java 2010-05-24 20:45:14 UTC (rev 105182)
+++ projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/ClassInfoEqualizer.java 2010-05-24 21:10:01 UTC (rev 105183)
@@ -23,7 +23,6 @@
import org.jboss.reflect.plugins.introspection.ParameterizedClassInfo;
import org.jboss.reflect.plugins.javassist.JavassistClassInfo;
-import org.jboss.reflect.plugins.javassist.JavassistParameterizedClassInfo;
import org.jboss.reflect.spi.ClassInfo;
import org.jboss.reflect.spi.DelegateClassInfo;
@@ -49,7 +48,6 @@
}
if (infoA instanceof JavassistClassInfo && infoB instanceof JavassistClassInfo)
{
- ((JavassistClassInfo)infoA).getClassSignature()
}
if (infoA instanceof DelegateClassInfo && infoB instanceof DelegateClassInfo)
{
Modified: projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java
===================================================================
--- projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java 2010-05-24 20:45:14 UTC (rev 105182)
+++ projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java 2010-05-24 21:10:01 UTC (rev 105183)
@@ -31,6 +31,7 @@
import javassist.bytecode.SignatureAttribute.MethodSignature;
import org.jboss.reflect.plugins.AnnotationHelper;
+import org.jboss.reflect.plugins.ClassInfoImpl;
import org.jboss.reflect.spi.AnnotationInfo;
import org.jboss.reflect.spi.AnnotationValue;
import org.jboss.reflect.spi.Body;
@@ -74,6 +75,8 @@
private transient final SignatureKey signatureKey;
+ private transient volatile ParameterStatus parameterStatus = ParameterStatus.NULL;
+
public JavassistAnnotatedParameterInfo(SignatureKey signatureKey, AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtBehavior ctBehavior)
{
super(annotationHelper);
@@ -133,7 +136,7 @@
return exceptionTypes;
}
- protected void generateParameters()
+ protected void generateParametersOld()
{
if (parameters != null)
return;
@@ -164,20 +167,98 @@
}
}
+ final static ParameterInfo[] UNKNOWN_PARAMETER_INFOS = new ParameterInfo[0];
+ protected void generateParameters()
+ {
+ if (parameters != null)
+ return;
+
+ SignatureKey key = getSignatureKey();
+ String[] params = key.getParams();
+ ParameterInfo[] parameters = params.length == 0 ? UNKNOWN_PARAMETER_INFOS : new ParameterInfo[params.length];
+ TypeInfo[] parameterTypes = params.length == 0 ? ClassInfoImpl.UNKNOWN_TYPES : new TypeInfo[params.length];
+ if (params.length == 0)
+ parameterStatus = ParameterStatus.INITIALIZED;
+ else
+ {
+ boolean lazy = false;
+ for (int i = 0 ; i < params.length ; i++)
+ {
+ parameterTypes[i] = getLazyInfo(key, i);
+ if (parameterTypes[i] instanceof LazyJavassistClassInfo)
+ lazy = true;
+
+ parameters[i] = new JavassistParameterInfo(annotationHelper, this, i, parameterTypes[i]);
+ }
+
+ parameterStatus = lazy ? ParameterStatus.LAZY : ParameterStatus.INITIALIZED;
+ }
+ this.parameterTypes = parameterTypes;
+ this.parameters = parameters;
+
+ }
+
+ protected TypeInfo getLazyInfo(SignatureKey key, int index)
+ {
+ String param = index >= 0 ? key.getParams()[index] : SignatureKey.getReturnType(ctBehavior);
+
+ TypeInfo info = typeInfo.getFactory().getPrimitiveOrNumberInfo(param);
+ if (info != null)
+ return info;
+
+ return LazyJavassistClassInfo.createJavassistClassInfo(this, param, index);
+ }
+
+
public ParameterInfo[] getParameters()
{
- if (parameters == null)
+ if (parameterStatus == ParameterStatus.NULL)
generateParameters();
return parameters;
}
public TypeInfo[] getParameterTypes()
{
- if (parameterTypes == null)
+ if (parameterStatus == ParameterStatus.NULL)
generateParameters();
return parameterTypes;
}
+ protected ClassInfo lazyLoadParameters(int index)
+ {
+ if (parameterStatus == ParameterStatus.NULL)
+ throw new IllegalStateException("Should be in INITIALIZED or LAZY state");
+
+ if (parameterStatus == ParameterStatus.LAZY)
+ {
+ try
+ {
+ CtClass[] ctParameters = ctBehavior.getParameterTypes();
+ MethodSignature sig = getMethodSignature();
+ if (sig != null && sig.getParameterTypes().length == ctParameters.length)
+ {
+ parameterTypes = JavassistHelper.createParameterTypes(sig, typeInfo);
+ }
+ else
+ {
+ CtClass[] types = ctParameters;
+ parameterTypes = new TypeInfo[types.length];
+ for (int i = 0; i < types.length; ++i)
+ parameterTypes[i] = typeInfo.getFactory().getTypeInfo(types[i]);
+ }
+ for (int i = 0; i < parameterTypes.length; ++i)
+ ((JavassistParameterInfo)parameters[i]).setParameterType(parameterTypes[i]);
+ }
+ catch (NotFoundException e)
+ {
+ throw JavassistTypeInfoFactoryImpl.raiseClassNotFound("for parameters of constructor", e);
+ }
+ parameterStatus = ParameterStatus.INITIALIZED;
+ }
+
+ return (ClassInfo)parameterTypes[index];
+ }
+
public AnnotationValue[] getAnnotations()
{
return getAnnotations(ctBehavior);
@@ -308,4 +389,11 @@
{
return ctBehavior.getSignature();
}
+
+ private enum ParameterStatus
+ {
+ NULL,
+ LAZY,
+ INITIALIZED;
+ }
}
Modified: projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java
===================================================================
--- projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java 2010-05-24 20:45:14 UTC (rev 105182)
+++ projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java 2010-05-24 21:10:01 UTC (rev 105183)
@@ -118,7 +118,7 @@
@Override
protected void toString(JBossStringBuilder buffer)
{
- buffer.append(Arrays.asList(getParameterTypes()));
+ buffer.append(Arrays.asList(getSignatureKey().getParams()));
super.toString(buffer);
}
Modified: projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java
===================================================================
--- projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java 2010-05-24 20:45:14 UTC (rev 105182)
+++ projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java 2010-05-24 21:10:01 UTC (rev 105183)
@@ -156,17 +156,6 @@
return (ClassInfo)returnType;
}
- private TypeInfo getLazyInfo(SignatureKey key, int index)
- {
- String param = index > 0 ? key.getParams()[index] : SignatureKey.getReturnType(ctBehavior);
-
- TypeInfo info = typeInfo.getFactory().getPrimitiveOrNumberInfo(param);
- if (info != null)
- return info;
-
- return LazyJavassistClassInfo.createJavassistClassInfo(this, param, index);
- }
-
public Object invoke(Object target, Object[] args) throws Throwable
{
if (method == null)
Modified: projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterInfo.java
===================================================================
--- projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterInfo.java 2010-05-24 20:45:14 UTC (rev 105182)
+++ projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/JavassistParameterInfo.java 2010-05-24 21:10:01 UTC (rev 105183)
@@ -45,7 +45,7 @@
private final String name;
/** The paramter type */
- private final TypeInfo parameterType;
+ private volatile TypeInfo parameterType;
/**
* Create a new JavassistParameterInfo.
@@ -82,6 +82,11 @@
{
return parameterType;
}
+
+ protected void setParameterType(TypeInfo parameterType)
+ {
+ this.parameterType = parameterType;
+ }
@Override
public boolean equals(Object obj)
Modified: projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/LazyJavassistClassInfo.java
===================================================================
--- projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/LazyJavassistClassInfo.java 2010-05-24 20:45:14 UTC (rev 105182)
+++ projects/jboss-reflect/branches/kabir_wip/src/main/java/org/jboss/reflect/plugins/javassist/LazyJavassistClassInfo.java 2010-05-24 21:10:01 UTC (rev 105183)
@@ -22,7 +22,6 @@
package org.jboss.reflect.plugins.javassist;
import java.lang.annotation.Annotation;
-import java.util.HashSet;
import java.util.Set;
import org.jboss.reflect.spi.AnnotationAttribute;
@@ -65,9 +64,9 @@
this.name = name;
}
- public static LazyJavassistClassInfo createJavassistClassInfo(JavassistMethodInfo behavior, String name, int index)
+ public static LazyJavassistClassInfo createJavassistClassInfo(JavassistAnnotatedParameterInfo behavior, String name, int index)
{
- return new LazyJavassistMethodClassInfo(behavior, name, index);
+ return new LazyJavassistBehaviorClassInfo(behavior, name, index);
}
//Simple methods
@@ -128,6 +127,13 @@
return super.equals(obj, doneTypeVariables);
}
+ public Class<?> getType()
+ {
+ if (delegate == null)
+ loadDelegate();
+ return delegate.getType();
+ }
+
//The following methods need to load up the delegate
public TypeInfo[] getActualTypeArguments()
@@ -312,13 +318,6 @@
return delegate.getSuperclass();
}
- public Class<?> getType()
- {
- if (delegate == null)
- loadDelegate();
- return delegate.getType();
- }
-
public TypeInfoFactory getTypeInfoFactory()
{
if (delegate == null)
@@ -524,31 +523,16 @@
@Override
protected void loadDelegate()
{
-
- }
- }
-
- private static class LazyJavassistMethodClassInfo extends LazyJavassistBehaviorClassInfo
- {
- private static final long serialVersionUID = 1L;
-
- protected LazyJavassistMethodClassInfo(JavassistMethodInfo method, String name, int index)
- {
- super(method, name, index);
- }
-
- @Override
- protected void loadDelegate()
- {
- if (index >= 0)
+ if (index < 0)
{
- super.loadDelegate();
- return;
+ if (owner instanceof JavassistMethodInfo == false)
+ throw new IllegalArgumentException("Not a method");
+ delegate = ((JavassistMethodInfo)owner).lazyLoadReturnType();
}
-
- delegate = ((JavassistMethodInfo)owner).lazyLoadReturnType();
+ else
+ delegate = owner.lazyLoadParameters(index);
+
}
-
}
}
Modified: projects/jboss-reflect/branches/kabir_wip/src/test/java/org/jboss/test/classinfo/test/AbstractClassInfoTest.java
===================================================================
--- projects/jboss-reflect/branches/kabir_wip/src/test/java/org/jboss/test/classinfo/test/AbstractClassInfoTest.java 2010-05-24 20:45:14 UTC (rev 105182)
+++ projects/jboss-reflect/branches/kabir_wip/src/test/java/org/jboss/test/classinfo/test/AbstractClassInfoTest.java 2010-05-24 21:10:01 UTC (rev 105183)
@@ -638,8 +638,8 @@
if (infoA.getRawType() == infoA)
{
//Not a paramerized type, check same
- assertSame(infoB, infoB.getRawType());
- assertSame(infoB, infoA);
+ assertEquals(infoB, infoB.getRawType());
+ assertEquals(infoB, infoA);
}
else
{
Modified: projects/jboss-reflect/branches/kabir_wip/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericMembersTest.java
===================================================================
--- projects/jboss-reflect/branches/kabir_wip/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericMembersTest.java 2010-05-24 20:45:14 UTC (rev 105182)
+++ projects/jboss-reflect/branches/kabir_wip/src/test/java/org/jboss/test/classinfo/test/ClassInfoGenericMembersTest.java 2010-05-24 21:10:01 UTC (rev 105183)
@@ -450,7 +450,7 @@
if (!generic)
{
assertEquals(parameterTypes[0], parameterTypes[1]);
- assertSame(parameterInfos[0], parameterInfos[1]);
+ assertEquals(parameterInfos[0], parameterInfos[1]);
}
else
{
@@ -484,7 +484,7 @@
if (!generic)
{
assertEquals(parameterTypes[2], parameterTypes[3]);
- assertSame(parameterInfos[2], parameterInfos[3]);
+ assertEquals(parameterInfos[2], parameterInfos[3]);
}
else
{
More information about the jboss-cvs-commits
mailing list