diff options
author | Andy Clement <aclement@pivotal.io> | 2022-01-31 15:47:27 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2022-01-31 15:47:27 -0800 |
commit | fab59b5d20ee3ad5d49920c4e9fe785f58820614 (patch) | |
tree | 3b4f99e0e11032b820fd4a197833f0ef215a31db /org.aspectj.matcher | |
parent | f1cb850e40b98dadfcaf0c6ea27531399a307529 (diff) | |
download | aspectj-fab59b5d20ee3ad5d49920c4e9fe785f58820614.tar.gz aspectj-fab59b5d20ee3ad5d49920c4e9fe785f58820614.zip |
Improve annotation style if pointcut handling
This fixes:
- negating annotation style if() pointcuts doesn't work
- annotation style if() pointcut not able to use a binding
that is not exposed
Fixes #120,#122
Diffstat (limited to 'org.aspectj.matcher')
-rw-r--r-- | org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java index 015e94f89..3b4295996 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java @@ -85,11 +85,13 @@ public class IfPointcut extends Pointcut { @Override protected FuzzyBoolean matchInternal(Shadow shadow) { - if ((extraParameterFlags & Advice.ConstantReference) != 0) { - if ((extraParameterFlags & Advice.ConstantValue) != 0) { - return FuzzyBoolean.YES; - } else { - return FuzzyBoolean.NO; + if (extraParameterFlags != -1) { // make sure it isn't annotation style if relying on these values + if ((extraParameterFlags & Advice.ConstantReference) != 0) { + if ((extraParameterFlags & Advice.ConstantValue) != 0) { + return FuzzyBoolean.YES; + } else { + return FuzzyBoolean.NO; + } } } // ??? this is not maximally efficient @@ -271,9 +273,33 @@ public class IfPointcut extends Pointcut { } else if (AjcMemberMaker.TYPEX_ENCLOSINGSTATICJOINPOINT.getSignature().equals(argSignature)) { args.add(shadow.getThisEnclosingJoinPointStaticPartVar()); } else { - if (state.size() == 0 || currentStateIndex > state.size()) { + + if (state.size() == 0 || currentStateIndex > state.size()) { // if 'we have nothing else to bind from in the state object' String[] paramNames = testMethod.getParameterNames(); StringBuilder errorParameter = new StringBuilder(); + + // Support a single special situation: where the if() pointcut takes a parameter bound elsewhere + // in the pointcut but the advice does not bind it. For example: + // + // @Pointcut("this(o) && if()") public static boolean method(Foo f) { return f.isTrue();} + // @Before("method(*)") public void beforeAdvice() {} + + // The condition above is effectively saying 'if we have nothing to bind' + if ( (i+1) == testMethod.getParameterTypes().length) { // If there is just one more to bind + // As with code style, recurse just to get the variable binding information + ExposedState myState = new ExposedState(baseArgsCount); + myState.setConcreteAspect(state.getConcreteAspect()); + residueSource.findResidue(shadow, myState); + if (myState.size()==1) { + // Treat that as the parameter value the if pointcut needs + Var v = myState.get(0); + args.add(v); + ret = Test.makeAnd(ret, + Test.makeInstanceof(v, testMethod.getParameterTypes()[i].resolve(shadow.getIWorld()))); + continue; + } + } + if (paramNames != null) { errorParameter.append(testMethod.getParameterTypes()[i].getName()).append(" "); errorParameter.append(paramNames[i]); |