From: aclement Date: Thu, 20 Jan 2005 14:44:39 +0000 (+0000) Subject: Fix for Bug 83303: complier error when mixing inheritance, overriding and polymorphism X-Git-Tag: Root_AspectJ5_Development~76 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5d281fd8e98c5c2bec4365d3fc340e2d5f04becc;p=aspectj.git Fix for Bug 83303: complier error when mixing inheritance, overriding and polymorphism --- diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java index 0f92785a1..9a6e11857 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java @@ -136,6 +136,38 @@ public class AjProblemReporter extends ProblemReporter { } + public void inheritedMethodReducesVisibility(SourceTypeBinding type, MethodBinding concreteMethod, MethodBinding[] abstractMethods) { + // if we implemented this method by a public inter-type declaration, then there is no error + + ResolvedTypeX onTypeX = null; + // If the type is anonymous, look at its supertype + if (!type.isAnonymousType()) { + onTypeX = factory.fromEclipse(type); + } else { + // Hmmm. If the ITD is on an interface that is being 'instantiated' using an anonymous type, + // we sort it out elsewhere and don't come into this method - + // so we don't have to worry about interfaces, just the superclass. + onTypeX = factory.fromEclipse(type.superclass()); //abstractMethod.declaringClass); + } + for (Iterator i = onTypeX.getInterTypeMungersIncludingSupers().iterator(); i.hasNext(); ) { + ConcreteTypeMunger m = (ConcreteTypeMunger)i.next(); + ResolvedMember sig = m.getSignature(); + if (!Modifier.isAbstract(sig.getModifiers())) { + if (ResolvedTypeX + .matches( + AjcMemberMaker.interMethod( + sig, + m.getAspectType(), + sig.getDeclaringType().isInterface( + factory.getWorld())), + EclipseFactory.makeResolvedMember(concreteMethod))) { + return; + } + } + } + + super.inheritedMethodReducesVisibility(type,concreteMethod,abstractMethods); + } public void abstractMethodMustBeImplemented( SourceTypeBinding type, diff --git a/tests/bugs150/PR83303.java b/tests/bugs150/PR83303.java new file mode 100644 index 000000000..a81efda82 --- /dev/null +++ b/tests/bugs150/PR83303.java @@ -0,0 +1,26 @@ + + +// Protected method in A +class A { + protected void m1 (){System.err.println("A.m1()");} +} + + +// Simple subclass +public class PR83303 extends A { + public static void main(String []argv) { + System.err.println("Hi"); + new PR83303().m1(); + } +} + + +aspect C { + declare parents: PR83303 implements I; + public void PR83303.m1(){System.err.println("ITD version of m1");} +} + + +interface I { + public void m1(); +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java index 9c4c08fdc..0fa039be0 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java @@ -73,6 +73,11 @@ public class Ajc150TestsNoHarness extends TestUtils { // } } + public void testCanOverrideProtectedMethodsViaITDandDecp_pr83303() { + CompilationResult cR = ajc(baseDir,new String[]{"PR83303.java"}); + assertTrue("Should be no errors:"+cR,!cR.hasErrorMessages()); + } +