]> source.dussan.org Git - aspectj.git/commitdiff
tests and fix for pr103157
authoracolyer <acolyer>
Wed, 23 Nov 2005 12:52:27 +0000 (12:52 +0000)
committeracolyer <acolyer>
Wed, 23 Nov 2005 12:52:27 +0000 (12:52 +0000)
tests/.classpath
tests/bugs150/Pr103157.aj [new file with mode: 0644]
tests/bugs150/Pr113368.aj
tests/new/AfterReturningParam.java
tests/new/ConstructorExecInit.java
tests/new/OddConstructors.java
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/Advice.java
weaver/src/org/aspectj/weaver/Shadow.java

index 3d4d909ebd6061a3e344d069a0036c6ff9de5c28..528b09d65eb8952b59bb8d0bcde2efda6d83003f 100644 (file)
@@ -13,7 +13,7 @@
        <classpathentry sourcepath="/lib/bcel/bcel-src.zip" kind="lib" path="/lib/bcel/bcel.jar"/>
        <classpathentry kind="lib" path="/lib/ant/lib/ant-launcher.jar"/>
        <classpathentry kind="src" path="testsrc"/>
-       <classpathentry kind="var" path="JAVA_HOME/lib/tools.jar"/>
+       <classpathentry kind="var" path="JAVA_HOME/lib/dt.jar"/>
        <classpathentry combineaccessrules="false" kind="src" path="/weaver"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/tests/bugs150/Pr103157.aj b/tests/bugs150/Pr103157.aj
new file mode 100644 (file)
index 0000000..f9d41cf
--- /dev/null
@@ -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
index b9d067df6f02741ecf50e18ad63425f3afd62ec9..7f70c7a6d28ec6afe618f3ab559275ea1f38a0fa 100644 (file)
@@ -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);
+}
+}
index 4010bf0588f81f50198500aadffcfee219336e1d..dd4e1fc3791f061858a15b85130baf7d60c863d2 100644 (file)
@@ -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
index 02b9bf2935b691a5e22d6f13b93db57444ef42f5..e27fbc205b8e18adb19c873aa47a2f90bf05144c 100644 (file)
@@ -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");
     }
 }
index 72717d275ab289eb576492a345fe08462e98e517..122e6719c17dfddd6632910ab41698335b7009e9 100644 (file)
@@ -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++;
      }
index f6d67c68938a19b95d65c99c0d027614450b3795..abec35200f5fffdcaaed3170eae10b1622d8ff5c 100644 (file)
@@ -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
    */
index c517c8fc0e2fca1722be67439c09493da3f24c61..373a56a0a3c04d6afec2e57e86433a8e4b87451b 100644 (file)
@@ -60,7 +60,8 @@
     
     <ajc-test dir="bugs150" pr="113368" title="thisJoinPointStaticPart in if test">
                <compile files="Pr113368.aj"/>
-               <run class="Pr113368"/>
+               <run class="Pr113368">
+               </run>
     </ajc-test>
     
     <ajc-test dir="bugs150/pr87525" pr="87525" title="privilege problem with switch">
                </run>
        </ajc-test>
        
+       <ajc-test dir="bugs150" pr="103157" title="returning(Object) binding">
+               <compile files="Pr103157.aj"/>
+               <run class="Pr103157">
+                       <stdout>
+                               <line text="returning from staticinit"/>
+                               <line text="returning from preinit"/>
+                               <line text="returning from set"/>
+                               <line text="returning from cons exe"/>
+                               <line text="returning from init"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+       
        <ajc-test dir="bugs150" title="declare soft and adviceexecution" pr="103051">
                <compile files="Pr103051.aj" options="-Xdev:Pinpoint"/>
        </ajc-test>
index 027e6253f67a8b919b4fefe66fa4c3dce5e747c2..791b9a853390b58c61b64a5e85f944c126c7cbf7 100644 (file)
@@ -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);
                        }
index a245c173e090ebf4e1e8cc43f4a2f834ac3d0f72..2fa1c1d4d195301f5c9684d96adc350c5bd3e40d 100644 (file)
@@ -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