harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r794224 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/Statement.java test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java test/java/org/apache/harmony/beans/tests/java/beans/StatementTest.java
Date Wed, 15 Jul 2009 10:45:33 GMT
Author: zhoukevin
Date: Wed Jul 15 10:45:33 2009
New Revision: 794224

URL: http://svn.apache.org/viewvc?rev=794224&view=rev
Log:
Fix a defect of java.beans.Statement.convertClassName(Class<?> type) which parses and
returns the class name of the given agrument incorrectly.

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/StatementTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java?rev=794224&r1=794223&r2=794224&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/Statement.java
Wed Jul 15 10:45:33 2009
@@ -489,17 +489,22 @@
     }
 
     static String convertClassName(Class<?> type) {
-        Class<?> componentType = type.getComponentType();
-        Class<?> resultType = (componentType == null) ? type : componentType;
-        String result = resultType.getName();
-        int k = result.lastIndexOf('.');
-        if (k != -1 && k < result.length()) {
-            result = result.substring(k + 1);
+        StringBuilder clazzNameSuffix = new StringBuilder();
+        Class<?> componentType = null;
+        Class<?> clazzType = type;
+        while ((componentType = clazzType.getComponentType()) != null) {
+            clazzNameSuffix.append("Array"); //$NON-NLS-1$
+            clazzType = componentType;
+        }
+        String clazzName = clazzType.getName();
+        int k = clazzName.lastIndexOf('.');
+        if (k != -1 && k < clazzName.length()) {
+            clazzName = clazzName.substring(k + 1);
         }
-        if (componentType != null) {
-            result += "Array"; //$NON-NLS-1$
+        if (clazzNameSuffix.length() == 0 && "String".equals(clazzName)) { //$NON-NLS-1$
+            return "\"\""; //$NON-NLS-1$
         }
-        return result;
+        return clazzName + clazzNameSuffix.toString();
     }
 
     private static Class<?>[] getClasses(Object[] arguments) {

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java?rev=794224&r1=794223&r2=794224&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ExpressionTest.java
Wed Jul 15 10:45:33 2009
@@ -392,6 +392,17 @@
     }
 
     /*
+     * Test the constructor(value, ...) with a expression value.
+     */
+    public void testConstructor_EmptyTarget_EmptyMethod_ExpressionArguments() {
+        Object[] objectArray = new Object[] { new Expression((Object) null,
+                (String) null, (Object[]) null) };
+        Expression expression = new Expression(objectArray, new String(),
+                new String(), objectArray);
+        assertEquals("ObjectArray=\"\".(Expression);", expression.toString());
+    }
+
+    /*
      * Test the setValue() method with a non-null value when the value of the
      * expression is still unbounded.
      */

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/StatementTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/StatementTest.java?rev=794224&r1=794223&r2=794224&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/StatementTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/StatementTest.java
Wed Jul 15 10:45:33 2009
@@ -338,6 +338,34 @@
         assertEquals("Object.method(null);", t.toString());
     }
 
+    public void testConstructor_EmptyTarget_EmptyMethod_NullArguments() {
+        Statement statement = new Statement(new String(), new String(),
+                (Object[]) null);
+        assertEquals("\"\".();", statement.toString());
+    }
+
+    public void testConstructor_StringArrayTarget_EmptyMethod_NullArguments() {
+        Object target = new String[2];
+        Statement statement = new Statement(target, new String(),
+                (Object[]) null);
+        assertEquals("StringArray.();", statement.toString());
+    }
+
+    public void testConstructor_StringArrayArrayTarget_EmptyMethod_NullArguments() {
+        Object target = new String[2][];
+        Statement statement = new Statement(target, new String(),
+                (Object[]) null);
+        assertEquals("StringArrayArray.();", statement.toString());
+    }
+
+    public void testConstructor_StringArrayArrayTarget_EmptyMethod_StringArrayArrayTarget()
{
+        Object target = new String[2][];
+        Statement statement = new Statement(target, new String(),
+                new Object[] { target });
+        assertEquals("StringArrayArray.(StringArrayArray);", statement
+                .toString());
+    }
+
     // public void testGetArguments() {
     // // Covered in the testcases for the constructor
     // }



Mime
View raw message