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!

I would say that the only difference is that "classical" aspect writting has been tested for years already, while the annotation-based aspect writting is quite a new (and very nice) beast.

./alex
--
.w( the_mindstorm )p.

#: Howard Lewis Ship changed the world a bit at a time by saying (astral date: 3/31/2006 9:48 AM) :#
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