Testing a navigation

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
Here is a two-file application called HelloWorld - with an Aspect which prints "Tracing" to show that the aspect has been applied. Load into Eclipse with the AJDT and you can see the aspect getting applied. For this example the AjLib jar is extracted into the project also. The src to the example is attached - see the attachments tab.

HellowWorld.java:

{color:#7f0055}*package*{color} com.AjlibTest;
{color:#7f0055}*public*{color} {color:#7f0055}*class*{color} HelloWorld
{
    {color:#7f0055}*public*{color} {color:#7f0055}*static*{color} {color:#7f0055}*void*{color} main(String\[\] args)
    {
        DummyObject dummyObject = {color:#7f0055}*new*{color} DummyObject();
        dummyObject.someMethod(5);
    }
}

DummyObject.java:

{color:#7f0055}*package*{color} com.AjlibTest;
{color:#7f0055}*public*{color} {color:#7f0055}*class*{color} DummyObject
{
    {color:#7f0055}*public*{color} {color:#7f0055}*int*{color} someMethod({color:#7f0055}*int*{color} i)
    {
        {color:#7f0055}*return*{color} 7;
    }
}

TestTraceAspect.aj:
{color:#7f0055}*package*{color} com.AjlibTest;
{color:#7f0055}*import*{color} org.codehaus.ajlib.util.tracing.ExecutionTracing;
{color:#7f0055}*public*{color} {color:#7f0055}*aspect*{color} TestTraceAspect {color:#7f0055}*extends*{color} ExecutionTracing
{
    {color:#7f0055}*public*{color}  pointcut scope() :within(DummyObject);
    before(): scope()
   
{         
System.out.println("Tracing");      }
}
With AjLib extracted along with the src into a single eclipse project for the purposes of this example, the resulting directory strructure looks like this:
org\codehaus\ajlib\util\tracing\AbstractTracing.aj
org\codehaus\ajlib\util\tracing\BasicTraceFormatter.aj
org\codehaus\ajlib\util\tracing\CustomTraceable.aj
org\codehaus\ajlib\util\tracing\ExecutionTracing.aj
org\codehaus\ajlib\util\tracing\ExtensibleTracing.aj
org\codehaus\ajlib\util\tracing\GuardTracing.aj
org\codehaus\ajlib\util\tracing\Log4jExecutionTracing.aj
org\codehaus\ajlib\util\tracing\Log4jTracer.aj
org\codehaus\ajlib\util\tracing\NotTraced.aj
org\codehaus\ajlib\util\tracing\PerThreadTracer.aj
org\codehaus\ajlib\util\tracing\PrintStreamTracer.aj
org\codehaus\ajlib\util\tracing\StandardPointcuts.aj
org\codehaus\ajlib\util\tracing\TraceFormatter.aj
org\codehaus\ajlib\util\tracing\Tracer.aj
org\codehaus\ajlib\util\tracing\XMLTraceFormatter.aj
com\AjlibTest\TestTraceAspect.aj
com\AjlibTest\DummyObject.java
com\AjlibTest\HelloWorld.java

This is the output produced to the console from running this example:

Tracing
Tracing
Tracing
Tracing
trace enter: com.AjlibTest.DummyObject() , this: com.AjlibTest.DummyObject@7a84e4
trace exit: com.AjlibTest.DummyObject()
Tracing
trace enter: int com.AjlibTest.DummyObject.someMethod(int) , this: com.AjlibTest.DummyObject@7a84e4, args: arg 0 = 5
trace exit: int com.AjlibTest.DummyObject.someMethod(int), return = 7