Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Mixins in AspectJ5

Hi Binil,

 

AspectJ supports inter-type declarations, e.g.,:

 

public aspect MyAspect {

    public interface Fooable {}

 

    public void Fooable.foo() {

        System.out.println(“Test”);

    }


    declare parents: Interface+ implements Fooable;
}

If you want to have implementers of an interface extend a mixin, you could use an idiom like this:

    declare parents: Interface+ && !Interface extends IntroductionImpl;

However, if you have interfaces that extend Interface, this won’t work. This is a place where it would be helpful to have a type pattern like !isInterface() (an old issue that’s tracked in bugzilla)…

 


From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Binil Thomas
Sent: Tuesday, February 28, 2006 5:11 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Mixins in AspectJ5

 

Hi all,

I have been using AspectWerkz for a while, and am now moving to AspectJ5. Does AspectJ5 have support for mixins the way AspectWerkz did?

For instance, consider:
    public interface Interface { }
    public class InterfaceImpl
        extends javax.swing.JFrame implements Interface { }
    public interface Introduction { }
    public class IntroductionImpl implements Introduction { }

If I have an aspectwerkz XML definition as:
    <mixin
        class="IntroductionImpl"
        deployment-model="perClass"
        bind-to="within(Interface+)"/>
    
The code:
    InterfaceImpl imp = new InterfaceImpl();
    if (imp instanceof Introduction) {
        System.out.println( "Mixin worked" );
    } else {
        System.out.println( "Mixin didnt work" );
    }
would print "Mixin worked".

How do I create a similar effect using AspectJ5?

public aspect MyAspect {
    declare parents: Interface+ extends IntroductionImpl;
}

gives me syntax a error.

[error] interface can not extend a class
declare parents: Interface+ extends IntroductionImpl;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When I tried:
public aspect MyAspect {
    declare parents: Implementation extends IntroductionImpl;
}

I get the error:
[error] can only insert a class into hierarchy, but IntroductionImpl is not a subtype of javax.swing.JFrame
declare parents: Implementation extends IntroductionImpl;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Can a mixin as the one I wanted, be expressed in AspectJ5? If so, what is the correct syntax for expressing it?

Thanks,
Binil


Back to the top