Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Frustrated Newbie

Title: Frustrated Newbie
If you look at the "gutter annotations" in Eclipse with these various declare error statements, you probably noticed that the "A" error only flagged the declaration line of your Listener interface(s). Interfaces don't have any code for the methods they declare, so there are no join points. It also appears that "A" doesn't flag any implementing classes or extending interfaces.

However, I did find one trick that seems to work. If Listener and Foo are in different packages, "listener" and "foo", respectively, the following seems to work:

declare error: within(*..listener.*+) && !within(*..listener.*) && !within(*..foo.*+): "message";

The second subexpression, !within(*..listener.*) prevents an error being reported on Listener itself, since it obviously doesn't implement Foo.

Not too obvious and maybe it's not convenient to organize your packages this way, but it seems to work.

dean

Kevin F wrote:
I’ve been at this for 4 days now.  I had some good luck with a few initial cases where I was able to clean up some code and verify through testing it worked like a charm.  I made a couple minor tweaks to those which broke them giving the technology an unreliable feel.  I’m willing to write that off as inexperience.

So I continued on and tried to implement some simple enforcement policies that I read in the book from the Eclipse Series (trying to support development by buying products and all).  It isn’t working at all and my frustration level trying to implement even simple enforcement policies is off the scale.

Yesterday, I posted the following to the AspectJ newsgroup without a response yet.  I continued researching on my own, even using the latest milestone AspectJ release for Eclipse 3.3M5.  Still no luck.

---------------
Newsgroup post:
---------------

I'm new to AspectJ so please no flames.  I'm using AJDT for Eclipse 3.2.1
and have been following the details from the "eclipse AspectJ" book.

I'm trying to enforce simple errors such as "It is an error to implement any
listener interface unless you also implement interface Foo."  To do this, I
want to try:

pointcut listeners() : within(*..*Listener*+);
pointcut myCode() : within(com.mycompany..*+);
pointcut mySpecialInterface() : within(com.mycompany.Foo+);
declare error: listeners() && myCode() && !mySpecialInterface()
             : "All listeners must implement Foo";


Since this did not work, I tried various experiments.  So, I tried the
following:

declare error: within(*..*Listener*+)
             : "A";
declare error: within(com.mycompany..*+)
             : "B";
declare error: within(*..*Listener*+) && within(com.mycompany..*+)
             : "A intersect B";
declare error: within(*..*Listener*+ && com.mycompany..*+)
             : "A intersect' B";
declare error: within(*..*Listener*+) || within(com.mycompany..*+)
             : "A union B";
declare error: within(*..*Listener*+ || com.mycompany..*+)
             : "A union' B";

A seems to be tagged correctly on all classes that implement any interface
with the word Listener in its name.

B seems to tag only a fraction of the classes I have written.

A intersect B and A intersect' B both result in no tags.

A union B and A union' B both seem to result in the union of what A and B
tagged above.


AOP seems so powerful yet so cryptic.  Can anybody help?


_______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/aspectj-users


--
Dean Wampler's Signature Dean Wampler, Ph.D.
dean at aspectprogramming.com
objectmentor.com
aspectprogramming.com
contract4j.org

I want my tombstone to say:
Unknown Application Error in Dean Wampler.exe.
Application Terminated.

Back to the top