[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Inter-Type Declaration Help Needed

My attempt at trying to implement what I understand from your
question, note though I am a newbie

public interface Foo {
    public void doFoo();
}

public interface Bar {
    public void doBar();
}

public class FooImpl implements Foo {
    public void doFoo() {
        System.out.println("you got fooed");
    }
}

public class BarImpl implements Bar {
    public void doBar() {
        System.out.println("you got barred");
    }
}

import foo.Foo;
import bar.Bar;
import bar.BarImpl;

public aspect FooBar {
    declare parents : Foo extends Bar;

    public void Foo.doBar() {
       Bar bar = new BarImpl();
       bar.doBar();
    }
}

import bar.Bar;
import foo.Foo;
import foo.FooImpl;

public class Main {
    public static void main(String[] args) {
        Foo foo = new FooImpl();
        foo.doFoo();
        ((Bar)foo).doBar();
    }
}

Result of running Main

you got fooed
you got barred

Hope that helps

Bhaskar




On Dec 12, 2007 11:40 AM, Kevin Shale <Shale@xxxxxx> wrote:
> Hi, I am a relative newbie to AspectJ and I have a problem to solve.
>
> In Java I have two interfaces A and B which are not related to each other via extends.
>
> Each interface has a number of concrete implementation classes.
>
> I am looking for a way to use AspectJ to force every class which implements interface B to also implement interface A with methods defined in the aspect.
>
> How would I go about programming this?
>
> Best Regards
> Kevin
> _______________________________________________________________________
> Jetzt neu! Schützen Sie Ihren PC mit McAfee und WEB.DE. 3 Monate
> kostenlos testen. http://www.pc-sicherheit.web.de/startseite/?mc=022220
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>