--- /dev/null
+// for Bug#: 33635
+import org.aspectj.testing.Tester;
+
+
+public class NotIf {
+ public static void main(String[] args) {
+ Tester.checkEqual(Aspect1.ranNone, 0, "shouldn't run");
+ Tester.checkEqual(Aspect1.ranTwo, 2, "should run");
+ Tester.checkEqual(Aspect2.ran, 1, "should run with values");
+ }
+}
+
+aspect Aspect1 {
+ static int ranNone = 0;
+ static int ranTwo = 0;
+
+ static boolean testTrue() { return true; }
+
+ static boolean testFalse() { return false; }
+
+ before(): execution(void main(..)) && !if(testTrue()) {
+ ranNone += 1;
+ }
+
+ before(): execution(void main(..)) && if(!testTrue()) {
+ ranNone += 1;
+ }
+ before(): execution(void main(..)) && !if(testFalse()) {
+ ranTwo += 1;
+ }
+
+ before(): execution(void main(..)) && if(!testFalse()) {
+ ranTwo += 1;
+ }
+}
+
+aspect Aspect2 {
+ static int ran = 0;
+
+ static boolean testValues(int i, String s, Object o) {
+ return false;
+ }
+
+ before(String[] a): execution(void main(String[])) &&
+ !if(testValues(a.length, a.toString(), a)) && args(a)
+ {
+ ran += 1;
+ }
+}
import org.aspectj.weaver.ResolvedTypeX;
import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.ShadowMunger;
+import org.aspectj.weaver.ast.*;
import org.aspectj.weaver.ast.Expr;
import org.aspectj.weaver.ast.Literal;
import org.aspectj.weaver.ast.Test;
return "if(" + testMethod + ")";
}
+
+ //??? The implementation of name binding and type checking in if PCDs is very convoluted
+ // There has to be a better way...
private boolean findingResidue = false;
public Test findResidue(Shadow shadow, ExposedState state) {
if (findingResidue) return Literal.TRUE;
try {
ExposedState myState = new ExposedState(baseArgsCount);
//System.out.println(residueSource);
- //??? 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
+ //??? we throw out the test that comes from this walk. All we want here
+ // is bindings for the arguments
+ residueSource.findResidue(shadow, myState);
//System.out.println(myState);
+ Test ret = Literal.TRUE;
+
List args = new ArrayList();
for (int i=0; i < baseArgsCount; i++) {
- args.add(myState.get(i));
+ Var v = myState.get(i);
+ args.add(v);
+ ret = Test.makeAnd(ret,
+ Test.makeInstanceof(v,
+ testMethod.getParameterTypes()[i].resolve(shadow.getIWorld())));
}
// handle thisJoinPoint parameters
if ((extraParameterFlags & Advice.ThisEnclosingJoinPointStaticPart) != 0) {
args.add(shadow.getThisEnclosingJoinPointStaticPartVar());
}
- Test myTest = Test.makeCall(testMethod, (Expr[])args.toArray(new Expr[args.size()]));
- return Test.makeAnd(preTest, myTest);
+
+ ret = Test.makeAnd(ret, Test.makeCall(testMethod, (Expr[])args.toArray(new Expr[args.size()])));
+
+ return ret;
} finally {
findingResidue = false;