]> source.dussan.org Git - aspectj.git/commitdiff
Fix for Bugzilla Bug 76096: Anonymous classes unaware of introductions into abstract...
authoraclement <aclement>
Tue, 19 Oct 2004 10:37:31 +0000 (10:37 +0000)
committeraclement <aclement>
Tue, 19 Oct 2004 10:37:31 +0000 (10:37 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java
tests/bugs/pr76096/ConcreteClassA.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java
tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml

index 61270166dfcab90ef6bcbbbbd3d7ded219551635..83117d409c966872c1ed16b521aefe0079cb061b 100644 (file)
@@ -15,6 +15,7 @@
 
 import java.lang.reflect.Modifier;
 import java.util.Iterator;
+import java.util.List;
 
 import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
 import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
@@ -156,7 +157,17 @@ public class AjProblemReporter extends ProblemReporter {
                
                // if we implemented this method by an inter-type declaration, then there is no error
                //??? be sure this is always right
-               ResolvedTypeX onTypeX = factory.fromEclipse(type); //abstractMethod.declaringClass);
+               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();
diff --git a/tests/bugs/pr76096/ConcreteClassA.java b/tests/bugs/pr76096/ConcreteClassA.java
new file mode 100644 (file)
index 0000000..77bbb9e
--- /dev/null
@@ -0,0 +1,50 @@
+// In the ConcreteClassA.someMethod() method, the creation of the anonymous class should
+// be ok as the ITD ensures that InterfaceA.a2() is implemented.
+
+interface InterfaceA {
+ public void a1();
+ public void a2();
+}
+
+abstract class AbstractClassA implements InterfaceA {
+  public void a1() {
+    System.out.println("AbstractClassA.a()");
+  }
+}
+
+public class ConcreteClassA extends AbstractClassA {
+  public void someMethod() {
+    InterfaceA a = new AbstractClassA() {  };
+    a.a2(); 
+  }
+  
+  public static void main(String[]argv) {
+       new ConcreteClassA().someMethod();
+       new concCB().someMethod();
+  }
+}
+
+aspect IntroAspectA {
+  public void AbstractClassA.a2() {
+    System.out.println("AbstractClassA.a2() from IntroAspectA");
+  }
+}
+
+interface IB {
+        public void m2();
+}
+
+abstract class absCB implements IB {
+       public void m1() { }
+}
+
+class concCB extends absCB {
+       public void someMethod() {
+               IB b = new IB() {};
+               b.m2();
+       }
+}
+
+aspect introAspectB {
+       public void IB.m2() {System.err.println("absCB.m1() from IB");}
+}
index 4e0cca88e0f85ee40064d92ef53979779bde3399..6e86caaccc1785b8948fc04d3a69e137f9a0ee72 100644 (file)
@@ -334,4 +334,8 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
        runTest("Optimization of cflow - counters with abstract pointcuts (5)");
   }
 
+  public void test064() {
+       runTest("Anonymous classes unaware of introductions into abstract classes");
+  }
+
 }
\ No newline at end of file
index a2684804dd9b02d3a37fb6552b6b6381d7068372..2ec496b3579cc84b9382be18d3e73f0d954505a9 100644 (file)
         <compile files="CounterTest05.java"/>
                <run class="CounterTest05"/>
     </ajc-test>
+    
+    <ajc-test dir="bugs/pr76096" pr="76096" title="Anonymous classes unaware of introductions into abstract classes">
+        <compile files="ConcreteClassA.java"/>
+        <run class="ConcreteClassA"/>
+    </ajc-test>