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 {
|| 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() */
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
*******************************************************************************/
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;
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);
}