Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] static croscutting introduction problem

Hi everyone, 

I would like to use static croscutting to introduce an interface to some
classes, and also to provide an implementation of some of the interface
methods in a generic way. [this is sort-of simulating multiple inheritance
in java] 

eg. suppose I have a Callback interface which is part of a framework:

interface Callback {
   public void notification();
}

Now, let's say I want to apply this aspect to two classes, ClassA and
ClassB.

I tried to do something like this:

aspect CallbackHandler {
    declare parents: (ClassA||ClassB) implements Callback;

    public void (ClassA||ClassB).notification() {
	System.out.println("here is the callback");
    }
}

I would expect that the aspect compiler magic would result in ClassA and
ClassB implementing Callback, and also implementing the notification()
method.

The delcare parents line is ok, as it takes a type pattern, but definition
of the "notification()" method is a compiler error. Is there any way to
achieve this?  Note: this is a simplified example - in the real case there
may be 20-30 classes in requiring this functionality.

As an extension to this question, lets say that ClassA and ClassB implement
a marker interface, lets say "interface Marker". Is there any way that I can
get the aspect compiler to do the static introductions (parents and method
declaration) to all classes implementing interface Marker?

Thanks and kind regards,
Nick.


ps. thanks to Ron for answering my previous question.




Back to the top