]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 135001
authoraclement <aclement>
Thu, 6 Apr 2006 11:45:02 +0000 (11:45 +0000)
committeraclement <aclement>
Thu, 6 Apr 2006 11:45:02 +0000 (11:45 +0000)
tests/bugs152/pr135001/AbstractAspect.java [new file with mode: 0644]
tests/bugs152/pr135001/ConcreteAspect.java [new file with mode: 0644]
tests/bugs152/pr135001/Foo.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/AllTests15.java
tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc152/ajc152.xml [new file with mode: 0644]
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/src/org/aspectj/weaver/bcel/BcelWorld.java
weaver/testsrc/org/aspectj/weaver/bcel/AsmDelegateTests.java

diff --git a/tests/bugs152/pr135001/AbstractAspect.java b/tests/bugs152/pr135001/AbstractAspect.java
new file mode 100644 (file)
index 0000000..6f4d579
--- /dev/null
@@ -0,0 +1,9 @@
+public abstract aspect AbstractAspect {
+       
+       abstract pointcut scope();
+       
+       void around(): scope() {
+               System.err.println("In the advice!");
+               proceed();
+       }
+}
\ No newline at end of file
diff --git a/tests/bugs152/pr135001/ConcreteAspect.java b/tests/bugs152/pr135001/ConcreteAspect.java
new file mode 100644 (file)
index 0000000..df61197
--- /dev/null
@@ -0,0 +1,3 @@
+public aspect ConcreteAspect extends AbstractAspect {
+       pointcut scope(): call(* foo(..));
+}
\ No newline at end of file
diff --git a/tests/bugs152/pr135001/Foo.java b/tests/bugs152/pr135001/Foo.java
new file mode 100644 (file)
index 0000000..4a80ea3
--- /dev/null
@@ -0,0 +1,9 @@
+public class Foo {
+       public static void main(String[] args) {
+               new Foo().foo();
+       }
+       
+       public void foo() {
+               
+       }
+}
\ No newline at end of file
index fec8757855dca1d24e79d1dd251c65497905ddaf..8667d9686dc2025eb7039eb66a9f7aa32c15c647 100644 (file)
@@ -9,6 +9,7 @@ import junit.framework.TestSuite;
 import org.aspectj.systemtest.ajc150.AllTestsAspectJ150;
 import org.aspectj.systemtest.ajc150.ataspectj.AtAjAnnotationGenTests;
 import org.aspectj.systemtest.ajc151.AllTestsAspectJ151;
