Skip to main content

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

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).




Back to the top