Skip to main content

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

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 +++


Back to the top