public static Test suite() {
TestSuite suite = new TestSuite("All tests");
- suite.addTestSuite(ataspectj.SingletonAspectBindingsTest.class);
- suite.addTestSuite(ataspectj.CflowTest.class);
- suite.addTestSuite(ataspectj.PointcutReferenceTest.class);
- suite.addTestSuite(ataspectj.AfterXTest.class);
- //FIXME AV - fix the pc grammar to support if for @AJ aspects
- System.err.println("(AllTests: IfPointcutTest fails)");
- //suite.addTestSuite(IfPointcutTest.class);
- suite.addTestSuite(ataspectj.XXJoinPointTest.class);
- suite.addTestSuite(ataspectj.PrecedenceTest.class);
- suite.addTestSuite(ataspectj.BindingTest.class);
- suite.addTestSuite(ataspectj.PerClauseTest.class);
+ suite.addTestSuite(SingletonAspectBindingsTest.class);
+ suite.addTestSuite(CflowTest.class);
+ suite.addTestSuite(PointcutReferenceTest.class);
+ suite.addTestSuite(AfterXTest.class);
+ suite.addTestSuite(IfPointcutTest.class);
+ suite.addTestSuite(XXJoinPointTest.class);
+ suite.addTestSuite(PrecedenceTest.class);
+ suite.addTestSuite(BindingTest.class);
+ suite.addTestSuite(PerClauseTest.class);
suite.addTestSuite(AroundInlineMungerTest.class);
suite.addTestSuite(SingletonInheritanceTest.class);
suite.addTestSuite(PerClauseInheritanceTest.class);
import org.aspectj.weaver.patterns.TypePattern;
import org.aspectj.weaver.patterns.PerFromSuper;
import org.aspectj.weaver.patterns.PointcutVisitor;
+import org.aspectj.weaver.patterns.IdentityPointcutVisitor;
+import org.aspectj.weaver.patterns.IfPointcut;
+import org.aspectj.weaver.patterns.AndPointcut;
+import org.aspectj.weaver.patterns.NotPointcut;
+import org.aspectj.weaver.patterns.OrPointcut;
import java.util.ArrayList;
import java.util.Collections;
final PerClause perClause;
if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERCFLOW.getName())) {
pointcutString = PerClause.KindAnnotationPrefix.PERCFLOW.extractPointcut(perClauseString);
- poincut = parsePointcut(pointcutString, struct);
+ poincut = parsePointcut(pointcutString, struct, false);
perClause = new PerCflow(poincut, false);
} else if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERCFLOWBELOW.getName())) {
pointcutString = PerClause.KindAnnotationPrefix.PERCFLOWBELOW.extractPointcut(perClauseString);
- poincut = parsePointcut(pointcutString, struct);
+ poincut = parsePointcut(pointcutString, struct, false);
perClause = new PerCflow(poincut, true);
} else if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERTARGET.getName())) {
pointcutString = PerClause.KindAnnotationPrefix.PERTARGET.extractPointcut(perClauseString);
- poincut = parsePointcut(pointcutString, struct);
+ poincut = parsePointcut(pointcutString, struct, false);
perClause = new PerObject(poincut, false);
} else if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERTHIS.getName())) {
pointcutString = PerClause.KindAnnotationPrefix.PERTHIS.extractPointcut(perClauseString);
- poincut = parsePointcut(pointcutString, struct);
+ poincut = parsePointcut(pointcutString, struct, false);
perClause = new PerObject(poincut, true);
} else if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERTYPEWITHIN.getName())) {
pointcutString = PerClause.KindAnnotationPrefix.PERTYPEWITHIN.extractPointcut(perClauseString);
if (preResolvedPointcut != null) {
pc = preResolvedPointcut.getPointcut();
} else {
- pc = parsePointcut(beforeAdvice.getValue().stringifyValue(), struct);
+ pc = parsePointcut(beforeAdvice.getValue().stringifyValue(), struct, false);
if (pc == null) return false;//parse error
pc.resolve(binding);
}
if (preResolvedPointcut != null) {
pc = preResolvedPointcut.getPointcut();
} else {
- pc = parsePointcut(afterAdvice.getValue().stringifyValue(), struct);
+ pc = parsePointcut(afterAdvice.getValue().stringifyValue(), struct, false);
if (pc == null) return false;//parse error
pc.resolve(binding);
}
if (preResolvedPointcut != null) {
pc = preResolvedPointcut.getPointcut();
} else {
- pc = parsePointcut(pointcut, struct);
+ pc = parsePointcut(pointcut, struct, false);
if (pc == null) return false;//parse error
pc.resolve(binding);
}
if (preResolvedPointcut != null) {
pc = preResolvedPointcut.getPointcut();
} else {
- pc = parsePointcut(pointcut, struct);
+ pc = parsePointcut(pointcut, struct, false);
if (pc == null) return false;//parse error
pc.resolve(binding);
}
if (preResolvedPointcut != null) {
pc = preResolvedPointcut.getPointcut();
} else {
- pc = parsePointcut(aroundAdvice.getValue().stringifyValue(), struct);
+ pc = parsePointcut(aroundAdvice.getValue().stringifyValue(), struct, false);
if (pc == null) return false;//parse error
pc.resolve(binding);
}
// use a LazyResolvedPointcutDefinition so that the pointcut is resolved lazily
// since for it to be resolved, we will need other pointcuts to be registered as well
- Pointcut pc = parsePointcut(pointcutExpr.getValue().stringifyValue(), struct);
+ Pointcut pc = parsePointcut(pointcutExpr.getValue().stringifyValue(), struct, true);
if (pc == null) return;//parse error
// do not resolve binding now but lazily
pc.setLocation(struct.context, -1, -1);
struct.context,
bindings
);
- Pointcut pc = parsePointcut(declareError.getValue().stringifyValue(), struct);
+ Pointcut pc = parsePointcut(declareError.getValue().stringifyValue(), struct, false);
if (pc == null) {
hasError = false;//cannot parse pointcut
} else {
struct.context,
bindings
);
- Pointcut pc = parsePointcut(declareWarning.getValue().stringifyValue(), struct);
+ Pointcut pc = parsePointcut(declareWarning.getValue().stringifyValue(), struct, false);
if (pc == null) {
hasWarning = false;//cannot parse pointcut
} else {
*
* @param pointcutString
* @param location
+ * @param allowIf
* @return
*/
- private static Pointcut parsePointcut(String pointcutString, AjAttributeStruct location) {
+ private static Pointcut parsePointcut(String pointcutString, AjAttributeStruct location, boolean allowIf) {
try {
Pointcut pointcut = new PatternParser(pointcutString, location.context).parsePointcut();
+ if (!allowIf && pointcutString.indexOf("if()") >= 0 && hasIf(pointcut)) {
+ reportError("if() pointcut is not allowed at this pointcut location '" + pointcutString +"'", location);
+ return null;
+ }
pointcut.setLocation(location.context, -1, -1);//FIXME -1,-1 is not good enough
return pointcut;
} catch (ParserException e) {
}
}
+ private static boolean hasIf(Pointcut pointcut) {
+ IfFinder visitor = new IfFinder();
+ pointcut.accept(visitor, null);
+ return visitor.hasIf;
+ }
+
/**
* Parse the given type pattern, return null on failure and issue an error
*
return null;
}
}
+
+ /**
+ * Look for an if() pointcut
+ */
+ private static class IfFinder extends IdentityPointcutVisitor {
+ boolean hasIf = false;
+ public Object visit(IfPointcut node, Object data) {
+ if (node.alwaysFalse() || node.alwaysTrue()) {
+ ;//IfFalse / IfTrue
+ } else {
+ hasIf = true;
+ }
+ return node;
+ }
+
+ public Object visit(AndPointcut node, Object data) {
+ if (!hasIf) node.getLeft().accept(this, data);
+ if (!hasIf) node.getLeft().accept(this, data);
+ return node;
+ }
+
+ public Object visit(NotPointcut node, Object data) {
+ if (!hasIf) node.getNegatedPointcut().accept(this, data);
+ return node;
+ }
+
+ public Object visit(OrPointcut node, Object data) {
+ if (!hasIf) node.getLeft().accept(this, data);
+ if (!hasIf) node.getLeft().accept(this, data);
+ return node;
+ }
+ }
}