]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for Bugzilla Bug 34925 v1_1_0_RC1
authorjhugunin <jhugunin>
Thu, 13 Mar 2003 19:16:53 +0000 (19:16 +0000)
committerjhugunin <jhugunin>
Thu, 13 Mar 2003 19:16:53 +0000 (19:16 +0000)
   compiler crash on yesterday's rc1 build

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseShadow.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java
tests/ajcTests.xml
tests/bugs/ConvertToUnchecked.java [new file with mode: 0644]
tests/jimTests.xml

index 2e0630f6c554d2f256f70e4cddb0720864b9f560..a8b5d3d40ea6a2845726fa8c0f0261d8d0d94ab7 100644 (file)
 
 package org.aspectj.ajdt.internal.compiler.lookup;
 
-import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
-import org.aspectj.ajdt.internal.compiler.ast.InterTypeConstructorDeclaration;
-import org.aspectj.ajdt.internal.compiler.ast.InterTypeDeclaration;
-import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
-import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
+
+import org.aspectj.ajdt.internal.compiler.ast.*;
 import org.aspectj.bridge.ISourceLocation;
-import org.aspectj.bridge.SourceLocation;
-import org.aspectj.weaver.Member;
-import org.aspectj.weaver.Shadow;
-import org.aspectj.weaver.TypeX;
-import org.aspectj.weaver.World;
+import org.aspectj.weaver.*;
 import org.aspectj.weaver.ast.Var;
