Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Capturing extending classes in compile time?

AspectJ doesn't yet support modifiers in type patterns, so there is no direct way to match abstract or final types (you can punt to an "if" pcd, but it's not as elegant and you can't do it statically). There is also no way to match based on the potential existence of subclasses (that would require making a "whole program" assumption which AspectJ doesn't do).  If we supported modifiers in type patterns, you could write something like:

staticinitialization(!final !abstract *)

which would get you what you wanted I believe.

On the second question, there is also no way to restrict pointcuts to only using certain pcds (we're not doing very well with your requirements today, sorry!!). Another considered extension to the language - named type patterns - would address this situation. Suppose that we could declare "typecuts' (name plucked out of thin air) in the same way that we declare pointcuts. A typecut matches a type in the same way that a pointcut matches a join point.

Then you would write:

     public abstract aspect A {

          // Specification of the allowed JPI - only possible to use withins!
          public abstract typecut matchedType;


          // other pointcuts in A written in terms of the abstract typecut, eg.
          pointcut interestingJoinPoint() : somePC() && within($typecut);
     }

     public aspect B extends A {

         public typecut matchedType : org.xyz..*;
 
     }

The best you can do today is to restrict matching only to certain join point kinds, by &&ing with a match-all pcd of the desired kind in the abstract aspect. E.g.

   public abstract aspect A {

      pointcut aHandler() : handler(*);

      abstract pointcut scope();

      // some advice, which applies in scope, but only to join points that are handler join points
      before() : scope() && aHandler() {
       ...
      }

   }

  And finally... there is no way to override the messages produced by declare warning / error.

  Regards, Adrian.

On 11/01/06, Paulo Alexandre Corigo Zenida <paulo.zenida@xxxxxxxx> wrote:
Good afternoon,

    I am trying to create a library of good programming policies and,
in the institution I'm working on, someone invoked one that could be
useful, which would be something like the following:

         - Classes that don't have subclasses should be declared as final
         - Classes that have subclasses should be declared as abstract,
and therefore, not able to be instantiated (this way, only the derived
classes can be instantiated. The example this person invoked was the
Human Being to be abstract and the subclasses Man and Woman being the
derived ones).

    Is there a way to enforce this in compile time? I managed to check
for a class's superclass in runtime, by using reflection. But what I
really would like to do, would be capturing this in compile time. Is
there a way to say something like "capturing the classes that have an
extends clause in its declaration"?

    Another question would be the following:

          - By creating a library of abstract aspects that can be used
in real projects, I have to create some abstract pointcuts that, later,
have to derived and defined in the derived aspects, for that project.
However, in certain cases, the use of some join points intersection
like execution doesn't work, because it's necessary to provide
something like within. Is is possible to explicitly say the allowed
things to put in a certain pointcut, just like we do with Annotations,
by specifying where they can be applied? Something like the following:

     public abstract aspect A {

          // Specification of the allowed JPI - only possible to use withins!
          public abstract pointcut shouldBeOnlyWithins();

     }

     public aspect B extends A {

          public pointcut shouldBeOnlyWithins() :
                within(ClassA) || // Valid
                within(ClassB+) || // Valid
                execution(*.new(..)); // Invalid -> a compilation error!
     }

     Finally, I would also like to know if it's possible to override
warning / error messages. For example:

     public abstract aspect A {

          // ...

          declare warning :                onePointcut() :
     "My message";

          // The following does not work, unfortunatelly
          public final String MY_STRING = "My message";

          declare warning :                otherPointcut() :
         MY_STRING;

     }

     public aspect B extends A {

          public pointcut otherPointcut() :                  A.otherPointcut()
                  // && ...;

          public final String MY_STRING = "My new message";
     }

     And, by using this, the warning message would be the one defined
in the derived aspect. Is there a way to do this?


    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



--
-- Adrian
adrian.colyer@xxxxxxxxx

Back to the top