Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[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