From edbf43c6841313ebe0e7747407cfed9b11082065 Mon Sep 17 00:00:00 2001 From: jhugunin Date: Mon, 23 Dec 2002 19:39:22 +0000 Subject: [PATCH] better errors for issingleton aspects advising own initializers also correct typing for dynamic checks on parameters to if pcds --- .../internal/compiler/ast/AspectDeclaration.java | 10 ++++++++++ weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java | 7 ++++++- .../src/org/aspectj/weaver/patterns/IfPointcut.java | 9 ++++++--- .../org/aspectj/weaver/patterns/PerSingleton.java | 12 +++++++++--- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java index 26bf18d8b..a52d3cad1 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java @@ -499,7 +499,17 @@ public class AspectDeclaration extends MemberTypeDeclaration { // body starts here codeStream.getstatic(world.makeFieldBinding(AjcMemberMaker.perSingletonField( typeX))); + Label isNull = new Label(codeStream); + codeStream.dup(); + codeStream.ifnull(isNull); codeStream.areturn(); + isNull.place(); + codeStream.new_(world.makeTypeBinding(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION)); + codeStream.dup(); + codeStream.invokespecial(world.makeMethodBindingForCall( + AjcMemberMaker.noAspectBoundExceptionInit() + )); + codeStream.athrow(); // body ends here }}); } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java b/weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java index ab5595916..80b36e255 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java @@ -186,7 +186,12 @@ public class BcelRenderer implements ITestVisitor, IExprVisitor { // assert method.isStatic() Expr[] args = call.getArgs(); //System.out.println("args: " + Arrays.asList(args)); - InstructionList callIl = renderExprs(fact, world, args); + InstructionList callIl = new InstructionList(); + for (int i=0, len=args.length; i < len; i++) { + //XXX only correct for static method calls + Type desiredType = BcelWorld.makeBcelType(method.getParameterTypes()[i]); + callIl.append(renderExpr(fact, world, args[i], desiredType)); + } //System.out.println("rendered args: " + callIl); callIl.append(Utility.createInvoke(fact, world, method)); callIl.append(createJumpBasedOnBooleanOnStack()); diff --git a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java index 1f0bac258..051a2b24d 100644 --- a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java @@ -80,7 +80,9 @@ public class IfPointcut extends Pointcut { try { ExposedState myState = new ExposedState(baseArgsCount); //System.out.println(residueSource); - residueSource.findResidue(shadow, myState); // don't care about Test + //??? some of these tests are preconditions for the if to run correctly + // this implementation will duplicate those tests, we should be more careful + Test preTest = residueSource.findResidue(shadow, myState); // might need this //System.out.println(myState); @@ -101,8 +103,9 @@ public class IfPointcut extends Pointcut { if ((extraParameterFlags & Advice.ThisEnclosingJoinPointStaticPart) != 0) { args.add(shadow.getThisEnclosingJoinPointStaticPartVar()); } - - return Test.makeCall(testMethod, (Expr[])args.toArray(new Expr[args.size()])); + Test myTest = Test.makeCall(testMethod, (Expr[])args.toArray(new Expr[args.size()])); + return Test.makeAnd(preTest, myTest); + } finally { findingResidue = false; } diff --git a/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java b/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java index e95065ece..f74d2bc22 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java +++ b/weaver/src/org/aspectj/weaver/patterns/PerSingleton.java @@ -33,9 +33,15 @@ public class PerSingleton extends PerClause { } public Test findResidue(Shadow shadow, ExposedState state) { - state.setAspectInstance( - Expr.makeFieldGet(AjcMemberMaker.perSingletonField(inAspect), inAspect)); - // XXX we need to think about whether it's null... + Expr myInstance = + Expr.makeCallExpr(AjcMemberMaker.perSingletonAspectOfMethod(inAspect), + Expr.NONE, inAspect); + + state.setAspectInstance(myInstance); + + // we have no test + // a NoAspectBoundException will be thrown if we need an instance of this + // aspect before we are bound return Literal.TRUE; } -- 2.39.5