Skip to main content

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

You were almost there.

Define non-static members on the interface type:

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

    // implementation
    public void Callback.notification() {
	System.out.println("here is the callback");
       // here "this" has static type Callback
       // regardless of the actual class
    }
}

// volunteer
class C implements Callback {}
---------
For more, check out the sample-code linked off the publications page.

Wes

Nick Airey wrote:
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.


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top