]> source.dussan.org Git - aspectj.git/commitdiff
better errors for issingleton aspects advising own initializers
authorjhugunin <jhugunin>
Mon, 23 Dec 2002 19:39:22 +0000 (19:39 +0000)
committerjhugunin <jhugunin>
Mon, 23 Dec 2002 19:39:22 +0000 (19:39 +0000)
also correct typing for dynamic checks on parameters to if pcds

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java
weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java
weaver/src/org/aspectj/weaver/patterns/IfPointcut.java
weaver/src/org/aspectj/weaver/patterns/PerSingleton.java

index 26bf18d8bc7b7a9938eedf090ddb3f3d63ea5296..a52d3cad1912b2b3ab5de670b24b6f00bf03d720 100644 (file)
@@ -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
                        }});
        }
index ab5595916fd58a6829c9f6878e295ec90cdb6bff..80b36e2558e7b467ac5bd5948cc217c64f71b09c 100644 (file)
@@ -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());
index 1f0bac25839ea3549ec3a5a76a594526c10a485d..051a2b24d8b49f67cd1974c3ee8dab64350817a0 100644 (file)
@@ -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;
                }
index e95065ece034777cc645254f00c3df7c82a89891..f74d2bc22b55b6a0d06a3d79f7c47d7d1c4b331c 100644 (file)
@@ -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;
     }