]> source.dussan.org Git - aspectj.git/commitdiff
More fixes for 116679: now copes with the enclosingSP type that we introduced for 1.5
authoraclement <aclement>
Wed, 30 Nov 2005 12:11:03 +0000 (12:11 +0000)
committeraclement <aclement>
Wed, 30 Nov 2005 12:11:03 +0000 (12:11 +0000)
tests/compatibility/Simple.java [deleted file]
tests/compatibility/case1/Simple.java [new file with mode: 0644]
tests/compatibility/case2/A.java [new file with mode: 0644]
tests/compatibility/case2/TrackingErrors.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java

diff --git a/tests/compatibility/Simple.java b/tests/compatibility/Simple.java
deleted file mode 100644 (file)
index 72fec18..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-public class Simple {
-  public static void main(String []argv) {
-    new Simple().a();
-  }
-
-  public void a() {}
-}
-
-aspect X {
-   before():execution(* a(..)) {
-     System.err.println(thisJoinPoint);
-     System.err.println(thisJoinPointStaticPart);
-     System.err.println(thisEnclosingJoinPointStaticPart);
-   }
-
-   before():execution(Simple.new(..)) {
-     System.err.println(thisJoinPoint);
-     System.err.println(thisEnclosingJoinPointStaticPart);
-     System.err.println(thisJoinPointStaticPart);
-   }
-}
diff --git a/tests/compatibility/case1/Simple.java b/tests/compatibility/case1/Simple.java
new file mode 100644 (file)
index 0000000..72fec18
--- /dev/null
@@ -0,0 +1,21 @@
+public class Simple {
+  public static void main(String []argv) {
+    new Simple().a();
+  }
+
+  public void a() {}
+}
+
+aspect X {
+   before():execution(* a(..)) {
+     System.err.println(thisJoinPoint);
+     System.err.println(thisJoinPointStaticPart);
+     System.err.println(thisEnclosingJoinPointStaticPart);
+   }
+
+   before():execution(Simple.new(..)) {
+     System.err.println(thisJoinPoint);
+     System.err.println(thisEnclosingJoinPointStaticPart);
+     System.err.println(thisJoinPointStaticPart);
+   }
+}
diff --git a/tests/compatibility/case2/A.java b/tests/compatibility/case2/A.java
new file mode 100644 (file)
index 0000000..e3acbb4
--- /dev/null
@@ -0,0 +1,20 @@
+public class A {
+  public static void main(String []argv) {
+    try {
+      new A().foo();
+    } catch (Exception e) {
+    }
+  }
+
+  public void foo() {
+    try {
+    } catch (Exception e) {
+    }
+  }
+}
+
+aspect ComplexSub extends TrackingErrors {
+  public pointcut errorScope(): within(A);
+}
+  
diff --git a/tests/compatibility/case2/TrackingErrors.aj b/tests/compatibility/case2/TrackingErrors.aj
new file mode 100644 (file)
index 0000000..42659de
--- /dev/null
@@ -0,0 +1,86 @@
+import org.aspectj.lang.*;
+
+import org.aspectj.lang.JoinPoint;
+
+public abstract aspect TrackingErrors {
+
+   protected abstract pointcut errorScope ();
+
+   private pointcut staticContext () : !this(Object);
+   private pointcut nonStaticContext (Object obj) : this(obj);
+   private pointcut caughtThrowable (Throwable th) : handler(Throwable+)
+           && args(th);
+
+
+
+   private pointcut excluded () : within(TrackingErrors+);
+
+   before (Throwable th) : caughtThrowable(th) && errorScope() &&
+           !excluded() && staticContext() {
+
+           processStaticTrackingErrors(th,thisJoinPointStaticPart,thisEnclosingJoinPointStaticPart);
+   }
+
+   before (Throwable th, Object obj) : caughtThrowable(th) && errorScope()
+           && !excluded() && nonStaticContext(obj) {
+
+           processNonStaticTrackingErrors(th,obj,thisJoinPointStaticPart,thisEnclosingJoinPointStaticPart);
+   }
+
+   protected  void processStaticTrackingErrors (Throwable th,
+           JoinPoint.StaticPart tjp, JoinPoint.StaticPart ejp) {}
+
+   protected void processNonStaticTrackingErrors (Throwable th, Object obj,
+           JoinPoint.StaticPart tjp, JoinPoint.StaticPart ejp) {}
+
+   protected String getSourceId (JoinPoint.StaticPart ejp) {
+                 String typeName =
+           ejp.getSignature().getDeclaringTypeName();
+                 String name = ejp.getSignature().getName();
+           return typeName + "." + name;
+   }
+
+   protected String getProbeId (JoinPoint.StaticPart tjp) {
+                 String sourceLocation =
+           tjp.getSourceLocation().toString();
+           return sourceLocation;
+   }
+
+}
+/*public abstract aspect Complex {
+    
+    protected abstract pointcut scope ();
+    
+    private pointcut staticContext () : !this(Object);
+    private pointcut nonStaticContext (Object obj) : this(obj);
+    private pointcut caughtThrowable (Throwable th) : handler(Throwable+) && args(th);
+    private pointcut excluded () : within(Complex+);
+    before (Throwable th) : caughtThrowable(th) && scope() && !excluded() && staticContext() {
+       processStaticData(th,thisJoinPointStaticPart,thisEnclosingJoinPointStaticPart);
+    }
+    before (Throwable th, Object obj) : caughtThrowable(th) && scope() && !excluded() && nonStaticContext(obj) {
+       processNonStaticData(th,obj,thisJoinPointStaticPart,thisEnclosingJoinPointStaticPart);
+    }
+    
+    private void processStaticData (Throwable th, JoinPoint.StaticPart tjp, JoinPoint.StaticPart ejp) {
+    }
+    private void processNonStaticData (Throwable th, Object obj, JoinPoint.StaticPart tjp, JoinPoint.StaticPart ejp) {
+    }
+    protected String getSourceId (JoinPoint.StaticPart ejp) {
+        String typeName = ejp.getSignature().getDeclaringTypeName();
+        String name = ejp.getSignature().getName();
+        return typeName + "." + name;
+    }
+    protected String getProbeId (JoinPoint.StaticPart tjp) {
+        String sourceLocation = String.valueOf(tjp.getSourceLocation().getLine());
+        return sourceLocation;
+    }
+}
+*/
index 3fa9ff605339a23cd720353146ba574a3ad02948..603cc05b32f6404c741f596fa21ba73a0d4509e9 100644 (file)
@@ -48,7 +48,8 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testCunningDeclareParents_pr92311() { runTest("cunning declare parents");}
   public void testGenericITDsAndAbstractMethodError_pr102357() { runTest("generic itds and abstract method error");}
   */
