summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormwebster <mwebster>2006-08-16 14:52:44 +0000
committermwebster <mwebster>2006-08-16 14:52:44 +0000
commit4a53ac4202af0d7ee667474c7a1a4820e32a98cf (patch)
treeb7d36991acb37701624dcd5edf20d19ea5e90a92
parentbf17ebb5bbb02bb0279122b965d9af713fd59005 (diff)
downloadaspectj-4a53ac4202af0d7ee667474c7a1a4820e32a98cf.tar.gz
aspectj-4a53ac4202af0d7ee667474c7a1a4820e32a98cf.zip
Bug 150487 "Tracing and Logging Framework" (improve formatting for arrays and Collections)
-rw-r--r--weaver/src/org/aspectj/weaver/tools/AbstractTrace.java16
-rw-r--r--weaver/testsrc/org/aspectj/weaver/AbstractTraceTest.java27
2 files changed, 42 insertions, 1 deletions
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);
}