[jboss-cvs] JBossAS SVN: r104997 - in projects/jboss-reflect/trunk/src/main/java/org/jboss: reflect/plugins/javassist and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 19 13:42:38 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-05-19 13:42:38 -0400 (Wed, 19 May 2010)
New Revision: 104997
Modified:
projects/jboss-reflect/trunk/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
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/JavassistConstructorInfo.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/JavassistTypeInfo.java
Log:
[JBREFLECT-124] Use SignatureKey for parameters comparison for JavassistConstructorInfo and JavassistMethodInfo, and don't call getReturnType()/getParameterTypes() in AbstractBeanInfoFactory until we have checked the name
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java 2010-05-19 17:17:18 UTC (rev 104996)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java 2010-05-19 17:42:38 UTC (rev 104997)
@@ -60,10 +60,13 @@
protected static boolean isGetter(MethodInfo minfo)
{
String name = minfo.getName();
- TypeInfo returnType = minfo.getReturnType();
- TypeInfo[] parameters = minfo.getParameterTypes();
if ((name.length() > 3 && name.startsWith("get")) || (name.length() > 2 && name.startsWith("is")))
{
+ //Don't load these until we verified the name since this hits the classpools for the javassist impl
+ //and we want things to be as lazy as possible
+ TypeInfo returnType = minfo.getReturnType();
+ TypeInfo[] parameters = minfo.getParameterTypes();
+
// isBoolean() is not a getter for java.lang.Boolean
if (name.startsWith("is") && PrimitiveInfo.BOOLEAN.equals(returnType) == false)
return false;
@@ -76,10 +79,13 @@
protected static boolean isSetter(MethodInfo minfo)
{
String name = minfo.getName();
- TypeInfo returnType = minfo.getReturnType();
- TypeInfo[] parameters = minfo.getParameterTypes();
if ((name.length() > 3 && name.startsWith("set")))
{
+ //Don't load these until we verified the name since this hits the classpools for the javassist impl
+ //and we want things to be as lazy as possible
+ TypeInfo returnType = minfo.getReturnType();
+ TypeInfo[] parameters = minfo.getParameterTypes();
+
if (parameters.length == 1 && PrimitiveInfo.VOID.equals(returnType))
return true;
}
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 17:17:18 UTC (rev 104996)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java 2010-05-19 17:42:38 UTC (rev 104997)
@@ -72,11 +72,14 @@
private transient volatile MethodSignature methodSignature;
- public JavassistAnnotatedParameterInfo(AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtBehavior ctBehavior)
+ private transient final SignatureKey signatureKey;
+
+ public JavassistAnnotatedParameterInfo(SignatureKey signatureKey, AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtBehavior ctBehavior)
{
super(annotationHelper);
this.typeInfo = typeInfo;
this.ctBehavior = ctBehavior;
+ this.signatureKey = signatureKey;
}
public int getModifiers()
@@ -294,4 +297,8 @@
return methodSignature;
}
+ protected SignatureKey getSignatureKey()
+ {
+ return signatureKey;
+ }
}
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java 2010-05-19 17:17:18 UTC (rev 104996)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistConstructorInfo.java 2010-05-19 17:42:38 UTC (rev 104997)
@@ -58,9 +58,9 @@
* @param typeInfo the type info
* @param ctConstructor the constructor
*/
- public JavassistConstructorInfo(AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtConstructor ctConstructor)
+ public JavassistConstructorInfo(SignatureKey signatureKey, AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtConstructor ctConstructor)
{
- super(annotationHelper, typeInfo, ctConstructor);
+ super(signatureKey, annotationHelper, typeInfo, ctConstructor);
}
public Object newInstance(Object[] args) throws Throwable
@@ -103,6 +103,13 @@
if (getDeclaringClass().equals(other.getDeclaringClass()) == false)
return false;
+
+ //Check the signature key since we want to avoid calling getParameterTypes(). If the parameters have
+ //not already been loaded that means hitting the classpools which is costly and might not be needed
+ //for anything else
+ if (other instanceof JavassistConstructorInfo)
+ return getSignatureKey().equals(((JavassistConstructorInfo)(other)).getSignatureKey());
+
return (Arrays.equals(getParameterTypes(), other.getParameterTypes()));
}
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 17:17:18 UTC (rev 104996)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java 2010-05-19 17:42:38 UTC (rev 104997)
@@ -72,9 +72,9 @@
* @param typeInfo the type info
* @param ctMethod the method
*/
- public JavassistMethodInfo(AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtMethod ctMethod)
+ public JavassistMethodInfo(SignatureKey signatureKey, AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtMethod ctMethod)
{
- super(annotationHelper, typeInfo, ctMethod);
+ super(signatureKey, annotationHelper, typeInfo, ctMethod);
}
public String getName()
@@ -149,6 +149,13 @@
// return false;
// if (getReturnType().equals(other.getReturnType()) == false)
// return false;
+
+ //Check the signature key since we want to avoid calling getParameterTypes(). If the parameters have
+ //not already been loaded that means hitting the classpools which is costly and might not be needed
+ //for anything else
+ if (other instanceof JavassistMethodInfo)
+ return getSignatureKey().equals(((JavassistMethodInfo)(other)).getSignatureKey());
+
return Arrays.equals(getParameterTypes(), other.getParameterTypes());
}
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 17:17:18 UTC (rev 104996)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java 2010-05-19 17:42:38 UTC (rev 104997)
@@ -26,7 +26,6 @@
import java.lang.reflect.Array;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -35,7 +34,6 @@
import java.util.concurrent.CopyOnWriteArrayList;
import javassist.CannotCompileException;
-import javassist.ClassPool;
import javassist.CtBehavior;
import javassist.CtClass;
import javassist.CtConstructor;
@@ -61,7 +59,6 @@
import org.jboss.reflect.spi.MutableFieldInfo;
import org.jboss.reflect.spi.MutableMethodInfo;
import org.jboss.reflect.spi.PackageInfo;
-import org.jboss.reflect.spi.PrimitiveInfo;
import org.jboss.reflect.spi.TypeInfo;
import org.jboss.reflect.spi.TypeInfoFactory;
import org.jboss.util.JBossStringBuilder;
@@ -681,7 +678,7 @@
String[] params = getParameterTypeStringsForSignature(constructor);
SignatureKey key = new SignatureKey(null, params);
- JavassistConstructorInfo info = new JavassistConstructorInfo(factory, this, constructor);
+ JavassistConstructorInfo info = new JavassistConstructorInfo(key, factory, this, constructor);
synchronized (constructors)
{
constructors.put(key, info);
@@ -771,7 +768,7 @@
*/
protected MutableMethodInfo generateMethodInfo(SignatureKey key, CtMethod method)
{
- JavassistMethodInfo info = new JavassistMethodInfo(factory, this, method);
+ JavassistMethodInfo info = new JavassistMethodInfo(key, factory, this, method);
synchronized (methods)
{
if (Modifier.isVolatile(method.getModifiers()))
@@ -1059,7 +1056,7 @@
try
{
CtConstructor constructor = CtNewConstructor.make(body.getBody(), ctClass);
- return new JavassistConstructorInfo(factory, this, constructor);
+ return new JavassistConstructorInfo(null, factory, this, constructor);
}
catch (CannotCompileException e)
{
@@ -1075,7 +1072,7 @@
CtConstructor constructor = CtNewConstructor.make(JavassistUtil.toCtClass(ctClass.getClassPool(), parameters),
JavassistUtil.toCtClass(ctClass.getClassPool(), exceptions), ctClass);
constructor.setModifiers(modifiers);
- return new JavassistConstructorInfo(factory, this, constructor);
+ return new JavassistConstructorInfo(null, factory, this, constructor);
}
catch (CannotCompileException e)
{
@@ -1091,7 +1088,7 @@
CtConstructor constructor = CtNewConstructor.make(JavassistUtil.toCtClass(parameters),
JavassistUtil.toCtClass(exceptions), ctClass);
constructor.setModifiers(modifiers);
- return new JavassistConstructorInfo(factory, this, constructor);
+ return new JavassistConstructorInfo(null, factory, this, constructor);
}
catch (CannotCompileException e)
{
@@ -1107,7 +1104,7 @@
CtConstructor constructor = CtNewConstructor.make(JavassistUtil.toCtClass(ctClass.getClassPool(), parameters),
JavassistUtil.toCtClass(ctClass.getClassPool(), exceptions), body.getBody(), ctClass);
constructor.setModifiers(modifiers);
- return new JavassistConstructorInfo(factory, this, constructor);
+ return new JavassistConstructorInfo(null, factory, this, constructor);
}
catch (CannotCompileException e)
{
@@ -1123,7 +1120,7 @@
CtConstructor constructor = CtNewConstructor.make(JavassistUtil.toCtClass(parameters),
JavassistUtil.toCtClass(exceptions), body.getBody(), ctClass);
constructor.setModifiers(modifiers);
- return new JavassistConstructorInfo(factory, this, constructor);
+ return new JavassistConstructorInfo(null, factory, this, constructor);
}
catch (CannotCompileException e)
{
@@ -1164,7 +1161,7 @@
try
{
CtMethod method = CtNewMethod.make(body.getBody(), ctClass);
- return new JavassistMethodInfo(factory, this, method);
+ return new JavassistMethodInfo(null, factory, this, method);
}
catch (CannotCompileException e)
{
@@ -1180,7 +1177,7 @@
CtMethod method = CtNewMethod.make(modifiers, JavassistUtil.toCtClass(ctClass.getClassPool(), returnType),
methodName, JavassistUtil.toCtClass(ctClass.getClassPool(), parameters), JavassistUtil.toCtClass(ctClass.getClassPool(), exceptions),
new InsertBeforeJavassistBody("{}").getBody(), ctClass);
- return new JavassistMethodInfo(factory, this, method);
+ return new JavassistMethodInfo(null, factory, this, method);
}
catch (CannotCompileException e)
{
@@ -1196,7 +1193,7 @@
CtMethod method = CtNewMethod.make(modifiers, JavassistUtil.toCtClass(returnType),
methodName, JavassistUtil.toCtClass(parameters), JavassistUtil.toCtClass(exceptions),
new InsertBeforeJavassistBody("{}").getBody(), ctClass);
- return new JavassistMethodInfo(factory, this, method);
+ return new JavassistMethodInfo(null, factory, this, method);
}
catch (CannotCompileException e)
{
@@ -1212,7 +1209,7 @@
CtMethod method = CtNewMethod.make(modifiers, JavassistUtil.toCtClass(ctClass.getClassPool(), returnType),
methodName, JavassistUtil.toCtClass(ctClass.getClassPool(), parameters), JavassistUtil.toCtClass(ctClass.getClassPool(), exceptions),
body.getBody(), ctClass);
- return new JavassistMethodInfo(factory, this, method);
+ return new JavassistMethodInfo(null, factory, this, method);
}
catch (CannotCompileException e)
{
@@ -1228,7 +1225,7 @@
CtMethod method = CtNewMethod.make(modifiers, JavassistUtil.toCtClass(returnType),
methodName, JavassistUtil.toCtClass(parameters), JavassistUtil.toCtClass(exceptions),
body.getBody(), ctClass);
- return new JavassistMethodInfo(factory, this, method);
+ return new JavassistMethodInfo(null, factory, this, method);
}
catch (CannotCompileException e)
{
More information about the jboss-cvs-commits
mailing list