]> source.dussan.org Git - aspectj.git/commitdiff
Bug 150487 "Tracing and Logging Framework" (improve formatting for arrays and Collect...
authormwebster <mwebster>
Wed, 16 Aug 2006 14:52:44 +0000 (14:52 +0000)
committermwebster <mwebster>
Wed, 16 Aug 2006 14:52:44 +0000 (14:52 +0000)
weaver/src/org/aspectj/weaver/tools/AbstractTrace.java
weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java

index 0ca7425033c9008d3dbe86e474e1f67c0aea22c2..893650b1f9da84fcc72a3d03710da4f3808999e5 100644 (file)
@@ -11,7 +11,9 @@
 package org.aspectj.weaver.tools;
 
 import java.io.File;
+import java.lang.reflect.Array;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
 import java.util.Date;
 
 public abstract class AbstractTrace implements Trace {
@@ -126,6 +128,12 @@ public abstract class AbstractTrace implements Trace {
                            || obj instanceof File
                            || obj instanceof StringBuffer
                    ) return obj;
+               else if (obj.getClass().isArray()) {
+                       return formatArray(obj);
+               }
+               else if (obj instanceof Collection) {
+                       return formatCollection((Collection)obj);
+               }
                else try {
                        
                        /* Classes can provide an alternative implementation of toString() */
@@ -142,6 +150,14 @@ public abstract class AbstractTrace implements Trace {
                        return obj.getClass().getName();
                }
        }
+       
+       protected String formatArray (Object obj) {
+               return obj.getClass().getComponentType().getName() + "[" + Array.getLength(obj) + "]"; 
+       }
+       
+       protected String formatCollection (Collection c) {
+               return c.getClass().getName() + "(" + c.size() + ")"; 
+       }
 
        /** 
         * Format arguments into a comma separated list
index abdff5fcb84896d8a1de7d112338d898454e5d0a..b28323a91fba3aded5da7ed625e4b426bc6f2430 100644 (file)
  *******************************************************************************/
 package org.aspectj.weaver;
 
+import java.util.ArrayList;
+
 import junit.framework.TestCase;
 
 import org.aspectj.weaver.tools.AbstractTrace;
 import org.aspectj.weaver.tools.DefaultTrace;
+import org.aspectj.weaver.tools.Traceable;
 
-public class AbstractTraceTest extends TestCase {
+public abstract class AbstractTraceTest extends TestCase {
 
        protected AbstractTrace trace;
 
@@ -28,6 +31,28 @@ public class AbstractTraceTest extends TestCase {
                trace.enter("testEnterWithThisAndArgs",this,new Object[] { "arg1", "arg2" });
        }
 
+       public void testEnterWithThisAndArray() {
+               Object arg1 = new String[] { "s1", "s2" };
+               Object arg2 = new char[] { 'a', 'b', 'c' };
+               trace.enter("testEnterWithThisAndArgs",this,new Object[] { arg1, arg2 });
+       }
+
+       public void testEnterWithThisAndCollection() {
+               Object arg1 = new ArrayList();
+               trace.enter("testEnterWithThisAndArgs",this,new Object[] { arg1 });
+       }
+
+       public void testEnterWithThisAndTraceable () {
+               Object arg1 = new Traceable() {
+
+                       public String toTraceString() {
+                               return "Traceable";
+                       }
+                       
+               };
+               trace.enter("testEnterWithThisAndArgs",this,new Object[] { arg1 });
+       }
+
        public void testEnterWithThis() {
                trace.enter("testEnterWithThis",this);
        }