[jboss-cvs] JBossAS SVN: r102923 - in projects/jboss-reflect/trunk/src: main/java/org/jboss/reflect/plugins/javassist/bytecode and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 24 16:31:44 EDT 2010


Author: kabir.khan at jboss.com
Date: 2010-03-24 16:31:42 -0400 (Wed, 24 Mar 2010)
New Revision: 102923

Added:
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/support/BoxedArrayBean.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/support/PrimitiveArrayBean.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/JavassistMemberFactoryArrayUnitTestCase.java
Modified:
   projects/jboss-reflect/trunk/src/main/java/org/jboss/config/plugins/property/PropertyConfiguration.java
   projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMemberFactory.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/AbstractJavassistMemberFactoryTest.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/AbstractJavassistMethodAndFieldFactoryTest.java
   projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/JavassistMemberFactoryTestSuite.java
Log:
[JBREFLECT-6] Support array parameters, return types and fields

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/config/plugins/property/PropertyConfiguration.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/config/plugins/property/PropertyConfiguration.java	2010-03-24 20:07:31 UTC (rev 102922)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/config/plugins/property/PropertyConfiguration.java	2010-03-24 20:31:42 UTC (rev 102923)
@@ -29,7 +29,6 @@
 import org.jboss.config.plugins.AbstractConfiguration;
 import org.jboss.joinpoint.spi.JoinpointFactoryBuilder;
 import org.jboss.logging.Logger;
-import org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory;
 import org.jboss.reflect.spi.TypeInfoFactory;
 
 /**
@@ -93,10 +92,7 @@
    @Override
    protected TypeInfoFactory createDefaultTypeInfoFactory() throws Throwable
    {
-//    return (TypeInfoFactory) loadFromProperties(PropertyConfigurationConstants.TYPE_INFO_FACTORY_NAME, PropertyConfigurationConstants.TYPE_INFO_FACTORY_DEFAULT, TypeInfoFactory.class);
-      TypeInfoFactory factory = (TypeInfoFactory) loadFromProperties(PropertyConfigurationConstants.TYPE_INFO_FACTORY_NAME, JavassistTypeInfoFactory.class.getName(), TypeInfoFactory.class);
-      log.warn("Factory: " + factory);
-      return factory;
+      return (TypeInfoFactory) loadFromProperties(PropertyConfigurationConstants.TYPE_INFO_FACTORY_NAME, PropertyConfigurationConstants.TYPE_INFO_FACTORY_DEFAULT, TypeInfoFactory.class);
    }
 
    @Override

Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMemberFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMemberFactory.java	2010-03-24 20:07:31 UTC (rev 102922)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/bytecode/JavassistMemberFactory.java	2010-03-24 20:31:42 UTC (rev 102923)
@@ -33,11 +33,13 @@
 import javassist.CtField;
 import javassist.CtMethod;
 import javassist.Modifier;
+import javassist.NotFoundException;
 import javassist.bytecode.AccessFlag;
 import javassist.bytecode.Bytecode;
 import javassist.bytecode.ClassFile;
 import javassist.bytecode.CodeAttribute;
 import javassist.bytecode.ConstPool;
+import javassist.bytecode.Descriptor;
 import javassist.bytecode.DuplicateMemberException;
 import javassist.bytecode.ExceptionsAttribute;
 import javassist.bytecode.MethodInfo;
@@ -516,6 +518,10 @@
     */
    String getBoxedType(CtClass type)
    {
+      if (type.isArray())
+      {
+         return Descriptor.of(type);
+      }
       if (type.isPrimitive())
       {
          if (CtClass.booleanType.equals(type))
@@ -538,6 +544,30 @@
       }
       return type.getName();
    }
