Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Not matching constructors

Hi Howard,

The AJDT plugin sometimes doesn't do incremental compilation correctly, so
if you ever see odd behavior like this try doing a full rebuild (either with
clean & build or by adding the AspectJ rebuild project button (*)). This
should show you a consistent picture of what's happening. 

However, I'd recommend you use the latest development build of AJDT since
incremental compilation in AspectJ has improved a lot since 1.5.0 and you
should see much more accurate information if you do.

Ron

(*) Use window | preference customize perspective, select commands and then
check AspectJ Actions to see this button and the open AspectJ type button.

-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Howard Lewis Ship
Sent: Thursday, March 30, 2006 10:48 PM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Not matching constructors

Ok. What I'm really seeing is the AspectJ plugin not working
correctly. Hard to say whether its a compile problem, or just an issue
with how the IDE updates, but commenting and uncommenting lines in my
aspect really change the state of things. It's weird. Perhaps I'll
have an Aha! moment about what I'm doing wrong.

BTW ... what's the consensus on using the "old" style (.aj files) vs.
writing "new" style, as ordinary classes w/ AspectJ annotations?

On 3/30/06, Howard Lewis Ship <hlship@xxxxxxxxx> wrote:
> Hm. They each work properly, seperately. They just don't work together.
>
> On 3/30/06, Howard Lewis Ship <hlship@xxxxxxxxx> wrote:
> > Hm. I changed it to:
> >
> >     pointcut codeNotMarkedAsSuppressed() :
> >         execution(!@SuppressNullCheck * *(..)) ||
> >         execution(!@SuppressNullCheck new(..));
> >
> >
> > And now it no longer matches any of my methods.
> >
> > On 3/30/06, Ramnivas Laddad <ramnivas@xxxxxxxxxxxxxxx> wrote:
> > > Howard,
> > >
> > > To match constructors, you will need to use a form of execution()
> > > pointcut that takes a constructor signature. You do so by using
special
> > > method name 'new' and not specifying the return type. So you will need
> > > to modify the codeNotMarkedAsSuppressed() as follows:
> > >
> > > pointcut codeNotMarkedAsSuppressed() :
> > >     execution(!@SuppressNullCheck * *(..))
> > >     || execution(!@SuppressNullCheck new(..)));
> > >
> > >
> > > -Ramnivas
> > >
> > >
> > > Howard Lewis Ship wrote:
> > > > I'm trying out some ideas using AspectJ 5.  I'm working in Eclipse
> > > > 3.1, with the current plugin (1.3.1.2006 etc.).
> > > >
> > > > As an experiment, I'm writing a Defense Coding aspect, that
determines
> > > > if any method
> > > > parameters are null. Further, the check can be defeated at the class
> > > > or method/constructor level with an annotation.
> > > >
> > > > My pointcut is matching methods (static and instance) properly:
> > > >
> > > > public aspect CatchNullParameters
> > > > {
> > > >     pointcut typeNotMarkedAsSuppressed() :
!within(@SuppressNullCheck Object+);
> > > >
> > > >     pointcut appliesToClasses() :
within(com.howardlewisship.ajexp..*);
> > > >
> > > >     pointcut codeNotMarkedAsSuppressed() :
> > > > execution(!@SuppressNullCheck * *(..));
> > > >
> > > >     pointcut methodsToCheck()  :
> > > >         appliesToClasses() &&
> > > >         typeNotMarkedAsSuppressed() &&
> > > >         codeNotMarkedAsSuppressed();
> > > >
> > > >     before() : methodsToCheck() {
> > > >         Object[] args = thisJoinPoint.getArgs();
> > > >
> > > >         for (int i = 0; i < args.length; i++)
> > > >         {
> > > >             if (args[i] == null)
> > > >             {
> > > >                 String message = String.format(
> > > >                         "Parameter #%d passed to method %s (at %s)
was null.",
> > > >                         i + 1,
> > > >                         thisJoinPoint.getSignature().toString(),
> > > >                         thisJoinPoint.getSourceLocation());
> > > >
> > > >                 System.err.println(message);
> > > >
> > > >                 throw new IllegalArgumentException(message);
> > > >             }
> > > >         }
> > > >     }
> > > > }
> > > >
> > > > However, I can't seem to get it to apply to my constructors. The
> > > > documentation seems to state that execution() matches methods and
> > > > constructors, but I'm not seeing it.
> > > >
> > > > Any clues as to what I'm missing?
> > > >
> > > > --
> > > > Howard M. Lewis Ship
> > > > Independent J2EE / Open-Source Java Consultant
> > > > Creator, Jakarta Tapestry
> > > > Creator, Jakarta HiveMind
> > > >
> > > > Professional Tapestry training, mentoring, support
> > > > and project work.  http://howardlewisship.com
> > > > _______________________________________________
> > > > aspectj-users mailing list
> > > > aspectj-users@xxxxxxxxxxx
> > > > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > > >
> > > >
> > > _______________________________________________
> > > aspectj-users mailing list
> > > aspectj-users@xxxxxxxxxxx
> > > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> > >
> >
> >
> > --
> > Howard M. Lewis Ship
> > Independent J2EE / Open-Source Java Consultant
> > Creator, Jakarta Tapestry
> > Creator, Jakarta HiveMind
> >
> > Professional Tapestry training, mentoring, support
> > and project work.  http://howardlewisship.com
> >
>
>
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
>
> Professional Tapestry training, mentoring, support
> and project work.  http://howardlewisship.com
>


--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top