Hi Eric -
Thanks for a well-worded question; you put a lot of work into the
investigation. Overall, annotation-style and code-style aspects should be
semantically the same, subject to the exceptions mentioned in the documentation
(including the aspectOf() method) and subject to any bugs in implementing
annotation-style. However, there is no guarantee that code-style and
annotation-style are implemented the same way. If the annotation-style
aspects didn't apply at all, I would suspect mistake in the build configuration
for that aspect.
The documentation on @AspectJ style aspects describes some differences from
code-style aspects, including the aspectOf method:
(See also exceptions for proceed(), privileged, thisJoinPoint, etc.)
We recommend against decompiling to understand AspectJ semantics because
the implementation techniques can vary between releases or styles of AspectJ and
because it's hard to do. More often than not, users find
"problems" -- things that shouldn't work (but actually do) -- because they
misinterpret the bytecode. In this case, you found a true difference in
the aspectOf() method, but one which would have been easier to understand
as an exception from reading the documentation.
(This is not to say the documentation is easy to read or complete; please
let us know when/where it isn't.)
Thanks -
Wes
------------Original Message------------
From: Eric Crahen <eric_crahen@xxxxxxxxx>
To: aspectj-dev@xxxxxxxxxxx
Date: Fri, Aug-4-2006 8:11 PM
Subject: [aspectj-dev] aspect keyword != @Aspect ? I'm having
difficulty understanding the difference between the aspect keyword and the
@Aspect annotation. According to the documentation the aspect keyword and the
@Aspect annotation are the same. In practice, this seems not to be true; or I
am making a giant
mistake.
http://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj.html
"The
use of the @AspectJ annotations means that there are large classes of AspectJ
applications that can be compiled by a regular Java 5 compiler, and
subsequently woven by the AspectJ weaver (for example, as an additional build stage, or as late as
class load-time). In this chapter we introduce the @AspectJ annotations and
show how they can be used to declare aspects and aspect members."
The
example on the next page reenforces this notion:
"The declaration: @Aspect
public class Foo {}
Is equivalent to: public aspect Foo {} "
So that's
why I think these two methods should produce equivalent results, below is why
I'm finding they do not:
The two simple examples show below do not
produce equivalent output. Its easy to see after building each separately and
dumping the class signatures with javap, its easy to see there are lots of
generated methods added to the TestAspect.class from sample #1, sample #2 on
the other hand doesn't contain any of these things.
// Sample #1 // TestAspect.java public
aspect TestAspect {
@Pointcut("execution(* *(..))") public
void pc() {}
@Before("pc()") public void beforePc() { }
}
// Sample #2 // TestAspect.java @Aspect public class TestAspect {
@Pointcut("execution(* *(..))")
public void pc() {}
@Before("pc()") public void
beforePc() { }
}
If I take it a step further
and actually apply the aspect to a simple HelloWorld example with the compile
time weaver. The first version using the keyword runs just fine. Dumping the
code with javap I can confirm that the aspect was woven into the class. The
second version using the aspect does not work. The HelloWorld program
references methods that are not actually generated for the aspect version
(TestAspect.aspectOf() for example).
I haven't attempted load time
weaving, but I will not be using this in my appliciation.
I am
building this all with the iajc ant task.
Can anyone explain what I'm
doing wrong?
- Eric
See the all-new, redesigned Yahoo.com. Check it
out. _______________________________________________ aspectj-dev
mailing list aspectj-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/aspectj-dev
|