-  public void testGeneratingCodeForAnOldRuntime_pr116679() { runTest("generating code for a 1.2.1 runtime");}
+  public void testGeneratingCodeForAnOldRuntime_pr116679_1() { runTest("generating code for a 1.2.1 runtime - 1");}
+  public void testGeneratingCodeForAnOldRuntime_pr116679_2() { runTest("generating code for a 1.2.1 runtime - 2");}
   
   public void testAtDeclareParents_pr117681() { runTest("at declare parents");}
   public void testPrivilegeProblem_pr87525() { runTest("privilege problem with switch");}
index 7cb13ac685c82ed6ff270a72bad0343df887606c..027648cf89b57468b031a414999e99fe36210274 100644 (file)
                <run class="ReflectOnAjcCompiledPointcuts" classpath="../lib/bcel/bcel.jar"/>
        </ajc-test>
        
-       <ajc-test dir="compatibility" title="generating code for a 1.2.1 runtime">
-               <compile files="Simple.java" options="-Xajruntimetarget:1.2"></compile>
+       <ajc-test dir="compatibility/case1" title="generating code for a 1.2.1 runtime - 1">
+               <compile files="Simple.java" options="-Xajruntimetarget:1.2"/>
                <run class="Simple" classpath="../lib/aspectj/lib/aspectjrt121.jar"/>
        </ajc-test>
-       
+
+       <ajc-test dir="compatibility/case2" title="generating code for a 1.2.1 runtime - 2">
+               <compile files="TrackingErrors.aj,A.java" options="-Xajruntimetarget:1.2"/>
+               <run class="A" classpath="../lib/aspectj/lib/aspectjrt121.jar"/>
+       </ajc-test>
+               
        <ajc-test dir="java5/reflection" title="arg names in advice annotations">
                <compile files="AdviceWithArgs.aj" options="-1.5"></compile>
                <run class="AdviceWithArgs"/>
        </ajc-test>
-       
-       
+
        <ajc-test dir="java5/reflection" pr="114322" title="reflection on abstract ITDs (Billing example)">
                <compile files="ReflectBilling.java,Billing.aj" options="-1.5"/>
                <run class="ReflectBilling">
