From 8b294d9e4f02625c4c3391612242969fb4b6be57 Mon Sep 17 00:00:00 2001 From: acolyer Date: Wed, 23 Nov 2005 12:52:27 +0000 Subject: [PATCH] tests and fix for pr103157 --- tests/.classpath | 2 +- tests/bugs150/Pr103157.aj | 66 +++++++++++++++++++ tests/bugs150/Pr113368.aj | 56 ++++++++++------ tests/new/AfterReturningParam.java | 4 +- tests/new/ConstructorExecInit.java | 2 +- tests/new/OddConstructors.java | 2 +- .../systemtest/ajc150/Ajc150Tests.java | 4 ++ .../org/aspectj/systemtest/ajc150/ajc150.xml | 16 ++++- weaver/src/org/aspectj/weaver/Advice.java | 4 +- weaver/src/org/aspectj/weaver/Shadow.java | 14 ++++ 10 files changed, 144 insertions(+), 26 deletions(-) create mode 100644 tests/bugs150/Pr103157.aj diff --git a/tests/.classpath b/tests/.classpath index 3d4d909eb..528b09d65 100644 --- a/tests/.classpath +++ b/tests/.classpath @@ -13,7 +13,7 @@ - + diff --git a/tests/bugs150/Pr103157.aj b/tests/bugs150/Pr103157.aj new file mode 100644 index 000000000..f9d41cf4b --- /dev/null +++ b/tests/bugs150/Pr103157.aj @@ -0,0 +1,66 @@ +public aspect Pr103157 { + + // verify after returning behaviour with join points that have no "return" value + + // these are: + // ConstructorExecution + // FieldSet + // StaticInitialization + // Initialization + // PreInitialization + // ExceptionHandler -- but handler can't have after returning advice anyway + // arguably all adviceexecution join points except for around, but allow this for now + + after() returning(Object obj) : execution(C.new(..)) { + System.out.println("returning obj on cons exe " + obj); + } + + after() returning : execution(C.new(..)) { + System.out.println("returning from cons exe"); + } + + after() returning(Object obj) : set(* C.*) { + System.out.println("returning obj on set " + obj); + } + + after() returning : set(* C.*) { + System.out.println("returning from set"); + } + + after() returning(Object obj) : staticinitialization(C) { + System.out.println("returning obj on staticinit " + obj); + } + + after() returning : staticinitialization(C) { + System.out.println("returning from staticinit"); + } + + after() returning(Object obj) : initialization(C.new(..)) { + System.out.println("returning obj on init " + obj); + } + + after() returning : initialization(C.new(..)) { + System.out.println("returning from init"); + } + + after() returning(Object obj) : preinitialization(C.new(..)) { + System.out.println("returning obj on preinit " + obj); + } + + after() returning : preinitialization(C.new(..)) { + System.out.println("returning from preinit"); + } + + public static void main(String[] args) { + new C(); + } + +} + +class C { + + String s; + + public C() { this.s = "xxx"; } + +} \ No newline at end of file diff --git a/tests/bugs150/Pr113368.aj b/tests/bugs150/Pr113368.aj index b9d067df6..7f70c7a6d 100644 --- a/tests/bugs150/Pr113368.aj +++ b/tests/bugs150/Pr113368.aj @@ -1,36 +1,52 @@ + public aspect Pr113368 { - - private pointcut managedBeanConstruction(ManagedBean bean) : - execution(ManagedBean+.new(..)) && this(bean); + + public static void main(String[] args) { + try { + aspectOf().hook(); + } catch (ExceptionInInitializerError ex) { + Throwable cause = ex.getCause(); + if (! (cause instanceof org.aspectj.lang.NoAspectBoundException)) { + throw new RuntimeException("Unexpected exception: " + cause); + } + } + } + + void hook() {} + private pointcut managedBeanConstruction(ManagedBean bean) : + execution(ManagedBean+.new(..)) && this(bean); + //NPE's on the if pointcut below private pointcut topLevelManagedBeanConstruction(ManagedBean bean) : managedBeanConstruction(bean) && if(thisJoinPointStaticPart.getSignature().getDeclaringType() == bean.getClass()); after(ManagedBean bean) returning: topLevelManagedBeanConstruction(bean) { - System.out.println("I just constructed " + bean); + System.out.println("I just constructed " + bean); } - public static void main(String[] args) { - new ManagedBean("super-bean"); - new ManagedSubBean(); +} + +abstract aspect ManagedBean { +} + + +aspect ManagedSubBean extends ManagedBean { + + before() : execution(* hook()) { } } -class ManagedBean { - - public ManagedBean(String s) { - System.out.println(s); - } +aspect AutoStart { + before() : staticinitialization(ManagedBean) { + ManagedSubBean.aspectOf(); + } } - -class ManagedSubBean extends ManagedBean { - - public ManagedSubBean() { - super("sub-bean"); - } - -} \ No newline at end of file +aspect Tracer { + before() : !within(Tracer) { + System.out.println(thisJoinPoint); +} +} diff --git a/tests/new/AfterReturningParam.java b/tests/new/AfterReturningParam.java index 4010bf058..dd4e1fc37 100644 --- a/tests/new/AfterReturningParam.java +++ b/tests/new/AfterReturningParam.java @@ -4,7 +4,8 @@ public class AfterReturningParam { public static void main(String[] args) { AfterReturningParam p = new AfterReturningParam(); - Tester.checkAndClearEvents(new String[] { "constr exec as Object null" }); + // Tester.checkAndClearEvents(new String[] { "constr exec as Object null" }); + // see pr 103157 for reason why this no longer matches p.mInt(); Tester.checkAndClearEvents(new String[] { "int as Object 2" }); @@ -36,6 +37,7 @@ aspect A { callEvent("constr exec as constd object", o); } after() returning (Object o) : execution(AfterReturningParam.new()) { // CW 38 in 1.0.4, does match + // in 1.5 does not match - no return value for this jp callEvent("constr exec as Object", o); } after() returning (String o) : execution(AfterReturningParam.new()) { // CW 41 in 1.0.4, no match diff --git a/tests/new/ConstructorExecInit.java b/tests/new/ConstructorExecInit.java index 02b9bf293..e27fbc205 100644 --- a/tests/new/ConstructorExecInit.java +++ b/tests/new/ConstructorExecInit.java @@ -20,7 +20,7 @@ aspect A { after (Object target) : execution(*.new(..)) && target(target) && !within(A) { Tester.event("execution"); } - after () returning (Object target) : initialization(new(..)) && !this(A) { + after () returning : initialization(new(..)) && !this(A) { Tester.event("initialization"); } } diff --git a/tests/new/OddConstructors.java b/tests/new/OddConstructors.java index 72717d275..122e6719c 100644 --- a/tests/new/OddConstructors.java +++ b/tests/new/OddConstructors.java @@ -35,7 +35,7 @@ abstract aspect A { //&& initialization(new(..)) ; && initialization(I.new(..)) ; - after() returning(Object o): j() { + after() returning: j() { Tester.note("advised default constructor"); count++; } diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index f6d67c689..abec35200 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -734,6 +734,10 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("declare soft and exclusions"); } + public void testReturningObjectBinding() { + runTest("returning(Object) binding"); + } + /* * Load-time weaving bugs */ diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index c517c8fc0..373a56a0a 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -60,7 +60,8 @@ - + + @@ -88,6 +89,19 @@ + + + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/Advice.java b/weaver/src/org/aspectj/weaver/Advice.java index 027e6253f..791b9a853 100644 --- a/weaver/src/org/aspectj/weaver/Advice.java +++ b/weaver/src/org/aspectj/weaver/Advice.java @@ -120,7 +120,9 @@ public abstract class Advice extends ShadowMunger { if (hasExtraParameter() && kind == AdviceKind.AfterReturning) { ResolvedType resolvedExtraParameterType = getExtraParameterType().resolve(world); ResolvedType shadowReturnType = shadow.getReturnType().resolve(world); - boolean matches = resolvedExtraParameterType.isConvertableFrom(shadowReturnType); + boolean matches = + (resolvedExtraParameterType.isConvertableFrom(shadowReturnType) && + shadow.getKind().hasReturnValue()); if (matches && resolvedExtraParameterType.isParameterizedType()) { maybeIssueUncheckedMatchWarning(resolvedExtraParameterType,shadowReturnType,shadow,world); } diff --git a/weaver/src/org/aspectj/weaver/Shadow.java b/weaver/src/org/aspectj/weaver/Shadow.java index a245c173e..2fa1c1d4d 100644 --- a/weaver/src/org/aspectj/weaver/Shadow.java +++ b/weaver/src/org/aspectj/weaver/Shadow.java @@ -280,6 +280,20 @@ public abstract class Shadow { return !isTargetSameAsThis(); } + /** + * These shadow kinds have return values that can be bound in + * after returning(Dooberry doo) advice. + * @return + */ + public boolean hasReturnValue() { + return + this == MethodCall || + this == ConstructorCall || + this == MethodExecution || + this == FieldGet || + this == AdviceExecution; + } + /** * These are all the shadows that contains other shadows within them and -- 2.39.5