From ea84f573e50bd198f3412acffb7157e9d9b8b544 Mon Sep 17 00:00:00 2001 From: jhugunin Date: Thu, 1 May 2003 03:25:43 +0000 Subject: [PATCH] expanded coverage and fix for bug involving around advice with either assert or .class in the body the fix for now is just to not inline such advice, but in the future these should be transformed to inlinable constructs --- .../compiler/ast/AccessForInlineVisitor.java | 20 +++++++++++++++++++ .../compiler/ast/AdviceDeclaration.java | 4 ++++ tests/bugs/interSpecials/p1/C.java | 1 + tests/bugs/interSpecials/p2/A1.java | 6 ++++++ tests/bugs/interSpecials/p2/A2.java | 6 ++++++ tests/jimTests.xml | 12 ++++++++++- 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java index 637ab0bd1..aa195135e 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java @@ -23,6 +23,8 @@ import org.aspectj.weaver.AjcMemberMaker; import org.aspectj.weaver.ResolvedMember; import org.eclipse.jdt.internal.compiler.AbstractSyntaxTreeVisitorAdapter; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; +import org.eclipse.jdt.internal.compiler.ast.AssertStatement; +import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess; import org.eclipse.jdt.internal.compiler.ast.FieldReference; import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference; @@ -57,6 +59,10 @@ public class AccessForInlineVisitor extends AbstractSyntaxTreeVisitorAdapter { AspectDeclaration inAspect; EclipseFactory world; // alias for inAspect.world + // set to true for ClassLiteralAccess and AssertStatement + // ??? A better answer would be to transform these into inlinable forms + public boolean isInlinable = true; + public AccessForInlineVisitor(AspectDeclaration inAspect, PrivilegedHandler handler) { this.inAspect = inAspect; this.world = inAspect.factory; @@ -187,4 +193,18 @@ public class AccessForInlineVisitor extends AbstractSyntaxTreeVisitorAdapter { return; } } + /* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.IAbstractSyntaxTreeVisitor#endVisit(org.eclipse.jdt.internal.compiler.ast.AssertStatement, org.eclipse.jdt.internal.compiler.lookup.BlockScope) + */ + public void endVisit(AssertStatement assertStatement, BlockScope scope) { + isInlinable = false; + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.IAbstractSyntaxTreeVisitor#endVisit(org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess, org.eclipse.jdt.internal.compiler.lookup.BlockScope) + */ + public void endVisit(ClassLiteralAccess classLiteral, BlockScope scope) { + isInlinable = false; + } + } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java index f23502f75..aabc84624 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java @@ -163,6 +163,10 @@ public class AdviceDeclaration extends MethodDeclaration { AccessForInlineVisitor v = new AccessForInlineVisitor((AspectDeclaration)upperScope.referenceContext, handler); this.traverse(v, (ClassScope) null); + + // ??? if we found a construct that we can't inline, set + // proceedInInners so that we won't try to inline this body + if (!v.isInlinable) proceedInInners = true; } } } diff --git a/tests/bugs/interSpecials/p1/C.java b/tests/bugs/interSpecials/p1/C.java index 472afd808..160bb847c 100644 --- a/tests/bugs/interSpecials/p1/C.java +++ b/tests/bugs/interSpecials/p1/C.java @@ -1,4 +1,5 @@ package p1; public class C { + public void bar() {} } \ No newline at end of file diff --git a/tests/bugs/interSpecials/p2/A1.java b/tests/bugs/interSpecials/p2/A1.java index 4a84e592d..9b75428bb 100644 --- a/tests/bugs/interSpecials/p2/A1.java +++ b/tests/bugs/interSpecials/p2/A1.java @@ -5,6 +5,7 @@ import p1.C; public class A1 { public static void main(String[] args) { new C().foo(); + new C().bar(); } } @@ -12,4 +13,9 @@ aspect InterClass { void C.foo() { System.out.println("class: " + C.class); } + + void around(): execution(void C.bar()) { + System.out.println("class: " + C.class); + proceed(); + } } \ No newline at end of file diff --git a/tests/bugs/interSpecials/p2/A2.java b/tests/bugs/interSpecials/p2/A2.java index a29f3d5b9..003e35486 100644 --- a/tests/bugs/interSpecials/p2/A2.java +++ b/tests/bugs/interSpecials/p2/A2.java @@ -4,6 +4,7 @@ import p1.C; public class A2 { public static void main(String[] args) { new C().foo(); + new C().bar(); } } @@ -11,4 +12,9 @@ aspect InterClass { void C.foo() { assert(C.class != null); } + + void around(): execution(void C.bar()) { + assert(C.class != null); + proceed(); + } } diff --git a/tests/jimTests.xml b/tests/jimTests.xml index 0ebd8cd50..a7b32080d 100644 --- a/tests/jimTests.xml +++ b/tests/jimTests.xml @@ -1,7 +1,17 @@ - + + + + + + + + +