index 124b46f888c51a40c75b3678edc16c34a792c387..5ce739a8c89ea0eb99e8049022f65b1d488f91a8 100644 (file)
@@ -1179,11 +1179,17 @@ public class BcelShadow extends Shadow {
     public BcelVar getThisJoinPointStaticPartBcelVar(final boolean isEnclosingJp) {
        if (thisJoinPointStaticPartVar == null) {
                Field field = getEnclosingClass().getTjpField(this, isEnclosingJp);
-               thisJoinPointStaticPartVar =
-                       new BcelFieldRef(
-                               isEnclosingJp?
-                        world.getCoreType(UnresolvedType.forName("org.aspectj.lang.JoinPoint$EnclosingStaticPart")):
-                        world.getCoreType(UnresolvedType.forName("org.aspectj.lang.JoinPoint$StaticPart")),
+               
+                       ResolvedType sjpType = null;
+               if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We didn't have different jpsp types in 1.2     
+                       sjpType = world.getCoreType(UnresolvedType.forName("org.aspectj.lang.JoinPoint$StaticPart"));
+                   } else {
+                       sjpType = isEnclosingJp?
+                              world.getCoreType(UnresolvedType.forName("org.aspectj.lang.JoinPoint$EnclosingStaticPart")):
+                              world.getCoreType(UnresolvedType.forName("org.aspectj.lang.JoinPoint$StaticPart"));
+                   }
+                   thisJoinPointStaticPartVar = new BcelFieldRef(
+                               sjpType,
                                getEnclosingClass().getClassName(),
                                field.getName());
 //             getEnclosingClass().warnOnAddedStaticInitializer(this,munger.getSourceLocation());
index 806b4e82ccad484d00fa7cd0e082ff3d6d7c5f04..6279ef1445725e181673398d69cc6c0fed924642 100644 (file)
@@ -901,10 +901,13 @@ public final class LazyClassGen {
                else {
                        modifiers |= Modifier.PRIVATE;
                }
-               ret = new FieldGen(modifiers,
-               isEnclosingJp?enclosingStaticTjpType:staticTjpType,
-               "ajc$tjp_" + tjpFields.size(),
-               getConstantPoolGen()).getField();
+               ObjectType jpType = null;
+               if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We didn't have different staticjp types in 1.2
+                       jpType = staticTjpType;
+               } else {
+                       jpType = isEnclosingJp?enclosingStaticTjpType:staticTjpType;
+               }
+               ret = new FieldGen(modifiers,jpType,"ajc$tjp_" + tjpFields.size(),getConstantPoolGen()).getField();
        addField(ret);
        tjpFields.put(shadow, ret);
        return ret;
@@ -999,7 +1002,7 @@ public final class LazyClassGen {
        // create the signature
        list.append(InstructionFactory.createLoad(factoryType, 0));
        
-       if (world.getTargetAspectjRuntimeLevel().equals(org.aspectj.weaver.Constants.RUNTIME_LEVEL_12)) {
+       if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We didn't have optimized factory methods in 1.2
                list.append(new PUSH(getConstantPoolGen(), sig.getSignatureString(shadow.getWorld())));
                list.append(fact.createInvoke(factoryType.getClassName(), 
                                        sig.getSignatureMakerName(),
@@ -1091,21 +1094,31 @@ public final class LazyClassGen {
        list.append(Utility.createConstant(fact, shadow.getSourceLine()));
 
         final String factoryMethod;
-        if (staticTjpType.equals(field.getType())) {
-            factoryMethod = "makeSJP";
-        } else if (enclosingStaticTjpType.equals(field.getType())) {
-            factoryMethod = "makeESJP";
+        
+               if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We didn't have makeESJP() in 1.2       
+               list.append(fact.createInvoke(factoryType.getClassName(),
+                               "makeSJP", staticTjpType, 
+                               new Type[] { Type.STRING, sigType, Type.INT},
+                               Constants.INVOKEVIRTUAL));
+               
+               // put it in the field  
+               list.append(fact.createFieldAccess(getClassName(), field.getName(),staticTjpType, Constants.PUTSTATIC));
+        
         } else {
-            throw new Error("should not happen");
-        }
-       list.append(fact.createInvoke(factoryType.getClassName(),
-                       factoryMethod, field.getType(),
-                       new Type[] { Type.STRING, sigType, Type.INT},
-                       Constants.INVOKEVIRTUAL));
-       
-       // put it in the field  
-       list.append(fact.createFieldAccess(getClassName(), field.getName(),
-               field.getType(), Constants.PUTSTATIC));
+               if (staticTjpType.equals(field.getType())) {
+                   factoryMethod = "makeSJP";
+               } else if (enclosingStaticTjpType.equals(field.getType())) {
+                   factoryMethod = "makeESJP";
+               } else {
+                   throw new Error("should not happen");
+               }
+               list.append(fact.createInvoke(factoryType.getClassName(),
+                               factoryMethod, field.getType(),
+                               new Type[] { Type.STRING, sigType, Type.INT},
+                               Constants.INVOKEVIRTUAL));
+               // put it in the field  
+               list.append(fact.createFieldAccess(getClassName(), field.getName(), field.getType(), Constants.PUTSTATIC));
+       }
     }