]> source.dussan.org Git - aspectj.git/commitdiff
tests and fix for pr71159, visibility not taken into account when determining matchin...
authoracolyer <acolyer>
Wed, 31 Aug 2005 15:44:22 +0000 (15:44 +0000)
committeracolyer <acolyer>
Wed, 31 Aug 2005 15:44:22 +0000 (15:44 +0000)
tests/bugs150/pr71159/PrivateITD.aj [new file with mode: 0644]
tests/bugs150/pr71159/pkg1/A.java [new file with mode: 0644]
tests/bugs150/pr71159/pkg1/B.java [new file with mode: 0644]
tests/bugs150/pr71159/pkg1/C.java [new file with mode: 0644]
tests/bugs150/pr71159/pkg2/ITDInDiffPackage.aj [new file with mode: 0644]
tests/bugs150/pr71159/pr71159.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/ResolvedMemberImpl.java

diff --git a/tests/bugs150/pr71159/PrivateITD.aj b/tests/bugs150/pr71159/PrivateITD.aj
new file mode 100644 (file)
index 0000000..e4649d0
--- /dev/null
@@ -0,0 +1,34 @@
+class A {
+       
+
+       
+}
+
+class B extends A {
+       
+       protected void foo() {}
+       
+}
+
+class C extends B {}
+
+
+class D extends C {
+       
+       public void foo() {}
+       
+}
+
+aspect X {
+       
+       private void A.foo() {}
+       
+       void bar() {
+               D d = new D();
+               d.foo();
+       }
+       
+       declare warning : call(* B.foo()) : "should match";
+       declare warning : call(* A.foo()) : "should not match";
+       
+}
\ No newline at end of file
diff --git a/tests/bugs150/pr71159/pkg1/A.java b/tests/bugs150/pr71159/pkg1/A.java
new file mode 100644 (file)
index 0000000..f07afe2
--- /dev/null
@@ -0,0 +1,7 @@
+package pkg1;
+
+public class A {
+       
+       //public void foo() {}
+       
+}
\ No newline at end of file
diff --git a/tests/bugs150/pr71159/pkg1/B.java b/tests/bugs150/pr71159/pkg1/B.java
new file mode 100644 (file)
index 0000000..e931fe8
--- /dev/null
@@ -0,0 +1,3 @@
+package pkg1;
+
+public class B {}
\ No newline at end of file
diff --git a/tests/bugs150/pr71159/pkg1/C.java b/tests/bugs150/pr71159/pkg1/C.java
new file mode 100644 (file)
index 0000000..48840a4
--- /dev/null
@@ -0,0 +1,7 @@
+package pkg1;
+
+public class C {
+       
+       public void foo() {}
+       
+}
\ No newline at end of file
diff --git a/tests/bugs150/pr71159/pkg2/ITDInDiffPackage.aj b/tests/bugs150/pr71159/pkg2/ITDInDiffPackage.aj
new file mode 100644 (file)
index 0000000..fa44cbf
--- /dev/null
@@ -0,0 +1,17 @@
+package pkg2;
+import pkg1.*;
+
+public aspect ITDInDiffPackage {
+       
+       void B.foo() {}
+       
+       void bar() {
+               C c = new C();
+               c.foo();
+       }
+       
+       declare warning : call(* B.foo()) : "should not match";
+       declare warning : call(* C.foo()) : "should match";
+       
+       
+}
\ No newline at end of file
diff --git a/tests/bugs150/pr71159/pr71159.aj b/tests/bugs150/pr71159/pr71159.aj
new file mode 100644 (file)
index 0000000..d332b4a
--- /dev/null
@@ -0,0 +1,32 @@
+class A {
+       
+       private void foo() {}
+       
+}
+
+class B extends A {
+       
+       protected void foo() {}
+       
+}
+
+class C extends B {}
+
+
+class D extends C {
+       
+       public void foo() {}
+       
+}
+
+aspect X {
+       
+       void bar() {
+               D d = new D();
+               d.foo();
+       }
+       
+       declare warning : call(* B.foo()) : "should match";
+       declare warning : call(* A.foo()) : "should not match";
+       
+}
\ No newline at end of file
index 864acd2332a79f73d50aecea061687b6ccdca642..de828818f02f95d6a698a4a82052b651cc45234b 100644 (file)
@@ -334,6 +334,18 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
          runTest("inlined field access in proceed call");
   }
   
+  public void testVisibiltyInSignatureMatchingWithOverridesPart1() {
+         runTest("visibility in signature matching with overrides - 1");
+  }
+
+  public void testVisibiltyInSignatureMatchingWithOverridesPart2() {
+         runTest("visibility in signature matching with overrides - 2");
+  }
+
+  public void testVisibiltyInSignatureMatchingWithOverridesPart3() {
+         runTest("visibility in signature matching with overrides - 3");
+  }
+  
   // helper methods.....
   
   public SyntheticRepository createRepos(File cpentry) {
index a5cdcfdc1492f7662cb3f0984afe81c0e2052a60..b1f4a2354dfb03f54aa13373964eb1123fb65b51 100644 (file)
         </compile>
     </ajc-test>  
  
+    <ajc-test dir="bugs150/pr71159" pr="71159" title="visibility in signature matching with overrides - 1">
+        <compile files="pr71159.aj">
+            <message kind="warning" line="26" text="should match"/>
+        </compile>
+    </ajc-test>  
+
+    <ajc-test dir="bugs150/pr71159" pr="71159" title="visibility in signature matching with overrides - 2">
+        <compile files="PrivateITD.aj">
+            <message kind="warning" line="28" text="should match"/>
+        </compile>
+    </ajc-test>  
+
+    <ajc-test dir="bugs150/pr71159" pr="71159" title="visibility in signature matching with overrides - 3">
+        <compile files="pkg1/A.java,pkg1/B.java,pkg1/C.java,pkg2/ITDInDiffPackage.aj">
+            <message kind="warning" line="10" text="should match"/>
+        </compile>
+    </ajc-test>  
+  
     <!-- ============================================================================ -->
     <!-- ============================================================================ -->
     
index d94d3db1268e4092819e119ab08430aeefa2af43..85837fe1e25a879092924475458994f37dd8d7ac 100644 (file)
@@ -210,7 +210,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                        if (!typesAlreadyVisited.contains(toLookIn)) {
                                typesAlreadyVisited.add(toLookIn);
                                ResolvedMemberImpl foundMember = (ResolvedMemberImpl) toLookIn.lookupResolvedMember(memberToMatch);
-                               if (foundMember != null) {
+                               if (foundMember != null && isVisibleTo(memberToMatch,foundMember)) {
                                        List declaringTypes = new ArrayList();
                                        // declaring type can be unresolved if the member can from an ITD...
                                        ResolvedType resolvedDeclaringType = foundMember.getDeclaringType().resolve(toLookIn.getWorld());
@@ -231,6 +231,22 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Anno
                }
     }
 
+    /**
+     * Returns true if the parent member is visible to the child member 
+     * In the same declaring type this is always true, otherwise if parent is private
+     * it is false.
+     * @param childMember
+     * @param parentMember
+     * @return
+     */
+    private static boolean isVisibleTo(ResolvedMember childMember, ResolvedMember parentMember) {
+       if (childMember.getDeclaringType().equals(parentMember.getDeclaringType())) return true;
+       if (Modifier.isPrivate(parentMember.getModifiers())) {
+               return false;
+       } else {
+               return true;
+       }
+    }
     
     // ----