]> source.dussan.org Git - aspectj.git/commitdiff
refactoring
authoraclement <aclement>
Fri, 2 Oct 2009 03:53:47 +0000 (03:53 +0000)
committeraclement <aclement>
Fri, 2 Oct 2009 03:53:47 +0000 (03:53 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java

index 22cedb3e8763647e68c9ce6d275c0918f10e883a..a5ec396173e355b41705412d711cabcedff282e3 100644 (file)
@@ -223,19 +223,27 @@ class BcelAdvice extends Advice {
                return boType.getLazyClassGen().isWoven();
        }
 
+       private boolean aspectIsBroken() {
+               if (concreteAspect instanceof ReferenceType) {
+                       ReferenceTypeDelegate rtDelegate = ((ReferenceType) concreteAspect).getDelegate();
+                       if (!(rtDelegate instanceof BcelObjectType)) {
+                               return true;
+                       }
+               }
+               return false;
+       }
+
        @Override
        public boolean implementOn(Shadow s) {
                hasMatchedAtLeastOnce = true;
-               BcelShadow shadow = (BcelShadow) s;
 
                // pr263323 - if the aspect is broken then the delegate will not be usable for weaving
-               if (concreteAspect instanceof ReferenceType) {
-                       ReferenceTypeDelegate rtDelegate = ((ReferenceType) concreteAspect).getDelegate();
-                       if (!(rtDelegate instanceof BcelObjectType)) {
-                               return false;
-                       }
+               if (aspectIsBroken()) {
+                       return false;
                }
 
+               BcelShadow shadow = (BcelShadow) s;
+
                // remove any unnecessary exceptions if the compiler option is set to
                // error or warning and if this piece of advice throws exceptions
                // (bug 129282). This may be expanded to include other compiler warnings
index 97c49ee929bca9f4cf0e99e8e783b4c996d17cc5..a878047ef19d32cb418910476e282ab9f0432ef5 100644 (file)
@@ -2136,32 +2136,8 @@ public class BcelShadow extends Shadow {
                }
 
                // specific test for @AJ proceedInInners
-               if (munger.getConcreteAspect().isAnnotationStyleAspect()) {
-                       // if we can't find one proceed() we suspect that the call
-                       // is happening in an inner class so we don't inline it.
-                       // Note: for code style, this is done at Aspect compilation time.
-                       boolean canSeeProceedPassedToOther = false;
-                       InstructionHandle curr = adviceMethod.getBody().getStart();
-                       InstructionHandle end = adviceMethod.getBody().getEnd();
-                       ConstantPool cpg = adviceMethod.getEnclosingClass().getConstantPool();
-                       while (curr != end) {
-                               InstructionHandle next = curr.getNext();
-                               Instruction inst = curr.getInstruction();
-                               if ((inst instanceof InvokeInstruction)
-                                               && ((InvokeInstruction) inst).getSignature(cpg).indexOf("Lorg/aspectj/lang/ProceedingJoinPoint;") > 0) {
-                                       // we may want to refine to exclude stuff returning jp ?
-                                       // does code style skip inline if i write dump(thisJoinPoint) ?
-                                       canSeeProceedPassedToOther = true;// we see one pjp passed around - dangerous
-                                       break;
-                               }
-                               curr = next;
-                       }
-                       if (canSeeProceedPassedToOther) {
-                               // remember this decision to avoid re-analysis
-                               adviceMethod.setCanInline(false);
-                               weaveAroundClosure(munger, hasDynamicTest);
-                               return;
-                       }
+               if (isAnnotationStylePassingProceedingJoinPointOutOfAdvice(munger, hasDynamicTest, adviceMethod)) {
+                       return;
                }
 
                // We can't inline around methods if they have around advice on them, this
@@ -2406,6 +2382,41 @@ public class BcelShadow extends Shadow {
                }
        }
 
+       /**
+        * Check if the advice method passes a pjp parameter out via an invoke instruction - if so we can't risk inlining.
+        */
+       private boolean isAnnotationStylePassingProceedingJoinPointOutOfAdvice(BcelAdvice munger, boolean hasDynamicTest,
+                       LazyMethodGen adviceMethod) {
+               if (munger.getConcreteAspect().isAnnotationStyleAspect()) {
+                       // if we can't find one proceed() we suspect that the call
+                       // is happening in an inner class so we don't inline it.
+                       // Note: for code style, this is done at Aspect compilation time.
+                       boolean canSeeProceedPassedToOther = false;
+                       InstructionHandle curr = adviceMethod.getBody().getStart();
+                       InstructionHandle end = adviceMethod.getBody().getEnd();
+                       ConstantPool cpg = adviceMethod.getEnclosingClass().getConstantPool();
+                       while (curr != end) {
+                               InstructionHandle next = curr.getNext();
+                               Instruction inst = curr.getInstruction();
+                               if ((inst instanceof InvokeInstruction)
+                                               && ((InvokeInstruction) inst).getSignature(cpg).indexOf("Lorg/aspectj/lang/ProceedingJoinPoint;") > 0) {
+                                       // we may want to refine to exclude stuff returning jp ?
+                                       // does code style skip inline if i write dump(thisJoinPoint) ?
+                                       canSeeProceedPassedToOther = true;// we see one pjp passed around - dangerous
+                                       break;
+                               }
+                               curr = next;
+                       }
+                       if (canSeeProceedPassedToOther) {
+                               // remember this decision to avoid re-analysis
+                               adviceMethod.setCanInline(false);
+                               weaveAroundClosure(munger, hasDynamicTest);
+                               return true;
+                       }
+               }
+               return false;
+       }
+
        private InstructionList getRedoneProceedCall(InstructionFactory fact, LazyMethodGen callbackMethod, BcelAdvice munger,
                        LazyMethodGen localAdviceMethod, List<BcelVar> argVarList) {
                InstructionList ret = new InstructionList();