[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] cflow(within(C)) vs (within(C) || cflowbelow(within(C))
|
I am new to AspectJ and is just trying to understand what each kind of
pointcut matches. So I wrote a simple class, SomeClass, and a simple
aspect, TraceClass, and was hoping that the aspect would print out all
the join points in SomeClass. To avoid infinite recursion, in
TraceClass I used "!cflow(within(Trace*))" as the pointcut. However, I
was not getting any output. Though "!(within(Trace*) ||
cflowbelow(within(Trace*)))" worked as I expected (printing something).
(From the post "cflow ( x()) && !cflowbelow( x()) " confusesme" I
gathered that cflow(x()) does not equal to (x() || cflowbelow(x())).
However, I still don't understand why my test doesn't work).
class SomeClass
{
static public void main (String [] args) {
}
} // SomeClass
aspect TraceClass {
// members
static private int level = 0;
static private void offset() {
int i;
for (i = 0; i < level; ++i) {
System.out.print(" ");
}
} // offset
pointcut pc() :
!cflow(within(Trace*))
// !(within(Trace*) || cflowbelow(within(Trace*)))
;
before () : pc() {
offset();
System.out.println("-> " + thisJoinPoint);
++level;
}
after () : pc() {
--level;
offset();
System.out.println("<- " + thisJoinPoint);
}
} // TraceClass
In order to figure out what is happening with TraceClass, I added a
third class, TraceTrace, which prints everything happen
"within(TraceClass)". Again, when TraceClass used "!(within(Trace*) ||
cflowbelow(within(Trace*)))" it worked. However, when TraceClass used
"!cflow(within(Trace*))", the output was
=> staticinitialization(TraceClass.<clinit>)
=> set(int TraceClass.level)
<= set(int TraceClass.level)
=> preinitialization(TraceClass())
=> initialization(TraceClass())
=> execution(TraceClass())
<= execution(TraceClass())
<= initialization(TraceClass())
<= staticinitialization(TraceClass.<clinit>)
The after advice for preinitialization was never executed and no trace
for SomeClass was printed.
aspect TraceTrace {
// members
static private int level = 0;
static private void offset() {
int i;
for (i = 0; i < level; ++i) {
System.out.print(" ");
}
} // offset
pointcut pc() : within(TraceClass);
before () : pc() {
offset();
System.out.println("=> " + thisJoinPoint);
++level;
}
after () : pc() {
--level;
offset();
System.out.println("<= " + thisJoinPoint);
}
} // TraceTrace
I use
AspectJ Compiler 1.2 built on Friday May 21, 2004 at 15:06:22 GMT
and
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)
Thanks,
Chi-Hua