-import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
-import org.eclipse.jdt.internal.compiler.ast.AstNode;
-import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall;
-import org.eclipse.jdt.internal.compiler.ast.MessageSend;
-import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.*;
 import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
 
 /**
@@ -44,8 +31,8 @@ import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
 public class EclipseShadow extends Shadow {
        EclipseFactory world;
        AstNode astNode;
-       //XXXReferenceContext context;
-       AbstractMethodDeclaration enclosingMethod;
+       ReferenceContext context;
+       //AbstractMethodDeclaration enclosingMethod;
 
        public EclipseShadow(EclipseFactory world, Kind kind, Member signature, AstNode astNode, 
                                                        ReferenceContext context)
@@ -53,8 +40,7 @@ public class EclipseShadow extends Shadow {
                super(kind, signature, null);
                this.world = world;
                this.astNode = astNode;
-               //XXX can this fail in practice?
-               this.enclosingMethod = (AbstractMethodDeclaration)context;
+               this.context = context;
        }
 
        public World getIWorld() {
@@ -63,7 +49,13 @@ public class EclipseShadow extends Shadow {
 
 
        public TypeX getEnclosingType() {
-               return world.fromBinding(enclosingMethod.binding.declaringClass);
+               if (context instanceof TypeDeclaration) {
+                       return world.fromBinding(((TypeDeclaration)context).binding);
+               } else if (context instanceof AbstractMethodDeclaration) {
+                       return world.fromBinding(((AbstractMethodDeclaration)context).binding.declaringClass);
+               } else {
+                       return ResolvedTypeX.MISSING;
+               }
        }
        
        public ISourceLocation getSourceLocation() {
@@ -72,7 +64,14 @@ public class EclipseShadow extends Shadow {
        }
 
        public Member getEnclosingCodeSignature() {
-               return world.makeResolvedMember(enclosingMethod.binding);
+               if (context instanceof TypeDeclaration) {
+                       return new Member(Member.STATIC_INITIALIZATION, getEnclosingType(), 0, 
+                                               ResolvedTypeX.VOID, "<clinit>", TypeX.NONE);
+               } else if (context instanceof AbstractMethodDeclaration) {
+                       return world.makeResolvedMember(((AbstractMethodDeclaration)context).binding);
+               } else {
+                       return null;
+               }
        }
 
        // -- all below here are only used for implementing, not in matching
@@ -114,14 +113,12 @@ public class EclipseShadow extends Shadow {
                                        world.makeResolvedMember(e.binding), astNode, context);
                } else if (astNode instanceof MessageSend) {
                        MessageSend e = (MessageSend)astNode;
+                       if (e.isSuperAccess()) return null;  // super calls don't have shadows
                        return new EclipseShadow(world, Shadow.MethodCall,
                                        world.makeResolvedMember(e.binding), astNode, context);
                } else if (astNode instanceof ExplicitConstructorCall) {
-                       //??? these need to be ignored, they don't have shadows
-                       return null;
-//                     ExplicitConstructorCall e = (ExplicitConstructorCall)astNode;
-//                     return new EclipseShadow(world, Shadow.MethodCall,
-//                                     world.makeResolvedMember(e.binding), astNode, context);                                 
+                       //??? these should be ignored, they don't have shadows
+                       return null;                            
                } else if (astNode instanceof AbstractMethodDeclaration) {
                        AbstractMethodDeclaration e = (AbstractMethodDeclaration)astNode;
                        Shadow.Kind kind;
@@ -139,13 +136,23 @@ public class EclipseShadow extends Shadow {
                                kind = Shadow.MethodExecution;
                        } else if (e instanceof ConstructorDeclaration) {
                                kind = Shadow.ConstructorExecution;
+                       } else if (e instanceof Clinit) {
+                               kind = Shadow.StaticInitialization; 
                        } else {
-                               throw new RuntimeException("unimplemented: " + e);
+                               return null;
+                               //throw new RuntimeException("unimplemented: " + e);
                        }
                        return new EclipseShadow(world, kind,
                                        world.makeResolvedMember(e.binding), astNode, context);
+               } else if (astNode instanceof TypeDeclaration) {
+                       return new EclipseShadow(world, Shadow.StaticInitialization,
+                                                       new Member(Member.STATIC_INITIALIZATION, 
+                                                               world.fromBinding(((TypeDeclaration)astNode).binding), 0, 
+                                                               ResolvedTypeX.VOID, "<clinit>", TypeX.NONE),
+                                                       astNode, context);
                } else {
-                       throw new RuntimeException("unimplemented: " + astNode);
+                       return null;
+                       //throw new RuntimeException("unimplemented: " + astNode);
                }               
        }
 
index 16bb99b1a8eceb6bd5f0623c7d649df73b559a8a..3981de98b47f415d49c588a0126eba9f8296f41c 100644 (file)
@@ -65,31 +65,31 @@ public class AjProblemReporter extends ProblemReporter {
        {
                if (!world.getWorld().getDeclareSoft().isEmpty()) {
                        Shadow callSite = world.makeShadow(location, referenceContext);
-                       if (callSite == null) {
-                               super.unhandledException(exceptionType, location);
-                               return;
-                       }
                        Shadow enclosingExec = world.makeShadow(referenceContext);
-       //              System.err.println("about to show error for unhandled exception: "  + exceptionType + 
-       //                              " at " + location + " in " + referenceContext);
-                       
+//                     System.err.println("about to show error for unhandled exception: "  + new String(exceptionType.sourceName()) + 
+//                                     " at " + location + " in " + referenceContext);         
                        
                        for (Iterator i = world.getWorld().getDeclareSoft().iterator(); i.hasNext(); ) {
                                DeclareSoft d = (DeclareSoft)i.next();
-                               FuzzyBoolean match = d.getPointcut().match(callSite);
-                               if (match.alwaysTrue()) {
-                                       //System.err.println("matched callSite: "  + callSite + " with " + d);
-                                       return;
-                               } else if (!match.alwaysFalse()) {
-                                       throw new RuntimeException("unimplemented, shouldn't have fuzzy match here");
+                               if (callSite != null) {
+                                       FuzzyBoolean match = d.getPointcut().match(callSite);
+                                       if (match.alwaysTrue()) {
+                                               //System.err.println("matched callSite: "  + callSite + " with " + d);
+                                               return;
+                                       } else if (!match.alwaysFalse()) {
+                                               //!!! need this check to happen much sooner
+                                               //throw new RuntimeException("unimplemented, shouldn't have fuzzy match here");
+                                       }
                                }
-                               
-                               match = d.getPointcut().match(enclosingExec);
-                               if (match.alwaysTrue()) {
-                                       //System.err.println("matched enclosingExec: "  + enclosingExec + " with " + d);
-                                       return;
-                               } else if (!match.alwaysFalse()) {
-                                       throw new RuntimeException("unimplemented, shouldn't have fuzzy match here");
+                               if (enclosingExec != null) {
+                                       FuzzyBoolean match = d.getPointcut().match(enclosingExec);
+                                       if (match.alwaysTrue()) {
+                                               //System.err.println("matched enclosingExec: "  + enclosingExec + " with " + d);
+                                               return;
+                                       } else if (!match.alwaysFalse()) {
+                                               //!!! need this check to happen much sooner
+                                               //throw new RuntimeException("unimplemented, shouldn't have fuzzy match here");
+                                       }
                                }
                        }
                }
index c524c71911f98e3ff9bbc4c4389a69bf20fb5943..2f591fff5d3fed57790d3ba10c95f76863fae803 100644 (file)
         <run class="AspectInitError"/>
     </ajc-test>
     
+    <ajc-test dir="bugs" pr="34925"
+      title="declare soft and throw statements">
+        <compile files="ConvertToUnchecked.java"/>
+        <run class="ConvertToUnchecked"/>
+    </ajc-test>
+    
 </suite>
diff --git a/tests/bugs/ConvertToUnchecked.java b/tests/bugs/ConvertToUnchecked.java
new file mode 100644 (file)
index 0000000..2c7eb6c
--- /dev/null
@@ -0,0 +1,68 @@
+
+import org.aspectj.testing.Tester;
+
+/** Bugzilla Bug 34925  
+   compiler crash on yesterday's rc1 build 
+ */
+import java.io.*;
+
+public aspect ConvertToUnchecked {
+       
+       public static void main(String[] args) {
+               try {
+                       Foo foo = new Foo("hello");
+                       Tester.check(false, "shouldn't get here");
+               } catch (PersistenceException pe) {
+               }
+       }
+       
+    // convert IOExceptions in Foo to PersistenceException
+    pointcut module() : within(Foo);
+  
+       after() throwing (IOException e) : module() {
+          throw new PersistenceException(e);
+       }
+    declare soft: (IOException): module();
+}
+
+class PersistenceException extends RuntimeException 
+{
+  public PersistenceException(Throwable cause) {
+    super(cause);
+  }
+}
+
+
+class Root {
+       Root(String s) throws IOException {
+       }
+}
+
+class Foo extends Root {
+       Foo(String s) {
+               super(s);
+       }
+       
+       static {
+               if (false) {
+                       getFile();
+                       throw new IOException("bar");
+               }
+               
+       }
+       
+       {
+               if (false) throw new IOException("bar");
+       }
+       
+       File f = getFile();
+       
+       static File getFile() throws IOException {
+               throw new IOException("bad");
+       }
+       
+       
+       public void m() {
+               throw new IOException("hi");
+       }
+}
\ No newline at end of file
index 7c1c4af1fe8338872a68a12589abe377cd02e4ec..a0ad71ec7c22e88fdffe9b1bfe04e56b3785ce93 100644 (file)
@@ -1,6 +1,8 @@
 <!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd">
 <suite>
 
+
+
     <!--
     
     <ajc-test dir="new" pr="885"