[jboss-cvs] JBossAS SVN: r102632 - in projects/jboss-reflect/trunk/src: main/java/org/jboss/reflect/plugins and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 19 13:26:58 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-03-19 13:26:57 -0400 (Fri, 19 Mar 2010)
New Revision: 102632
Added:
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUnitTestCase.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistConfiguration.java
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/MethodInfoImpl.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
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java
Log:
[JBREFLECT-107] Make sure that javassist beaninfo handles volatile methods properly. They should be returned by ClassInfo.getDeclaredMethods(), but not be picked up in the bean info
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-03-19 16:33:26 UTC (rev 102631)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/beans/info/plugins/AbstractBeanInfoFactory.java 2010-03-19 17:26:57 UTC (rev 102632)
@@ -226,6 +226,8 @@
{
HashSet<MethodInfo> result = new HashSet<MethodInfo>();
+ MethodInfo getProp = null;
+
while (classInfo != null)
{
MethodInfo[] minfos = classInfo.getDeclaredMethods();
@@ -233,6 +235,25 @@
{
for (int i = 0; i < minfos.length; ++i)
{
+ if (minfos[i].getName().equals("getProperty"))
+ {
+ if (getProp == null)
+ {
+ getProp = minfos[i];
+ }
+ else
+ {
+ MethodInfo mi = minfos[i];
+ int mainHc = getProp.hashCode();
+ int currHc = mi.hashCode();
+
+ boolean left = mi.equals(getProp);
+ boolean right = getProp.equals(mi);
+
+ int blah = 0;
+ }
+ }
+
if (result.contains(minfos[i]) == false && minfos[i].isPublic() && minfos[i].isStatic() == false && minfos[i].isVolatile() == false)
result.add(minfos[i]);
}
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/MethodInfoImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/MethodInfoImpl.java 2010-03-19 16:33:26 UTC (rev 102631)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/MethodInfoImpl.java 2010-03-19 17:26:57 UTC (rev 102632)
@@ -208,7 +208,7 @@
protected void toString(JBossStringBuilder buffer)
{
buffer.append("name=").append(name);
- buffer.append(Arrays.asList(parameterTypes));
+ buffer.append(Arrays.toString(parameterTypes));
buffer.append(" return=").append(returnType);
}
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-03-19 16:33:26 UTC (rev 102631)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java 2010-03-19 17:26:57 UTC (rev 102632)
@@ -199,10 +199,10 @@
if (getName().equals(other.getName()) == false)
return false;
- if (getDeclaringClass().equals(other.getDeclaringClass()) == false)
- return false;
- if (getReturnType().equals(other.getReturnType()) == false)
- return false;
+// if (getDeclaringClass().equals(other.getDeclaringClass()) == false)
+// return false;
+// if (getReturnType().equals(other.getReturnType()) == false)
+// return false;
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-03-19 16:33:26 UTC (rev 102631)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java 2010-03-19 17:26:57 UTC (rev 102632)
@@ -24,9 +24,14 @@
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Modifier;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
import javassist.CannotCompileException;
import javassist.CtClass;
@@ -93,6 +98,8 @@
/** The methods */
private Map<SignatureKey, JavassistMethodInfo> methods = new ConcurrentHashMap<SignatureKey, JavassistMethodInfo>();
+
+ private Map<SignatureKey, List<JavassistMethodInfo>> volatileMethods = new HashMap<SignatureKey, List<JavassistMethodInfo>>();
/** The methods */
private MutableMethodInfo[] methodArray;
@@ -442,6 +449,20 @@
for (int i = 0; i < declaredMethods.length; ++i)
generateMethodInfo(declaredMethods[i]);
Collection<JavassistMethodInfo> methodCollection = methods.values();
+
+ if (volatileMethods.size() > 0)
+ {
+ Collection<JavassistMethodInfo> allMethods = new ArrayList<JavassistMethodInfo>();
+ allMethods.addAll(methodCollection);
+ methodCollection = allMethods;
+
+ for (List<JavassistMethodInfo> infos : volatileMethods.values())
+ {
+ if (infos.size() > 0)
+ methodCollection.addAll(infos);
+ }
+ }
+
methodArray = methodCollection.toArray(new MutableMethodInfo[methodCollection.size()]);
}
}
@@ -715,14 +736,25 @@
*
* @param key the key
* @param method the method
- * @return the method info
+ * @return the method info or null if the method is volatile
*/
protected MutableMethodInfo generateMethodInfo(SignatureKey key, CtMethod method)
{
JavassistMethodInfo info = new JavassistMethodInfo(factory, this, method);
synchronized (methods)
{
- methods.put(key, info);
+ if (Modifier.isVolatile(method.getModifiers()))
+ {
+ List<JavassistMethodInfo> infos = volatileMethods.get(key);
+ if (infos == null)
+ {
+ infos = new CopyOnWriteArrayList<JavassistMethodInfo>();
+ volatileMethods.put(key, infos);
+ }
+ infos.add(info);
+ }
+ else
+ methods.put(key, info);
}
return info;
}
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java 2010-03-19 16:33:26 UTC (rev 102631)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/AbstractBeanInfoTest.java 2010-03-19 17:26:57 UTC (rev 102632)
@@ -68,6 +68,11 @@
super(name);
}
+ protected void setJavassist()
+ {
+ configuration = new JavassistConfiguration();
+ }
+
protected void assertBeanInfo(BeanInfo beanInfo, Class<?> clazz) throws Throwable
{
assertBeanInfo(beanInfo, clazz, BeanAccessMode.STANDARD);
@@ -168,6 +173,12 @@
{
System.out.println("expected = " + expected);
System.out.println("actual = " + actual);
+
+ PropertyInfo[] expecteds = expected.toArray(new PropertyInfo[2]);
+ PropertyInfo[] actuals = actual.toArray(new PropertyInfo[2]);
+
+ expected = getExpectedProperties(clazz, mode);
+ actual = beanInfo.getProperties();
}
assertTrue(equals);
// assertEquals(expected, actual);
Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUnitTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUnitTestCase.java (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistBeanInfoUnitTestCase.java 2010-03-19 17:26:57 UTC (rev 102632)
@@ -0,0 +1,45 @@
+/*
+* 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.beaninfo.test;
+
+import junit.framework.Test;
+
+/**
+ * BeanInfo Test Case.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 45663 $
+ */
+public class JavassistBeanInfoUnitTestCase extends BeanInfoUnitTestCase
+{
+ public static Test suite()
+ {
+ return suite(JavassistBeanInfoUnitTestCase.class);
+ }
+
+ public JavassistBeanInfoUnitTestCase(String name)
+ {
+ super(name);
+ setJavassist();
+ }
+
+}
\ No newline at end of file
Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistConfiguration.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistConfiguration.java (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/beaninfo/test/JavassistConfiguration.java 2010-03-19 17:26:57 UTC (rev 102632)
@@ -0,0 +1,43 @@
+/*
+* 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.test.beaninfo.test;
+
+import org.jboss.config.plugins.BasicConfiguration;
+import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavassistConfiguration extends BasicConfiguration
+{
+ @Override
+ protected TypeInfoFactory createDefaultTypeInfoFactory() throws Throwable
+ {
+ return new JavassistTypeInfoFactory();
+ }
+
+
+
+}
More information about the jboss-cvs-commits
mailing list