From 144143c2970a1e874d74cdbd0f8c622d4282a3c3 Mon Sep 17 00:00:00 2001 From: wisberg Date: Mon, 16 Dec 2002 18:51:06 +0000 Subject: initial version --- tests/new/AddObjectMethodProblem.java | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/new/AddObjectMethodProblem.java (limited to 'tests/new/AddObjectMethodProblem.java') diff --git a/tests/new/AddObjectMethodProblem.java b/tests/new/AddObjectMethodProblem.java new file mode 100644 index 000000000..d218f77af --- /dev/null +++ b/tests/new/AddObjectMethodProblem.java @@ -0,0 +1,48 @@ +import org.aspectj.testing.Tester; + +public class AddObjectMethodProblem { + + // Uncommenting this and changing addObject -> doAddObject in the advice + // works around the bug 0.5beta1 + //public void doAddObject(Class1 o) { + // addObject(o); + //} + + public static void main(String[] args) { test(); } + + crosscut ccut(Class1 c1): c1 && void process(); + + advice(Class1 c1): ccut(c1) { + before { + if (c1.getElement() != null) addObject(c1.getElement()); + c1.setProcessedAndAdvised(true); + } + } + + public static void test() { + AddObjectMethodProblem a = new AddObjectMethodProblem(); + Class1 c1 = new Class1(); + Class1 c2 = new Class1(); + c1.element = c2; + a.addObject(c1); + c1.process(); + Tester.check(c1.processedAndAdvised, "advice on top"); + Tester.check(c2.processedAndAdvised, "advice on element"); + } +} + +class Class1 { + public Class1 element; + public boolean processedAndAdvised = false; + + public Class1 getElement() { return element; } + + public void setProcessedAndAdvised( boolean val ) { + processedAndAdvised = val; + } + + public void process() { + if (element != null) element.process(); + } +} + -- cgit v1.2.3