From 8c5d8d3a13b7c6bb8243da5eb686ddc1149b981e Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 28 Jan 2009 00:39:21 +0000 Subject: [PATCH] refactoring to make around advice lvt fixes easier to apply - and make the code a bit clearer --- .../org/aspectj/weaver/bcel/BcelShadow.java | 24 +++++++++++++------ .../bcel/MoveInstructionsWeaveTestCase.java | 10 ++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index ddc6ab6df..9db743319 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -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; } diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java index 73bd7dd3e..45bd977a4 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java @@ -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()) { -- 2.39.5