From 4a53ac4202af0d7ee667474c7a1a4820e32a98cf Mon Sep 17 00:00:00 2001 From: mwebster Date: Wed, 16 Aug 2006 14:52:44 +0000 Subject: [PATCH] Bug 150487 "Tracing and Logging Framework" (improve formatting for arrays and Collections) --- .../aspectj/weaver/tools/AbstractTrace.java | 16 +++++++++++ .../org/aspectj/weaver/AbstractTraceTest.java | 27 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/weaver/src/org/aspectj/weaver/tools/AbstractTrace.java b/weaver/src/org/aspectj/weaver/tools/AbstractTrace.java index 0ca742503..893650b1f 100644 --- a/weaver/src/org/aspectj/weaver/tools/AbstractTrace.java +++ b/weaver/src/org/aspectj/weaver/tools/AbstractTrace.java @@ -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 diff --git a/weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java b/weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java index abdff5fcb..b28323a91 100644 --- a/weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java +++ b/weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java @@ -10,12 +10,15 @@ *******************************************************************************/ 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); } -- 2.39.5