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;
/**
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)
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() {
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() {
}
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
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;
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);
}
}
{
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");
+ }
}
}
}
--- /dev/null
+
+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