[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Not matching constructors
|
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