+import org.aspectj.systemtest.ajc152.AllTestsAspectJ152;
 
 public class AllTests15 {
 
@@ -18,6 +19,7 @@ public class AllTests15 {
                suite.addTest(AllTests14.suite());
                suite.addTest(AllTestsAspectJ150.suite());
                suite.addTest(AllTestsAspectJ151.suite());
+               suite.addTest(AllTestsAspectJ152.suite());
                suite.addTest(AtAjAnnotationGenTests.suite());
                //$JUnit-END$
                return suite;
diff --git a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
new file mode 100644 (file)
index 0000000..18baacb
--- /dev/null
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ *    Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc152;
+
+import java.io.File;
+import junit.framework.Test;
+
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
+  public void testAspectLibrariesAndASM_pr135001() { runTest("aspect libraries and asm");}
+  
+  
+  /////////////////////////////////////////
+  public static Test suite() {
+    return XMLBasedAjcTestCase.loadSuite(Ajc152Tests.class);
+  }
+
+  protected File getSpecFile() {
+    return new File("../tests/src/org/aspectj/systemtest/ajc152/ajc152.xml");
+  }
+
+  
+}
\ No newline at end of file
diff --git a/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java b/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java
new file mode 100644 (file)
index 0000000..82a3983
--- /dev/null
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ *    Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc152;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTestsAspectJ152 {
+
+       public static Test suite() {
+               TestSuite suite = new TestSuite("AspectJ 1.5.2 tests");
+               //$JUnit-BEGIN$
+               suite.addTest(Ajc152Tests.suite());
+        //$JUnit-END$
+               return suite;
+       }
+}
diff --git a/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml b/tests/src/org/aspectj/systemtest/ajc152/ajc152.xml
new file mode 100644 (file)
index 0000000..75c8c07
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<!-- AspectJ v1.5.2 Tests -->
+<suite>
+
+    <ajc-test dir="bugs152/pr135001" title="aspect libraries and asm">
+      <compile files="AbstractAspect.java" outjar="lib.jar" options="-1.5"/>
+      <compile files="Foo.java,ConcreteAspect.java" classpath="lib.jar" options="-1.5 -showWeaveInfo">
+        <message kind="weave" text="Join point 'method-call(void Foo.foo())' in Type 'Foo' (Foo.java:3) advised by around advice from 'ConcreteAspect' (AbstractAspect.java:5)"/>
+      </compile>
+      <run class="Foo">
+         <stderr>
+           <line text="In the advice!"/>
+         </stderr>
+      </run>
+    </ajc-test>
+    
+</suite>
\ No newline at end of file
index f53a380f198bd9d15a42451869c61d0868407678..3ed40489d13c6ed5e4a67ca88e1cffcc56a5bc69 100644 (file)
@@ -55,6 +55,7 @@ import org.aspectj.apache.bcel.generic.StoreInstruction;
 import org.aspectj.apache.bcel.generic.TargetLostException;
 import org.aspectj.apache.bcel.generic.Type;
 import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.MessageUtil;
 import org.aspectj.weaver.Advice;
 import org.aspectj.weaver.AdviceKind;
 import org.aspectj.weaver.AjcMemberMaker;
@@ -2104,8 +2105,14 @@ public class BcelShadow extends Shadow {
 //          world.getMessageHandler().handleMessage(msg);
         }
         //??? might want some checks here to give better errors
-        BcelObjectType ot = BcelWorld.getBcelObjectType((declaringType.isParameterizedType()?declaringType.getGenericType():declaringType)); 
-        
+        ResolvedType rt = (declaringType.isParameterizedType()?declaringType.getGenericType():declaringType);
+        BcelObjectType ot = BcelWorld.getBcelObjectType(rt); 
+//        if (ot==null) {
+//             world.getMessageHandler().handleMessage(
+//               MessageUtil.warn("Unable to find modifiable delegate for the aspect '"+rt.getName()+"' containing around advice - cannot implement inlining",munger.getSourceLocation()));
+//             weaveAroundClosure(munger, hasDynamicTest);
+//                     return;
+//        }
                LazyMethodGen adviceMethod = ot.getLazyClassGen().getLazyMethodGen(mungerSig);
                if (!adviceMethod.getCanInline()) {
                        weaveAroundClosure(munger, hasDynamicTest);
index 4afe29bfecc057989fb670326fd6f3e0b17a1c35..8251842cad79958cf3f2dbe83507e5188f6239da 100644 (file)
@@ -244,8 +244,11 @@ public class BcelWorld extends World implements Repository {
     
     public ResolvedType resolve(Type t) {
         return resolve(fromBcel(t));
-    }       
-
+    } 
+    
+    // SECRETAPI: used for testing ASM loading of delegates...
+    public boolean fallbackToLoadingBcelDelegatesForAspects = true;
+    
     private int packageRestrictionsForFastDelegates = 0; // 0=dontknow 1=no  2=yes
     private List packagePrefixRestrictionList = null;
     
@@ -288,7 +291,22 @@ public class BcelWorld extends World implements Repository {
                if (cf==null) {
                        return null;
                } else {
-                       return buildAsmDelegate(ty,cf);
+                       ReferenceTypeDelegate delegate =  buildAsmDelegate(ty,cf);
+                       if (fallbackToLoadingBcelDelegatesForAspects && delegate.isAspect()) {
+                               // bugger - pr135001 - we can't inline around advice from an aspect because we don't load the instructions.
+                               // fixing this quick to get AJDT upgraded with a good 1.5.2dev build.
+                               // other fixes would be:
+                               // 1. record that we are loading the superclass for an aspect, so we know to make it a BCEL delegate
+                               //
+                               // the 'fix' here is only reasonable because there are many less aspects than classes!
+                               
+                               // Create a BCEL delegate
+                               if (jc == null) jc = lookupJavaClass(classPath, name);
+                       if (jc == null) return delegate; // worrying situation ?!?
+                       else            return buildBcelDelegate(ty, jc, false);
+                       } else {
+                               return delegate;
+                       }
                }
         } else {
                if (jc == null) {
index 8a6f78e674746dbe42932c757bf5cb06c987dc06..146a5ba2ba7655bbd44e576d770a884357dae311 100644 (file)
@@ -57,8 +57,10 @@ public class AsmDelegateTests extends AbstractWorldTestCase {
        // --- testcode
 
     public void testWeDontGoBang() {
+        world.fallbackToLoadingBcelDelegatesForAspects = false;
        ResolvedType rt = world.resolve("SimpleAspect");
        ReferenceTypeDelegate delegate = ((ReferenceType)rt).getDelegate();
+       
        assertTrue("Should be an ASM delegate but is "+delegate.getClass(),
                           delegate.getClass().toString().equals("class org.aspectj.weaver.asm.AsmDelegate"));
     }
@@ -392,8 +394,10 @@ public class AsmDelegateTests extends AbstractWorldTestCase {
      * Load up the AspectFromHell and take it apart...
      */
     public void testLoadingAttributesForTypes() {
-       BcelWorld slowWorld = new BcelWorld(BcweaverTests.TESTDATA_PATH+"/forAsmDelegateTesting/stuff.jar");slowWorld.setFastDelegateSupport(false);
+       BcelWorld slowWorld = new BcelWorld(BcweaverTests.TESTDATA_PATH+"/forAsmDelegateTesting/stuff.jar");
+       slowWorld.setFastDelegateSupport(false);
         BcelWorld fastWorld = new BcelWorld(BcweaverTests.TESTDATA_PATH+"/forAsmDelegateTesting/stuff.jar");
+        fastWorld.fallbackToLoadingBcelDelegatesForAspects = false;
         
         ReferenceType bcelT = (ReferenceType)slowWorld.resolve("AspectFromHell");
         ReferenceType asmT  = (ReferenceType)fastWorld.resolve("AspectFromHell");
@@ -416,7 +420,8 @@ public class AsmDelegateTests extends AbstractWorldTestCase {
        boolean debug = false;
        BcelWorld slowWorld = new BcelWorld(BcweaverTests.TESTDATA_PATH+"/forAsmDelegateTesting/stuff.jar");slowWorld.setFastDelegateSupport(false);
         BcelWorld fastWorld = new BcelWorld(BcweaverTests.TESTDATA_PATH+"/forAsmDelegateTesting/stuff.jar");
-        
+        fastWorld.fallbackToLoadingBcelDelegatesForAspects = false;
+
         ReferenceType bcelT = (ReferenceType)slowWorld.resolve("AspectFromHell");
         ReferenceType asmT  = (ReferenceType)fastWorld.resolve("AspectFromHell");