Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Library of Abstract Aspects

Hi -

Your instincts are right that declare-error should work when the pointcuts
are defined in a subaspect.

Here it is unclear to me what worked and what didn't:

> However, since they are aspects from the same library, it makes 
> sense that the precedence coordination comes with that library. I had 
> created a concrete aspect in it and tried to apply it. It worked for 
> one case but it didn't in the other one!!!

Remember that a subaspect has precedence over a superaspect.  This came
up in https://bugs.eclipse.org/bugs/show_bug.cgi?id=124100.


wrt "forbidPackageNames()", I don't see the bug/problem offhand, but you 
might try using staticinitialization() rather than within() to avoid
checking every possible join point, and then use within() to declare scope.
Also, I'm not sure why you have "within(*) && ...".  So try something like

  public pointcut initCapitaledPackageType() :
    staticinitialization(*A*..*) ||
    staticinitialization(*B*..*) ||
  ...

But that would only capture capitals in the initial name, not
"org.ASPECTJ.stuff.Foo".  So you'd need

    staticinitialization(*A*..*) ||
    staticinitialization(*..*A*..*) ||
    ...

I'd recommend getting the declare-warning to work first on offending and
non-offending classes and then extend it through the alphabet.

hth - Wes

> ------------Original Message------------
> From: Paulo Alexandre Corigo Zenida <paulo.zenida@xxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Mon, Feb-27-2006 1:08 PM
> Subject: [aspectj-users] Library of Abstract Aspects
>
> Hello,
> 
> I have a library of abstract aspects which I use in two different 
> projects. To do that, I have created a .jar file containing the library 
> 
> and put in the classpath of my two projects. Then, I simply extend the 
> abstract aspects and define their scope providing a definition for the 
> scope pointcut. For example:
> 
> public aspect MyConcreteAspect extends MyAbstractAspectFromTheLibrary {
> 
>      public pointcut scope() :          within(pt.zenida.paulo..);
> }
> 
> So far, so good. And, testing the aspects separatedly, everything seems 
> 
> to be working. Then, I tried to apply them all and I had a problem with 
> 
> precedence. I have two Aspects (one related to resource pooling and 
> another one related to transaction management - adaptations from the 
> wonderful book, AspectJ in Action) and they apply to the same join 
> point (the closing resource one). So, I had created an aspect to define 
> 
> the precedence between them (the transaction one must have less 
> precedence than the resource pooling one). To do that, I had put the 
> Aspect in the two projects where the library had been applied. It did 
> work! However, since they are aspects from the same library, it makes 
> sense that the precedence coordination comes with that library. I had 
> created a concrete aspect in it and tried to apply it. It worked for 
> one case but it didn't in the other one!!!
> 
> And there is also a second strange thing: I have an Aspect that tries 
> to enforce the allowed names for package names (basically, forbids any 
> package identifier with an upper case character - the caveat here is 
> that it also applies to inner classes; is this a limitation for the 
> current feature?). When I extend the Aspect and define its scope, it 
> simply doesn't seem to work. However, if I put the definition of the 
> pointcut in the concrete aspect, it works. Let me better demonstrate 
> this with a snippet of the code:
> 
> public abstract aspect CoordinateProjectPackageNameAspect extends 
> BaseAspect {
> 
> 	public pointcut forbidPackageNames() :
> 		within(*) &&
> 		within(*A*..*) ||
> 		within(*B*..*) ||
> 		within(*C*..*) ||
> 		within(*D*..*) ||
> 		within(*E*..*) ||
> 		within(*F*..*) ||
> 		within(*G*..*) ||
> 		within(*H*..*) ||
> 		within(*I*..*) ||
> 		within(*J*..*) ||
> 		within(*K*..*) ||
> 		within(*L*..*) ||
> 		within(*M*..*) ||
> 		within(*N*..*) ||
> 		within(*O*..*) ||
> 		within(*P*..*) ||
> 		within(*Q*..*) ||
> 		within(*R*..*) ||
> 		within(*S*..*) ||
> 		within(*T*..*) ||
> 		within(*U*..*) ||
> 		within(*V*..*) ||
> 		within(*W*..*) ||
> 		within(*X*..*) ||
> 		within(*Y*..*) ||
> 		within(*Z*..*);
> 
> 	declare warning :
>                   // this defines the scope for application and the 
> points that
>                   // should be ignored, such as any inner class!
> 		scopeWithExcludedPoints() &&
> 		forbidPackageNames() : 			"Names representing packages should be in 
> all lower case";
> 
> }
> 
> public aspect ConcreteCoordinateProjectPackageNameAspect extends
> 		CoordinateProjectPackageNameAspect {
> 
> 	public pointcut scope() : 
> 		within(pt.zenida.paulo.thesis.test.convention.naming..*);
> 
> 	public pointcut excludedPoints() : 
> 		within(pt.zenida.paulo.thesis.test.convention.naming.A.MyException) 
> ||
> 		
> within(pt.zenida.paulo.thesis.test.convention.naming.A.MyExceptionWithIncorrectName);
> 
>          // this only works if I define this here. If not, it simply 
> does not
>          // apply to any case. Why?
> 	public pointcut forbidPackageNames() :
> 		within(*) &&
> 		within(*A*..*) ||
> 		within(*B*..*) ||
> 		within(*C*..*) ||
> 		within(*D*..*) ||
> 		within(*E*..*) ||
> 		within(*F*..*) ||
> 		within(*G*..*) ||
> 		within(*H*..*) ||
> 		within(*I*..*) ||
> 		within(*J*..*) ||
> 		within(*K*..*) ||
> 		within(*L*..*) ||
> 		within(*M*..*) ||
> 		within(*N*..*) ||
> 		within(*O*..*) ||
> 		within(*P*..*) ||
> 		within(*Q*..*) ||
> 		within(*R*..*) ||
> 		within(*S*..*) ||
> 		within(*T*..*) ||
> 		within(*U*..*) ||
> 		within(*V*..*) ||
> 		within(*W*..*) ||
> 		within(*X*..*) ||
> 		within(*Y*..*) ||
> 		within(*Z*..*);
> }
> 
> 
> Any ideas about what this might be?
> 
> Thanks in advance. Best regards,
> 
> 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
> 



Back to the top