diff options
author | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2002-12-16 18:51:06 +0000 |
commit | 144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch) | |
tree | b12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/tracing | |
parent | fafae443719b26159ab2d7dac1c9b46b5e00b671 (diff) | |
download | aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip |
initial version
Diffstat (limited to 'tests/tracing')
-rw-r--r-- | tests/tracing/TraceJoinPoints.java | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/tracing/TraceJoinPoints.java b/tests/tracing/TraceJoinPoints.java new file mode 100644 index 000000000..095172c28 --- /dev/null +++ b/tests/tracing/TraceJoinPoints.java @@ -0,0 +1,104 @@ + +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; +import java.io.*; + +/** + * Produces an XML representation of all of the join points in a program + * within the control-flow of those points matching <code>entry</code>. + * + * To use this, extend this aspect and fill in an appropriate value for + * <code>entry</code>. + */ +public abstract aspect TraceJoinPoints dominates * { + /** + * The join points which mark the entry of the traced control-flow. + * To trace all command-line programs, set this to: + * <pre>call(public static void main(String[]));</pre> + */ + protected abstract pointcut entry(); + + /** + * Join points which mark an exit from the control-flow. Use this + * to exclude parts of the call-graph that you're not interested in. + * The default value matches the current implementation limitation + * (in ajc-1.0) that join points within system libraries are not + * visible. + */ + protected pointcut exit(): call(* java..*.*(..)); + + final pointcut start(): entry() && !cflowbelow(entry()); + + final pointcut trace(): + cflow(entry()) && !cflowbelow(exit()) && !within(TraceJoinPoints+); + + before(): start() { makeLogStream(); } + + before(): trace() { logEnter(thisJoinPointStaticPart); } + after(): trace() { logExit(thisJoinPointStaticPart); } + + after(): start() { closeLogStream(); } + + + PrintStream out; + int logs = 0; + protected void makeLogStream() { + try { + out = new PrintStream(new FileOutputStream("log" + logs++ + ".xml")); + } catch (IOException ioe) { + out = System.err; + } + } + + protected void closeLogStream() { + out.close(); + } + + + int depth = 0; + boolean terminal = false; + protected void logEnter(JoinPoint.StaticPart jp) { + if (terminal) out.println(">"); + indent(depth); + out.print("<" + jp.getKind()); + writeSig(jp); + writePos(jp); + + depth += 1; + terminal = true; + } + + void writeSig(JoinPoint.StaticPart jp) { + out.print(" sig="); + out.print(quoteXml(jp.getSignature().toShortString())); + } + + void writePos(JoinPoint.StaticPart jp) { + SourceLocation loc = jp.getSourceLocation(); + if (loc == null) return; + + out.print(" pos="); + out.print(quoteXml(loc.getFileName() + + ":" + loc.getLine() + + ":" + loc.getColumn())); + } + + String quoteXml(String s) { + return "\"" + s.replace('<', '_').replace('>', '_') + "\""; + } + + protected void logExit(JoinPoint.StaticPart jp) { + depth -= 1; + if (terminal) { + out.println("/>"); + } else { + indent(depth); + out.println("</" + jp.getKind() + ">"); + } + terminal = false; + } + + void indent(int i) { + while (i-- > 0) out.print(" "); + } +} |