]> source.dussan.org Git - aspectj.git/commitdiff
Fix and tests for Bugzilla Bug 71372
authoraclement <aclement>
Fri, 13 Aug 2004 14:48:43 +0000 (14:48 +0000)
committeraclement <aclement>
Fri, 13 Aug 2004 14:48:43 +0000 (14:48 +0000)
   NoSuchMethodError calling private method from around advice in inner aspect

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java
tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java
tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml

index c913040fe909e51a557010fd55f37328c7dc304a..9840be79e0a105f7d2d120334904ece1ade0738d 100644 (file)
@@ -170,16 +170,24 @@ public class AccessForInlineVisitor extends ASTVisitor {
                if (isPublic(binding)) return binding;
                if (binding instanceof InterTypeMethodBinding) return binding;
 
+               ResolvedMember m = null;
                if (binding.isPrivate() &&  binding.declaringClass != inAspect.binding) {
+                       // does this always mean that the aspect is an inner aspect of the bindings
+                       // declaring class?  After all, the field is private but we can see it from 
+                       // where we are.
                        binding.modifiers = AstUtil.makePackageVisible(binding.modifiers);
+                       m = EclipseFactory.makeResolvedMember(binding);
+               } else {
+                       // Sometimes receiverType and binding.declaringClass are *not* the same.
+                       
+                       // Sometimes receiverType is a subclass of binding.declaringClass.  In these situations
+                       // we want the generated inline accessor to call the method on the subclass (at
+                       // runtime this will be satisfied by the super).
+                       m = EclipseFactory.makeResolvedMember(binding, receiverType);
                }
-
-               
-               ResolvedMember m = EclipseFactory.makeResolvedMember(binding, receiverType);
                if (inAspect.accessForInline.containsKey(m)) return (MethodBinding)inAspect.accessForInline.get(m);
                MethodBinding ret = world.makeMethodBinding(
-                       AjcMemberMaker.inlineAccessMethodForMethod(inAspect.typeX, m)
-                       );
+                       AjcMemberMaker.inlineAccessMethodForMethod(inAspect.typeX, m));
                inAspect.accessForInline.put(m, ret);
                return ret;
        }
index 0e5654ec659fef19e2aebc3010846914242948a1..1d79649402ee68416d32f19b67f136023e0b92b4 100644 (file)
@@ -180,7 +180,35 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
   public void test034_scopeForITDS_pr61768() {
       runTest("scope for inter-type methods");
-    }
+  }
+  
+  public void test035_innerAspectCallsPrivateMethod_pr71372() {
+    runTest("NoSuchMethodError calling private method from around advice in inner aspect");
+    String s = getLastRunResult().getStdErr();
+    assertTrue("Expected ':before:around' but got "+s,
+                  s.equals(":before:around"));
+  }
+  
+  public void test036_innerAspectCallsPrivateMethod_pr71372_2() {
+    runTest("NoSuchMethodError calling private method from around advice in inner aspect (2)");
+    String s = getLastRunResult().getStdErr();
+    assertTrue("Expected ':before:around' but got "+s,
+                  s.equals(":before:around"));
+  }
+  
+  public void test037_innerAspectCallsPrivateMethod_pr71372_3() {
+    runTest("NoSuchMethodError calling private method from around advice in inner aspect (3)");
+    String s = getLastRunResult().getStdErr();
+    assertTrue("Expected ':before:around' but got "+s,
+                  s.equals(":before:around"));
+  }
+  
+  public void test038_innerAspectCallsPrivateMethod_pr71372_4() {
+    runTest("NoSuchMethodError calling private method from around advice in inner aspect (4)");
+    String s = getLastRunResult().getStdErr();
+    assertTrue("Expected ':before:around' but got "+s,
+                  s.equals(":before:around"));
+  }
 
 }
 
index c11ce0228bbc92dfb1a48091759fb20019e00b2f..1ebf21c7a2c8a6d4e6bdc3cee4e9f4301f3b5f31 100644 (file)
                <compile files="PR61768.java">
                        <message kind="error" line="37" text="No enclosing instance of type Aspect is accessible"/>
                </compile>
-       </ajc-test>
\ No newline at end of file
+       </ajc-test>
+
+       <ajc-test dir="bugs/doYouHaveVisiblePrivates" pr="71372"
+               title="NoSuchMethodError calling private method from around advice in inner aspect">
+               <compile files="PrivateCall.java"/>
+               <run class="PrivateCall"/>
+       </ajc-test>
+
+       <ajc-test dir="bugs/doYouHaveVisiblePrivates" pr="71372"
+               title="NoSuchMethodError calling private method from around advice in inner aspect (2)">
+               <compile files="PrivateCall2.java,PrivateCall3.java"/>
+               <run class="def.PrivateCall3"/>
+       </ajc-test>
+               
+       <ajc-test dir="bugs/doYouHaveVisiblePrivates" pr="71372"
+               title="NoSuchMethodError calling private method from around advice in inner aspect (3)">
+               <compile files="PrivateCallInstance.java"/>
+               <run class="PrivateCallInstance"/>
+       </ajc-test>
+       
+       <ajc-test dir="bugs/doYouHaveVisiblePrivates" pr="71372"
+               title="NoSuchMethodError calling private method from around advice in inner aspect (4)">
+               <compile files="PrivateCall_Instance_Package1.java,PrivateCall_Instance_Package2.java"/>
+               <run class="def.PrivateCall_Instance_Package2"/>
+       </ajc-test>
+