+
+   String getArrayType(CtClass type)
+   {
+      String s = Descriptor.of(type);
+      StringBuilder buf = new StringBuilder();
+
+      //int dims = 0;
+      while (type.isArray())
+      {
+         buf.append("L");
+         try
+         {
+            type = type.getComponentType();
+         }
+         catch(NotFoundException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+      buf.append(type.getName());
+      buf.append(";");
+
+      return buf.toString();
+   }
    
    /**
     * Casts the value currently on the stack to the target type, and if a primitive

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/support/BoxedArrayBean.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/support/BoxedArrayBean.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/support/BoxedArrayBean.java	2010-03-24 20:31:42 UTC (rev 102923)
@@ -0,0 +1,155 @@
+/*
+* 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.plugins.javassist.bytecode.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BoxedArrayBean
+{
+   public Object[] objectArray;
+   
+   public Object[][] object2Array;
+
+   public Boolean[] booleanArray;
+   
+   public Byte[] byteArray;
+   
+   public Character[] charArray;
+   
+   public Double[] doubleArray;
+   
+   public Float[] floatArray;
+   
+   public Integer[] intArray;
+   
+   public Long[] longArray;
+   
+   public Short[] shortArray;
+
+   public BoxedArrayBean()
+   {
+   }
+   
+   public BoxedArrayBean(Object[] objectArray)
+   {
+      this.objectArray = objectArray;
+   }
+
+   public BoxedArrayBean(Object[][] object2Array)
+   {
+      this.object2Array = object2Array;
+   }
+
+   public BoxedArrayBean(Boolean[] booleanArray)
+   {
+      this.booleanArray = booleanArray;
+   }
+
+   public BoxedArrayBean(Byte[] byteArray)
+   {
+      this.byteArray = byteArray;
+   }
+
+   public BoxedArrayBean(Character[] charArray)
+   {
+      this.charArray = charArray;
+   }
+
+   public BoxedArrayBean(Double[] doubleArray)
+   {
+      this.doubleArray = doubleArray;
+   }
+
+   public BoxedArrayBean(Float[] floatArray)
+   {
+      this.floatArray = floatArray;
+   }
+   
+   public BoxedArrayBean(Integer[] intArray)
+   {
+      this.intArray = intArray;
+   }
+   
+   public BoxedArrayBean(Long[] longArray)
+   {
+      this.longArray = longArray;
+   }
+
+   public BoxedArrayBean(Short[] shortArray)
+   {
+      this.shortArray = shortArray;
+   }
+
+   public Object[] useObjectArray(Object[] o)
+   {
+      return o;
+   }
+
+   public Object[][] useObject2Array(Object[][] o)
+   {
+      return o;
+   }
+
+   public Boolean[] useBooleanArray(Boolean[] o)
+   {
+      return o;
+   }
+
+   public Byte[] useByteArray(Byte[] o)
+   {
+      return o;
+   }
+
+   public Character[] useCharArray(Character[] o)
+   {
+      return o;
+   }
+
+   public Double[] useDoubleArray(Double[] o)
+   {
+      return o;
+   }
+
+   public Float[] useFloatArray(Float[] o)
+   {
+      return o;
+   }
+
+   public Integer[] useIntArray(Integer[] o)
+   {
+      return o;
+   }
+
+   public Long[] useLongArray(Long[] o)
+   {
+      return o;
+   }
+
+   public Short[] useShortArray(Short[] o)
+   {
+      return o;
+   }
+
+}

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/support/PrimitiveArrayBean.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/support/PrimitiveArrayBean.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/support/PrimitiveArrayBean.java	2010-03-24 20:31:42 UTC (rev 102923)
@@ -0,0 +1,131 @@
+/*
+* 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.plugins.javassist.bytecode.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PrimitiveArrayBean
+{
+   public boolean[] booleanArray;
+   
+   public byte[] byteArray;
+   
+   public char[] charArray;
+   
+   public double[] doubleArray;
+   
+   public float[] floatArray;
+   
+   public int[] intArray;
+   
+   public long[] longArray;
+   
+   public short[] shortArray;
+
+   public PrimitiveArrayBean()
+   {
+   }
+   
+   public PrimitiveArrayBean(boolean[] booleanArray)
+   {
+      this.booleanArray = booleanArray;
+   }
+
+   public PrimitiveArrayBean(byte[] byteArray)
+   {
+      this.byteArray = byteArray;
+   }
+
+   public PrimitiveArrayBean(char[] charArray)
+   {
+      this.charArray = charArray;
+   }
+
+   public PrimitiveArrayBean(double[] doubleArray)
+   {
+      this.doubleArray = doubleArray;
+   }
+
+   public PrimitiveArrayBean(float[] floatArray)
+   {
+      this.floatArray = floatArray;
+   }
+   
+   public PrimitiveArrayBean(int[] intArray)
+   {
+      this.intArray = intArray;
+   }
+   
+   public PrimitiveArrayBean(long[] longArray)
+   {
+      this.longArray = longArray;
+   }
+
+   public PrimitiveArrayBean(short[] shortArray)
+   {
+      this.shortArray = shortArray;
+   }
+
+   public boolean[] useBooleanArray(boolean[] o)
+   {
+      return o;
+   }
+
+   public byte[] useByteArray(byte[] o)
+   {
+      return o;
+   }
+
+   public char[] useCharArray(char[] o)
+   {
+      return o;
+   }
+
+   public double[] useDoubleArray(double[] o)
+   {
+      return o;
+   }
+
+   public float[] useFloatArray(float[] o)
+   {
+      return o;
+   }
+
+   public int[] useIntArray(int[] o)
+   {
+      return o;
+   }
+
+   public long[] useLongArray(long[] o)
+   {
+      return o;
+   }
+
+   public short[] useShortArray(short[] o)
+   {
+      return o;
+   }
+
+}

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/AbstractJavassistMemberFactoryTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/AbstractJavassistMemberFactoryTest.java	2010-03-24 20:07:31 UTC (rev 102922)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/AbstractJavassistMemberFactoryTest.java	2010-03-24 20:31:42 UTC (rev 102923)
@@ -143,9 +143,4 @@
    {
       return JavassistMemberFactory.createJavassistField(MAGIC_ACCESSOR_IMPL, getCtField(clazz, name), CHECK, DEBUG);
    }
-   
-   protected abstract Class<?> getClazz();
-   
-   protected abstract Object createInstance();
-
 }

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/AbstractJavassistMethodAndFieldFactoryTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/AbstractJavassistMethodAndFieldFactoryTest.java	2010-03-24 20:07:31 UTC (rev 102922)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/AbstractJavassistMethodAndFieldFactoryTest.java	2010-03-24 20:31:42 UTC (rev 102923)
@@ -248,4 +248,9 @@
       {
       }  
    }
+   
+   protected abstract Class<?> getClazz();
+   
+   protected abstract Object createInstance();
+
 }

Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/JavassistMemberFactoryArrayUnitTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/JavassistMemberFactoryArrayUnitTestCase.java	                        (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/JavassistMemberFactoryArrayUnitTestCase.java	2010-03-24 20:31:42 UTC (rev 102923)
@@ -0,0 +1,152 @@
+/*
+* 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.plugins.javassist.bytecode.test;
+
+import junit.framework.Test;
+
+import org.jboss.reflect.plugins.javassist.JavassistConstructor;
+import org.jboss.reflect.plugins.javassist.JavassistField;
+import org.jboss.reflect.plugins.javassist.JavassistMethod;
+import org.jboss.test.plugins.javassist.bytecode.support.BoxedArrayBean;
+import org.jboss.test.plugins.javassist.bytecode.support.PrimitiveArrayBean;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavassistMemberFactoryArrayUnitTestCase extends AbstractJavassistMemberFactoryTest
+{
+   public static Test suite()
+   {
+      return suite(JavassistMemberFactoryArrayUnitTestCase.class);
+   }
+
+   public JavassistMemberFactoryArrayUnitTestCase(String name)
+   {
+      super(name, false);
+   }
+
+   public void testObjectArray() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Object[].class, "useObjectArray", "objectArray", new Object[] {"x"}, new Object[] {"y"});
+   }
+   
+   public void testObject2Array() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Object[][].class, "useObject2Array", "object2Array", new Object[][] {new Object[] {"x"}}, new Object[][] {new Object[] {"y"}});
+   }
+   
+   public void testBoxedBooleanArray() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Boolean[].class, "useBooleanArray", "booleanArray", new Boolean[] {Boolean.TRUE}, new Boolean[] {Boolean.FALSE});
+   }
+   
+   public void testPrimitiveBooleanArray() throws Throwable
+   {
+      testArray(PrimitiveArrayBean.class, boolean[].class, "useBooleanArray", "booleanArray", new boolean[] {true}, new boolean[] {false});
+   }
+   
+   public void testBoxedByteArray() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Byte[].class, "useByteArray", "byteArray", new Byte[] {Byte.valueOf((byte)1)}, new Byte[] {Byte.valueOf((byte)2)});
+   }
+   
+   public void testPrimitiveByteArray() throws Throwable
+   {
+      testArray(PrimitiveArrayBean.class, byte[].class, "useByteArray", "byteArray", new byte[] {(byte)1}, new byte[] {(byte)2});
+   }
+   
+   public void testBoxedCharArray() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Character[].class, "useCharArray", "charArray", new Character[] {Character.valueOf('a')}, new Character[] {Character.valueOf('b')});
+   }
+   
+   public void testPrimitiveCharArray() throws Throwable
+   {
+      testArray(PrimitiveArrayBean.class, char[].class, "useCharArray", "charArray", new char[] {'a'}, new char[] {'b'});
+   }
+   
+   public void testBoxedDoubleArray() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Double[].class, "useDoubleArray", "doubleArray", new Double[] {Double.valueOf(1)}, new Double[] {Double.valueOf(2)});
+   }
+   
+   public void testPrimitiveDoubleArray() throws Throwable
+   {
+      testArray(PrimitiveArrayBean.class, double[].class, "useDoubleArray", "doubleArray", new double[] {1}, new double[] {2});
+   }
+   
+   public void testBoxedFloatArray() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Float[].class, "useFloatArray", "floatArray", new Float[] {Float.valueOf(1)}, new Float[] {Float.valueOf(2)});
+   }
+   
+   public void testPrimitveFloatArray() throws Throwable
+   {
+      testArray(PrimitiveArrayBean.class, float[].class, "useFloatArray", "floatArray", new float[] {1}, new float[] {2});
+   }
+   
+   public void testBoxedIntArray() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Integer[].class, "useIntArray", "intArray", new Integer[] {Integer.valueOf(1)}, new Integer[] {Integer.valueOf(2)});
+   }
+   
+   public void testPrimitiveIntArray() throws Throwable
+   {
+      testArray(PrimitiveArrayBean.class, int[].class, "useIntArray", "intArray", new int[] {1}, new int[] {2});
+   }
+   
+   public void testBoxedLongArray() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Long[].class, "useLongArray", "longArray", new Long[] {Long.valueOf(1)}, new Long[] {Long.valueOf(2)});
+   }
+   
+   public void testPrimitiveLongArray() throws Throwable
+   {
+      testArray(PrimitiveArrayBean.class, long[].class, "useLongArray", "longArray", new long[] {1}, new long[] {2});
+   }
+   
+   public void testBoxedShortArray() throws Throwable
+   {
+      testArray(BoxedArrayBean.class, Short[].class, "useShortArray", "shortArray", new Short[] {Short.valueOf((short)1)}, new Short[] {Short.valueOf((short)2)});
+   }
+   
+   public void testPrimitveShortArray() throws Throwable
+   {
+      testArray(PrimitiveArrayBean.class, short[].class, "useShortArray", "shortArray", new short[] {(short)1}, new short[] {(short)2});
+   }
+   
+   private <T> void testArray(Class<?> beanClass, Class<T> type, String methodName, String fieldName, T arg, T arg2) throws Throwable
+   {
+      JavassistConstructor ctor = createConstructor(beanClass, type);
+      Object tgt = ctor.newInstance(new Object[] {arg});
+      assertInstanceOf(tgt, beanClass);
+      
+      JavassistMethod method = createMethod(beanClass, methodName, type);
+      assertSame(arg, method.invoke(tgt, new Object[] {arg}));
+      
+      JavassistField field = createField(beanClass, fieldName);
+      field.set(tgt, arg2);
+      assertSame(arg2, field.get(tgt));
+   }
+}

Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/JavassistMemberFactoryTestSuite.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/JavassistMemberFactoryTestSuite.java	2010-03-24 20:07:31 UTC (rev 102922)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/plugins/javassist/bytecode/test/JavassistMemberFactoryTestSuite.java	2010-03-24 20:31:42 UTC (rev 102923)
@@ -61,6 +61,8 @@
       suite.addTest(JavassistMemberFactoryPrivateStaticBoxedUnitTestCase.suite());
       suite.addTest(JavassistMemberFactoryPrivateStaticPrimitiveUnitTestCase.suite());
       
+      suite.addTest(JavassistMemberFactoryArrayUnitTestCase.suite());
+      
       return suite;
    }
 




More information about the jboss-cvs-commits mailing list