]> source.dussan.org Git - aspectj.git/commitdiff
Fix for Bugzilla Bug 50641
authoraclement <aclement>
Mon, 9 Feb 2004 15:07:37 +0000 (15:07 +0000)
committeraclement <aclement>
Mon, 9 Feb 2004 15:07:37 +0000 (15:07 +0000)
   Better binary compatibility for advice method names
- I've run the tests a thousand times and they all pass, I'm still nervous about this first big commit though *gulp*

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java
org.aspectj.ajdt.core/testsrc/AroundAMain.java
tests/ajcTests.xml
tests/ajcTestsFailing.xml
tests/bugs/binaryCompat/Main.java
tests/bugs/binaryCompat/TraceV2.aj
tests/bugs/binaryCompat/TraceWithInnerV1.aj [new file with mode: 0644]
tests/bugs/binaryCompat/TraceWithInnerV2.aj [new file with mode: 0644]
weaver/src/org/aspectj/weaver/NameMangler.java

index 6b6b801f5a6d9bc7562827ae8706e46c378b253b..9d10f63815f057892f951a23d89019d1863216fe 100644 (file)
@@ -263,11 +263,18 @@ public class AdviceDeclaration extends MethodDeclaration {
                return ret;
        }
 
-
        
        public void postParse(TypeDeclaration typeDec) {
+               int adviceSequenceNumberInType = ((AspectDeclaration)typeDec).adviceCounter++;
+               
+               StringBuffer stringifiedPointcut = new StringBuffer(30);
+               pointcutDesignator.print(0,stringifiedPointcut);
                this.selector =
-                       NameMangler.adviceName(EclipseFactory.fromBinding(typeDec.binding), kind, sourceStart).toCharArray();
+                       NameMangler.adviceName(
+                         EclipseFactory.fromBinding(typeDec.binding), 
+                         kind, 
+                         adviceSequenceNumberInType,
+                         stringifiedPointcut.toString().hashCode()).toCharArray();
                if (arguments != null) {
                        baseArgumentCount = arguments.length;
                }
index a3cff8ae6eadddc81db8f98c05a7b9a6b1814498..27db10c3e783d0940267444419c5df07b9a0137f 100644 (file)
@@ -53,6 +53,7 @@ public class AspectDeclaration extends TypeDeclaration {
        
        public EclipseFactory factory;  //??? should use this consistently
 
+    public int adviceCounter = 1; // Used as a part of the generated name for advice methods
 
        // for better error messages in 1.0 to 1.1 transition
        public TypePattern dominatesPattern;
index 2f101dd74e4d915eaaf293176096e54defc3ea39..fcdeab18e3b2865cff45796a9306a10ff3a5b399 100644 (file)
@@ -33,12 +33,12 @@ public class AroundAMain extends TestCase {
                Object instance = Reflection.getStaticField(Class.forName("AroundA"),
                        "ajc$perSingletonInstance");
 
-               Reflection.invoke(Class.forName("AroundA"), instance, "ajc$around$AroundA$46",
+               Reflection.invoke(Class.forName("AroundA"), instance, "ajc$around$AroundA$1$73ebb943", // was $AroundA$46
                                        new Integer(10), new Boolean(true), closure);
 
-               Reflection.invoke(Class.forName("AroundA"), instance, "ajc$around$AroundA$c5",
+               Reflection.invoke(Class.forName("AroundA"), instance, "ajc$around$AroundA$2$a758212d",  // Was $AroundA$c5
                                        "hello there", closure);
-               Reflection.invoke(Class.forName("AroundA"), instance, "ajc$around$AroundA$150",
+               Reflection.invoke(Class.forName("AroundA"), instance, "ajc$around$AroundA$3$a758212d",  // Was $AroundA$150
                                        new String[1], closure);
 
        }
index 57b496aaafa533a26df0c7cda91d1eae9db3f332..4f68d8e006ef79811467d273e98ef87c2e29a3e8 100644 (file)
         <run class="HandlerSig"/>
     </ajc-test>
     
+
     <ajc-test dir="new" pr="42668"
         title="after returning with parameter: matching rules">
         <compile files="AfterReturningParamMatching.java" />
         <run class="AfterReturningParamMatching"/>
     </ajc-test>
+    
+    <ajc-test dir="bugs/binaryCompat" pr="50641"
+      title="binary compatibility of advice method names - expect no error">
+        <compile files="Main.java,TraceV1.aj"/>
+        <run class="Main"/>
+        <compile files="TraceV2.aj"/>
+        <run class="Main"/>
+    </ajc-test>
+   
+    <ajc-test dir="bugs/binaryCompat" pr="50641"
+      title="binary compatibility of advice method names - expect error">
+        <compile files="Main.java,TraceV1.aj"/>
+        <run class="Main"/>
+        <compile files="TraceRE.aj"/>
+        <run class="Main"/>
+    </ajc-test>
+    
+     <ajc-test dir="bugs/binaryCompat" pr="50641"
+      title="binary compatibility of advice method names - expect no error">
+        <compile files="Main.java,TraceWithInnerV1.aj"/>
+        <run class="Main"/>
+        <compile files="TraceWithInnerV2.aj"/>
+        <run class="Main"/>
+    </ajc-test>
 </suite>
index cea32f4dd6513ca300ed93ffe6535c8bdda8eb31..c2fb46b054957ea5becf0e41505d18a491820f82 100644 (file)
         <run class="InterfaceMethodDeclarationNonPublic"/>
     </ajc-test>
 
-    <ajc-test dir="bugs/binaryCompat" pr="50641"
-      title="binary compatibility of advice method names - expect no error">
-        <compile files="Main.java,TraceV1.aj"/>
-        <run class="Main"/>
-        <compile files="TraceV2.aj"/>
-        <run class="Main"/>
-    </ajc-test>
-   
-    <ajc-test dir="bugs/binaryCompat" pr="50641"
-      title="binary compatibility of advice method names - expect error">
-        <compile files="Main.java,TraceV1.aj"/>
-        <run class="Main"/>
-        <compile files="TraceRE.aj"/>
-        <run class="Main"/>
-    </ajc-test>
-
     <ajc-test dir="bugs" pr="36787"
       title="interface initialization order">
         <compile files="InterfaceInitializerOrder.java"/>
index d91978f9fb4f7e25a3efb5fdf54a89760a93ad45..0903463d9a5a95e04529f8e5afa5106851e175a7 100644 (file)
@@ -14,4 +14,4 @@ public class Main {
        private static void doit() {
                System.out.println("hello world");
        }
-}
\ No newline at end of file
+}
index c71416af34197422bb360df7678436ef852fbc5c..5764387b02b7fa826551da59f6bca3e057fd8801 100644 (file)
@@ -3,8 +3,10 @@ aspect Trace {
        \r
        before(): execution(void doit(..)) {\r
                System.out.println("entering");\r
+               \r
        }\r
        \r
+       \r
        after() returning: execution(void doit(..)) {\r
                System.out.println("exiting");\r
        }\r
diff --git a/tests/bugs/binaryCompat/TraceWithInnerV1.aj b/tests/bugs/binaryCompat/TraceWithInnerV1.aj
new file mode 100644 (file)
index 0000000..2238a23
--- /dev/null
@@ -0,0 +1,24 @@
+aspect Trace {\r
+       public static boolean expectNoSuchMethodError = false;\r
+       \r
+       before(): execution(void doit(..)) {\r
+               System.out.println("enter");\r
+       }\r
+\r
+       static aspect InnerTrace {\r
+               before(): execution(void doit(..)) {\r
+                       System.out.println("Inner enter");\r
+               }\r
+               \r
+               after() returning: execution(void doit(..)) {\r
+                       System.out.println("Inner exit");\r
+               }\r
+               \r
+               after() throwing: execution(void doit(..)) {\r
+                       System.out.println("Inner after throwing");\r
+               }\r
+       }\r
+       after() returning: execution(void doit(..)) {\r
+               System.out.println("exit");\r
+       }\r
+}
\ No newline at end of file
diff --git a/tests/bugs/binaryCompat/TraceWithInnerV2.aj b/tests/bugs/binaryCompat/TraceWithInnerV2.aj
new file mode 100644 (file)
index 0000000..297fdfb
--- /dev/null
@@ -0,0 +1,34 @@
+aspect Trace {\r
+       public static boolean expectNoSuchMethodError = false;\r
+       \r
+       before(): execution(void doit(..)) {\r
+               System.out.println("entering");\r
+               \r
+       }\r
+\r
+       public void method() {\r
+               // Extra method to do nothing but test if the numbering still behaves   \r
+       }\r
+\r
+       static aspect InnerTrace {\r
+               before(): execution(void doit(..)) {\r
+                       System.out.println("Inner entering");\r
+               }\r
+               \r
+               after() returning: execution(void doit(..)) {\r
+                       System.out.println("Inner exiting");\r
+               }\r
+               \r
+               after() throwing: execution(void doit(..)) {\r
+                       System.out.println("Inner chucking");\r
+               }\r
+               \r
+               before(): execution(* noMatch(..)) {\r
+                       System.out.println("This doesn't match anything, but checks the sequence number for the next bit of advice is OK");\r
+               }\r
+       }\r
+       \r
+       after() returning: execution(void doit(..)) {\r
+               System.out.println("exiting");\r
+       }\r
+}
\ No newline at end of file
index 7db5107ce6622d0b413f975c25105650092fc265..e73973541027d8c3852829fa5de1378e1175fcf2 100644 (file)
@@ -89,13 +89,17 @@ public class NameMangler {
        }
        
        
-       
        /**
         * The name of methods corresponding to advice declarations
+        * Of the form: "ajc$[AdviceKind]$[AspectName]$[NumberOfAdviceInAspect]$[PointcutHash]"
         */
-       public static String adviceName(TypeX aspectType, AdviceKind kind, int position) {
-               return makeName(kind.getName(), aspectType.getNameAsIdentifier(),
-                                       Integer.toHexString(position));
+       public static String adviceName(TypeX aspectType, AdviceKind kind, int adviceSeqNumber,int pcdHash) {
+               String newname = makeName(
+                       kind.getName(),
+                       aspectType.getNameAsIdentifier(),
+                       Integer.toString(adviceSeqNumber),
+                       Integer.toHexString(pcdHash));
+               return newname;
        }
        
        /**