Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Set scope for code in advice to join point's target

You can't get AspectJ to do that in the advice code. However, you can
put the contents of your advice into another method, then use
intertype declaration to make that method a member of class Foo:

public aspect FooAspect {
    before(Foo f): call(void Foo.doSomething()) && target(f) {
    	f.advice();
    }

    void Foo.advice() {
        // magic construct
        doSomethingElse();
        System.out.println("Some String");
        doAnotherThing();
    }
}

HTH.

dean

--
Dean Wampler
http://www.aspectprogramming.com
http://www.newaspects.com
http://www.contract4j.org

On 2/12/06, Michael Herrmann <Michael_Herrmann@xxxxxx> wrote:
> Hello again,
>
> is it possible to set the scope for the execution of some code in an advice
> to the join point's target (I hope I've used the technical terms correctly)?
> Let's assume I have a class Foo:
>
> public class Foo {
>         public void doSomething() {
>                 // ...
>         }
>
>         public void doSomethingElse() {
>                 // ...
>         }
>
>         public void doAnotherThing() {
>                 // ...
>         }
> }
>
> and the corresponding aspect, FooAspect:
>
> public aspect FooAspect {
>         before(Foo f): call(void Foo.doSomething()) && target(f) {
>                 f.doSomethingElse();
>                 System.out.println("Some String");
>                 f.doAnotherThing();
>         }
> }
>
> I now want to avoid having to write f. ... everytime. Rather, I'd like to
> tell AJ to execute a set of statements in the context of f. In other words:
> I want to execute a set of statements as if they were directly written in
> the source code of Foo:
>
> public aspect FooAspect {
>         before(Foo f): call(void Foo.doSomething()) && target(f) {
>                 // magic construct
>                 doSomethingElse();
>                 System.out.println("Some String");
>                 doAnotherThing();
>         }
> }
>
> I hope you understand what I mean. Thank you very much in advance,
> Michael Herrmann
>
> --
> 10 GB Mailbox, 100 FreeSMS/Monat http://www.gmx.net/de/go/topmail
> +++ GMX - die erste Adresse für Mail, Message, More +++
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


--
Dean Wampler
http://www.aspectprogramming.com
http://www.newaspects.com
http://www.contract4j.org


Back to the top