]> source.dussan.org Git - aspectj.git/commitdiff
refactoring to make around advice lvt fixes easier to apply - and make the code a...
authoraclement <aclement>
Wed, 28 Jan 2009 00:39:21 +0000 (00:39 +0000)
committeraclement <aclement>
Wed, 28 Jan 2009 00:39:21 +0000 (00:39 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java

index ddc6ab6df7395c2b4dab7e6f108571e8a8ecfed4..9db74331904198a6147572d1a5bc0d9849151ed8 100644 (file)
@@ -2138,12 +2138,12 @@ public class BcelShadow extends Shadow {
                enclosingMethod.setCanInline(false);
 
                // start by exposing various useful things into the frame
-               final InstructionFactory fact = getFactory();
 
                // now generate the aroundBody method
                // eg. "private static final void method_aroundBody0(M, M, String, org.aspectj.lang.JoinPoint)"
                LazyMethodGen extractedShadowMethod = extractShadowInstructionsIntoNewMethod(NameMangler.aroundShadowMethodName(
-                               getSignature(), new Integer(getEnclosingClass().getNewGeneratedNameTag()).toString()), Modifier.PRIVATE, munger);
+                               getSignature(), new Integer(getEnclosingClass().getNewGeneratedNameTag()).toString()), Modifier.PRIVATE, munger
+                               .getSourceLocation());
 
                List argsToCallLocalAdviceMethodWith = new ArrayList();
                List proceedVarList = new ArrayList();
@@ -2225,6 +2225,8 @@ public class BcelShadow extends Shadow {
                        varMap.put(i - extraParamOffset, i);
                }
 
+               final InstructionFactory fact = getFactory();
+
                localAdviceMethod.getBody().insert(
                                BcelClassWeaver.genInlineInstructions(adviceMethod, localAdviceMethod, varMap, fact, true));
 
@@ -2693,7 +2695,7 @@ public class BcelShadow extends Shadow {
                int linenumber = getSourceLine();
                // MOVE OUT ALL THE INSTRUCTIONS IN MY SHADOW INTO ANOTHER METHOD!
                LazyMethodGen callbackMethod = extractShadowInstructionsIntoNewMethod(NameMangler.aroundShadowMethodName(getSignature(),
-                               new Integer(getEnclosingClass().getNewGeneratedNameTag()).toString()), 0, munger);
+                               new Integer(getEnclosingClass().getNewGeneratedNameTag()).toString()), 0, munger.getSourceLocation());
 
                BcelVar[] adviceVars = munger.getExposedStateAsBcelVars(true);
 
@@ -2968,12 +2970,20 @@ public class BcelShadow extends Shadow {
 
        // ---- extraction methods
 
-       public LazyMethodGen extractShadowInstructionsIntoNewMethod(String newMethodName, int visibilityModifier, ShadowMunger munger) {
-               LazyMethodGen.assertGoodBody(range.getBody(), newMethodName);
+       /**
+        * Extract the instructions in the shadow to a new method.
+        * 
+        * @param extractedMethodName name for the new method
+        * @param extractedMethodVisibilityModifier visibility modifiers for the new method
+        * @param adviceSourceLocation source location of the advice affecting the shadow
+        */
+       public LazyMethodGen extractShadowInstructionsIntoNewMethod(String extractedMethodName, int extractedMethodVisibilityModifier,
+                       ISourceLocation adviceSourceLocation) {
+               LazyMethodGen.assertGoodBody(range.getBody(), extractedMethodName);
                if (!getKind().allowsExtraction())
                        throw new BCException("Attempt to extract method from a shadow kind that does not support this operation (" + getKind()
                                        + ")");
-               LazyMethodGen freshMethod = createShadowMethodGen(newMethodName, visibilityModifier);
+               LazyMethodGen freshMethod = createShadowMethodGen(extractedMethodName, extractedMethodVisibilityModifier);
 
                // System.err.println("******");
                // System.err.println("ABOUT TO EXTRACT METHOD for" + this);
@@ -2987,7 +2997,7 @@ public class BcelShadow extends Shadow {
                if (getKind() == PreInitialization) {
                        addPreInitializationReturnCode(freshMethod, getSuperConstructorParameterTypes());
                }
-               getEnclosingClass().addMethodGen(freshMethod, munger.getSourceLocation());
+               getEnclosingClass().addMethodGen(freshMethod, adviceSourceLocation);
 
                return freshMethod;
        }
index 73bd7dd3e098c8f4fd253f1f48b7e4154c297e88..45bd977a47f6950c1bf8f8f98b9dc675d0df204f 100644 (file)
@@ -36,8 +36,9 @@ public class MoveInstructionsWeaveTestCase extends WeaveTestCase {
 
                        public boolean implementOn(Shadow s) {
                                BcelShadow shadow = (BcelShadow) s;
-                               LazyMethodGen newMethod = shadow.extractMethod(
-                                               NameMangler.getExtractableName(shadow.getSignature()) + "_extracted", 0, this);
+                               LazyMethodGen newMethod = shadow.extractShadowInstructionsIntoNewMethod(NameMangler.getExtractableName(shadow
+                                               .getSignature())
+                                               + "_extracted", 0, this.getSourceLocation());
                                shadow.getRange().append(shadow.makeCallToCallback(newMethod));
 
                                if (!shadow.isFallsThrough()) {
@@ -61,8 +62,9 @@ public class MoveInstructionsWeaveTestCase extends WeaveTestCase {
 
                        public boolean implementOn(Shadow s) {
                                BcelShadow shadow = (BcelShadow) s;
-                               LazyMethodGen newMethod = shadow.extractMethod(NameMangler.getExtractableName(shadow.getSignature()) + "_extracted"
-                                               + counter++, 0, this);
+                               LazyMethodGen newMethod = shadow.extractShadowInstructionsIntoNewMethod(NameMangler.getExtractableName(shadow
+                                               .getSignature())
+                                               + "_extracted" + counter++, 0, this.getSourceLocation());
                                shadow.getRange().append(shadow.makeCallToCallback(newMethod));
 
                                if (!shadow.isFallsThrough()) {