Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Strange thing when using a library of abstract aspects

Em Terça, 14 de Março de 2006 13:08, o Matthew Webster escreveu:

Hi Mathew,

> Paulo,
>
> The problem lies with the "exceptionClassesCorrectNames()" pointcut. What
> actually have is "within(pt.zenida.paulo.jar.test.*Exception)" because
> type names are fully qualified. If you move the aspect or the target class
> into a different package the pointcut won't match,

I changed the pointcut definition to this: within(*..*Exception); instead of 
simply within(*Exception); and now it seems to work. I though that the * 
would match anything behind of it, but I was wrong after all.

Thanks,

Paulo Zenida

>
> Matthew Webster
> AOSD Project
> Java Technology Centre, MP146
> IBM Hursley Park, Winchester,  SO21 2JN, England
> Telephone: +44 196 2816139 (external) 246139 (internal)
> Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
> http://w3.hursley.ibm.com/~websterm/
> Please respond to aspectj-users@xxxxxxxxxxx
> Sent by:        aspectj-users-bounces@xxxxxxxxxxx
> To:     aspectj-users@xxxxxxxxxxx
> cc:
> Subject:        Re: [aspectj-users] Strange thing when using a library of
> abstract        aspects
>
>
> Hello again,
>
> Once my previous e-mail is very long and also complicated, I will try to
> make
> it simpler. So, here's the situation:
>
> The ProjectToGenerateJar is the one that generates the JAR file to be used
> in
> other projects and it simply has an aspect, such as the one:
>
> // if the package is pt.zenida.paulo.test, then it will work!!!
> package pt.zenida.paulo.jar.test;
>
> public abstract aspect EnforceExceptionClassesNamingConventionAspect {
>
>                  public pointcut exceptionClassesCorrectNames() :
>                                  within(*Exception);
>
>                  public final pointcut invalidNamesForExceptionClasses() :
>
>                                  staticinitialization(Exception+) &&
>                                  !exceptionClassesCorrectNames();
>
>                  declare error :
>                                  invalidNamesForExceptionClasses() :
>                                                  "Exception classes should
> be suffixed with Exception.";
> }
>
> In the ProjectToUseGeneratedJar, I have two classes extending Exception:
> MyException and MyExceptionWithWrongName, and the following Aspect:
>
> // This does not work
> package pt.zenida.paulo.test;
>
> import
> pt.zenida.paulo.jar.test.EnforceExceptionClassesNamingConventionAspect;
>
> public aspect ConcreteEnforceExceptionClassesNamingConventionAspect
> extends
>  EnforceExceptionClassesNamingConventionAspect {
> }
>
> // But this works, if I had created the abstract Aspect in a package
> called
> "pt.zenida.paulo.test"
>
> package pt.zenida.paulo.test;
>
> public aspect ConcreteEnforceExceptionClassesNamingConventionAspect
> extends
>  EnforceExceptionClassesNamingConventionAspect {
> }
>
> Is this a bug or am I missing something?
>
> Cheers,
>
> Paulo Zenida
>
>
> Em Segunda, 13 de Março de 2006 21:48, o Paulo Alexandre Corigo Zenida
>
> escreveu:
> > Hello,
> >
> > I have a problem with using a library of abstract aspects in a project.
> > I would like to understand if this is a bug, because I'm not seeing any
> > other reason.
> >
> > Let us suppose we have a project called ProjectA with the following
> > structure:
> >
> > ProjectA
> >   src
> >     pt.zenida.paulo.common.pointcuts
> >       CommonPointcuts:
> >
> > public aspect CommonPointcuts {
> >
> >                public final pointcut all() : !none();
> >
> >                public final pointcut none();
> > }
> >
> >
> >     pt.zenida.paulo.projecta
> >       BaseAspect:
> >
> > import pt.zenida.paulo.common.pointcuts.*;
> >
> > public abstract aspect BaseAspect {
> >
> >                public pointcut scope() : !within(BaseAspect+);
> >
> >                public pointcut enableAdvice() :  !within(BaseAspect+);
> >
> >                public pointcut excludedPoints() :
> >                                CommonPointcuts.none();
> >
> >                public pointcut declareWarningScope() :
>
> CommonPointcuts.all();
>
> >                public final pointcut declareErrorScope() :
>
> !declareWarningScope();
>
> >                public pointcut declareSofteningExceptionScope() :
> >                                CommonPointcuts.all();
> >
> >                public final pointcut scopeWithExcludedPoints() :
> >                                scope() &&
> >                                !excludedPoints();
> > }
> >
> >       EnforceExceptionClassesNamingConventionAspect:
> >
> > public abstract aspect EnforceExceptionClassesNamingConventionAspect
> > extends BaseAspect {
> >
> >                public pointcut exceptionClassesCorrectNames() :
> >                                within(*Exception);
> >
> >                public final pointcut invalidNamesForExceptionClasses() :
> >                                staticinitialization(Exception+) &&
> >                                !exceptionClassesCorrectNames();
> >
> >                declare warning : declareWarningScope() &&
> >                                invalidNamesForExceptionClasses() &&
> >                                scopeWithExcludedPoints() &&
> >                                enableAdvice() :
> >                                                "Exception classes should
>
> be suffixed with Exception.";
>
> >                declare error : declareErrorScope() &&
> >                                invalidNamesForExceptionClasses() &&
> >                                scopeWithExcludedPoints() &&
> >                                enableAdvice() :
> >                                                "Exception classes should
>
> be suffixed with Exception.";
>
> > }
> >
> >       ConcreteEnforceExceptionClassesNamingConventionAspect:
> >
> > public aspect ConcreteEnforceExceptionClassesNamingConventionAspect
>
> extends
>
> > EnforceExceptionClassesNamingConventionAspect {
> >
> >                public pointcut scope() : within(A) ||
> > within(pt.zenida.paulo.thesis.test.convention.naming..*);
> > }
> >
> >     pt.zenida.paulo.projecta.test
> >       MyException (listing 5)
> >
> > public class MyException extends Exception {
> >
> > }
> >
> >       MyExceptionWithWrongName (listing 6)
> >
> > public class MyExceptionWithWrongName extends Exception {
> >
> > }
> >
> > The previous works just fine, with the compiler displaying a warning
> > message for the second class but not for the first one. However, if I
> > use two projects, creating a jar file with the Abstract aspect which is
> > included in the classpath of the second project, such as the following,
> > it issues a warning for both classes:
> >
> > ProjectA
> >   src
> >     pt.zenida.paulo.common.pointcuts
> >       CommonPointcuts:
> > (remains unchanged)
> >     pt.zenida.paulo.projecta
> >       BaseAspect:
> > (remains unchanged)
> >       EnforceExceptionClassesNamingConventionAspect:
> > (remains unchanged)
> >
> > ProjectB
> >   src
> >     pt.zenida.paulo.projectb
> >       ConcreteEnforceExceptionClassesNamingConventionAspect:
> >
> > import
> > pt.zenida.paulo.projecta.EnforceExceptionClassesNamingConventionAspect;
> >
> > public aspect ConcreteEnforceExceptionClassesNamingConventionAspect
>
> extends
>
> > EnforceExceptionClassesNamingConventionAspect {
> >
> >                public pointcut scope() :
>
> within(pt.zenida.paulo.projectb.test.*);
>
> > }
> >
> >     pt.zenida.paulo.projectb.test
> >       MyException:
> > (remains unchanged)
> >       MyExceptionWithWrongName:
> > (remains unchanged)
> >   lib
> >     projectA.jar
> >
> > Any ideas about what this might be? Am I missing something?
> >
> > Thanks in advance.
> >
> > Paulo Zenida
> >
> > ----------------------------------------------------------------
> > Mensagem enviada usando o IMP (Internet Messaging Program).
> >
> >
> > _______________________________________________
> > 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


Back to the top