[jboss-cvs] JBossAS SVN: r73517 - in projects/aop/trunk/aop/src: test/org/jboss/test/aop/pointcut and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 20 07:19:15 EDT 2008
Author: kabir.khan at jboss.com
Date: 2008-05-20 07:19:15 -0400 (Tue, 20 May 2008)
New Revision: 73517
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/PointcutStats.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/pointcut/PointcutTestCase.java
Log:
[JBAOP-579] Classify pointcuts more finely
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/PointcutStats.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/PointcutStats.java 2008-05-20 11:18:22 UTC (rev 73516)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/PointcutStats.java 2008-05-20 11:19:15 UTC (rev 73517)
@@ -72,8 +72,12 @@
protected ASTStart start;
protected AspectManager manager;
protected boolean execution = false;
+ protected boolean methodExecution = false;
+ protected boolean constructorExecution = false;
protected boolean construction = false;
protected boolean call = false;
+ protected boolean methodCall = false;
+ protected boolean constructorCall = false;
protected boolean within = false;
protected boolean get = false;
protected boolean set = false;
@@ -91,6 +95,16 @@
return execution;
}
+ public boolean isMethodExecution()
+ {
+ return methodExecution;
+ }
+
+ public boolean isConstructorExecution()
+ {
+ return constructorExecution;
+ }
+
public boolean isConstruction()
{
return construction;
@@ -100,7 +114,17 @@
{
return call;
}
+
+ public boolean isMethodCall()
+ {
+ return methodCall;
+ }
+ public boolean isConstructorCall()
+ {
+ return constructorCall;
+ }
+
public boolean isWithin()
{
return within;
@@ -227,6 +251,8 @@
execution = true;
get = true;
set = true;
+ methodExecution = true;
+ constructorExecution = true;
return Boolean.FALSE;
}
@@ -239,6 +265,9 @@
public Object visit(ASTCall node, Object data)
{
call = true;
+ //For ASTCall the expression lives in behaviour rather than in chilren
+ //node.childrenAccept(this, node);
+ node.getBehavior().jjtAccept(this, node);
return Boolean.FALSE;
}
@@ -257,6 +286,7 @@
public Object visit(ASTExecution node, Object data)
{
execution = true;
+ node.childrenAccept(this, node);
return Boolean.FALSE;
}
@@ -266,6 +296,39 @@
return Boolean.FALSE;
}
+ public Object visit(ASTConstructor node, Object data)
+ {
+ Object parent = data; //Passed in if parent node was ASTCall or ASTExecution
+ if (parent instanceof ASTExecution)
+ {
+ execution = constructorExecution = true;
+ }
+ else if (parent instanceof ASTCall)
+ {
+ call = constructorCall = true;
+ }
+ return Boolean.FALSE;
+ }
+
+ public Object visit(ASTMethod node, Object data)
+ {
+ Object parent = data; //Passed in if parent node was ASTCall or ASTExecution
+ if (parent instanceof ASTExecution)
+ {
+ execution = methodExecution = true;
+ }
+ else if (parent instanceof ASTCall)
+ {
+ call = methodCall = true;
+ }
+ return Boolean.FALSE;
+ }
+
+ public Object visit(ASTParameter node, Object data)
+ {
+ return Boolean.FALSE;
+ }
+
public Object visit(ASTGet node, Object data)
{
get = true;
@@ -327,26 +390,11 @@
return Boolean.FALSE;
}
- public Object visit(ASTMethod node, Object data)
- {
- return Boolean.FALSE;
- }
-
public Object visit(ASTAttribute node, Object data)
{
return Boolean.FALSE;
}
- public Object visit(ASTConstructor node, Object data)
- {
- return Boolean.FALSE;
- }
-
- public Object visit(ASTParameter node, Object data)
- {
- return Boolean.FALSE;
- }
-
public Object visit(ASTAllParameter node, Object data)
{
return Boolean.FALSE;
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/pointcut/PointcutTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/pointcut/PointcutTestCase.java 2008-05-20 11:18:22 UTC (rev 73516)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/pointcut/PointcutTestCase.java 2008-05-20 11:19:15 UTC (rev 73517)
@@ -26,6 +26,9 @@
import java.util.ArrayList;
import java.util.Iterator;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.pointcut.PointcutExpression;
+import org.jboss.aop.pointcut.PointcutStats;
import org.jboss.aop.pointcut.ast.ASTStart;
import org.jboss.aop.pointcut.ast.PointcutExpressionParser;
import org.jboss.aop.pointcut.ast.PointcutExpressionParserVisitor;
@@ -375,6 +378,67 @@
checkFailures(e.failures);
}
+ public void testPointcutClassification() throws Exception
+ {
+ createAndCheckPointcut("execution(void org.acme.Class->method())", true, false, false, false, false, false, false, false);
+ createAndCheckPointcut("execution(org.acme.Class->new())", false, true, false, false, false, false, false, false);
+ createAndCheckPointcut("field(int org.acme.Class->fld)", false, false, true, true, false, false, false, false);
+ createAndCheckPointcut("get(int org.acme.Class->fld)", false, false, true, false, false, false, false, false);
+ createAndCheckPointcut("set(int org.acme.Class->fld)", false, false, false, true, false, false, false, false);
+ createAndCheckPointcut("construction(org.acme.Class->new())", false, false, false, false, true, false, false, false);
+ createAndCheckPointcut("call(int org.acme.Class->method())", false, false, false, false, false, true, false, false);
+ createAndCheckPointcut("call(org.acme.Class->new())", false, false, false, false, false, false, true, false);
+ createAndCheckPointcut("call(org.acme.Class->new())", false, false, false, false, false, false, true, false);
+ createAndCheckPointcut("all(org.acme.Class)", true, true, true, true, false, false, false, false);
+ createAndCheckPointcut("call(org.acme.Class->new()) AND withincode(* org.acme.Class->method())", false, false, false, false, false, false, true, true);
+ createAndCheckPointcut("execution(org.acme.Class->new()) OR field(* org.acme.Class->fld)", false, true, true, true, false, false, false, false);
+ }
+
+ private void createAndCheckPointcut(
+ String expression,
+ boolean methodExecution,
+ boolean constructorExecution,
+ boolean get,
+ boolean set,
+ boolean construction,
+ boolean methodCall,
+ boolean constructorCall,
+ boolean withincode) throws Exception
+ {
+ AspectManager manager = AspectManager.instance();
+ PointcutExpression pointcut = new PointcutExpression("TEST", expression);
+ manager.addPointcut(pointcut);
+ PointcutStats stats = pointcut.getStats();
+ assertEquals(methodExecution, stats.isMethodExecution());
+ assertEquals(constructorExecution, stats.isConstructorExecution());
+ assertEquals(get, stats.isGet());
+ assertEquals(set, stats.isSet());
+ assertEquals(construction, stats.isConstruction());
+ assertEquals(methodCall, stats.isMethodCall());
+ assertEquals(constructorCall, stats.isConstructorCall());
+ assertEquals(withincode, stats.isWithincode());
+
+ if (methodExecution || constructorExecution)
+ {
+ assertTrue(stats.isExecution());
+ }
+ else
+ {
+ assertFalse(stats.isExecution());
+ }
+
+ if (methodCall || constructorCall)
+ {
+ assertTrue(stats.isCall());
+ }
+ else
+ {
+ assertFalse(stats.isCall());
+ }
+ manager.removePointcut("TEST");
+ }
+
+
private void checkFailures(ArrayList failures)
{
StringBuffer buf = new StringBuffer();
More information about the jboss-cvs-commits
mailing list