diff options
author | acolyer <acolyer> | 2004-08-18 08:25:46 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2004-08-18 08:25:46 +0000 |
commit | 7fd50c75ae779195b87922c5ffd839ac7a6910bf (patch) | |
tree | ef161539e5d9ad7154c3a2ae97db270ab16e73c4 | |
parent | 5d2c29e5769f11763514a173690c290f3111e64b (diff) | |
download | aspectj-7fd50c75ae779195b87922c5ffd839ac7a6910bf.tar.gz aspectj-7fd50c75ae779195b87922c5ffd839ac7a6910bf.zip |
test for Bugzilla Bug 64069
ITD name clashes with private members
-rw-r--r-- | tests/bugs/PR64069.aj | 43 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java | 5 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml | 10 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/ResolvedTypeX.java | 25 |
4 files changed, 81 insertions, 2 deletions
diff --git a/tests/bugs/PR64069.aj b/tests/bugs/PR64069.aj new file mode 100644 index 000000000..a83041b17 --- /dev/null +++ b/tests/bugs/PR64069.aj @@ -0,0 +1,43 @@ + + +aspect Aspect { + + public A.new() { // CE L5 + super(); + System.out.println("ITD A()"); + } + + public void A.bar() { // CE L10 + System.out.println("ITD bar"); + } + + public int A.x; // CE L14 + +} + +class A { + + void foo() { + A a = new A(); + bar(); + } + + private int x; + + private A() { + super(); + System.out.println("private A()"); + } + + private void bar() { + System.out.println("private bar"); + } + +} + +public class PR64069 { + + static public void main(String[] args) { + new A().foo(); + } +}
\ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java b/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java index ec5513053..6127997d2 100644 --- a/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java @@ -234,5 +234,10 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { assertTrue("Output should contain 'CAUSE=org.aspectj.lang.NoAspectBoundException' but is '"+s+"'", s.indexOf("CAUSE=org.aspectj.lang.NoAspectBoundException")!=-1); } + + public void test044_ITDnameClashes() { + runTest("ITD name clashes with private members"); + } + } diff --git a/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml b/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml index 1ef453ef8..e6f71c3c0 100644 --- a/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml +++ b/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml @@ -335,3 +335,13 @@ <compile files="pr62642.java"/> <run class="pr62642"/> </ajc-test> + + <ajc-test dir="bugs" pr="64069" + title="ITD name clashes with private members"> + <compile files="PR64069.aj"> + <message kind="error" line="5" text="conflicts with existing member"/> + <message kind="error" line="10" text="conflicts with existing member"/> + <message kind="error" line="14" text="conflicts with existing member"/> + </compile> + </ajc-test> + diff --git a/weaver/src/org/aspectj/weaver/ResolvedTypeX.java b/weaver/src/org/aspectj/weaver/ResolvedTypeX.java index c21a5db91..3fbf7d588 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedTypeX.java +++ b/weaver/src/org/aspectj/weaver/ResolvedTypeX.java @@ -1140,8 +1140,12 @@ public abstract class ResolvedTypeX extends TypeX { munger.getSourceLocation()) ); } - } else { - //interTypeMungers.add(munger); + } else if (isDuplicateMemberWithinTargetType(existingMember,this,sig)) { + getWorld().getMessageHandler().handleMessage( + MessageUtil.error(WeaverMessages.format(WeaverMessages.ITD_MEMBER_CONFLICT,munger.getAspectType().getName(), + existingMember), + munger.getSourceLocation()) + );; } //return; } @@ -1149,6 +1153,23 @@ public abstract class ResolvedTypeX extends TypeX { return true; } + // we know that the member signature matches, but that the member in the target type is not visible to the aspect. + // this may still be disallowed if it would result in two members within the same declaring type with the same + // signature AND more than one of them is concrete AND they are both visible within the target type. + private boolean isDuplicateMemberWithinTargetType(ResolvedMember existingMember, ResolvedTypeX targetType,ResolvedMember itdMember) { + if ( (existingMember.isAbstract() || itdMember.isAbstract())) return false; + TypeX declaringType = existingMember.getDeclaringType(); + if (!targetType.equals(declaringType)) return false; + // now have to test that itdMember is visible from targetType + if (itdMember.isPrivate()) return false; + if (itdMember.isPublic()) return true; + // must be in same package to be visible then... + if (!targetType.getPackageName().equals(itdMember.getDeclaringType().getPackageName())) return false; + + // trying to put two members with the same signature into the exact same type..., and both visible in that type. + return true; + } + public boolean checkLegalOverride(ResolvedMember parent, ResolvedMember child) { //System.err.println("check: " + child.getDeclaringType() + " overrides " + parent.getDeclaringType()); if (!parent.getReturnType().equals(child.getReturnType())) { |