summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--weaver/src/org/aspectj/weaver/internal/tools/PointcutDesignatorHandlerBasedPointcut.java19
-rw-r--r--weaver/src/org/aspectj/weaver/internal/tools/PointcutExpressionImpl.java7
-rw-r--r--weaver/src/org/aspectj/weaver/reflect/ReflectionFastMatchInfo.java42
-rw-r--r--weaver/src/org/aspectj/weaver/tools/ContextBasedMatcher.java11
-rw-r--r--weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java35
5 files changed, 101 insertions, 13 deletions
diff --git a/weaver/src/org/aspectj/weaver/internal/tools/PointcutDesignatorHandlerBasedPointcut.java b/weaver/src/org/aspectj/weaver/internal/tools/PointcutDesignatorHandlerBasedPointcut.java
index 824e52192..63a7139e8 100644
--- a/weaver/src/org/aspectj/weaver/internal/tools/PointcutDesignatorHandlerBasedPointcut.java
+++ b/weaver/src/org/aspectj/weaver/internal/tools/PointcutDesignatorHandlerBasedPointcut.java
@@ -27,6 +27,7 @@ import org.aspectj.weaver.patterns.FastMatchInfo;
import org.aspectj.weaver.patterns.IScope;
import org.aspectj.weaver.patterns.PatternNodeVisitor;
import org.aspectj.weaver.patterns.Pointcut;
+import org.aspectj.weaver.reflect.ReflectionFastMatchInfo;
import org.aspectj.weaver.reflect.ReflectionShadow;
import org.aspectj.weaver.reflect.ReflectionWorld;
import org.aspectj.weaver.tools.ContextBasedMatcher;
@@ -60,14 +61,18 @@ public class PointcutDesignatorHandlerBasedPointcut extends Pointcut{
* @see org.aspectj.weaver.patterns.Pointcut#fastMatch(org.aspectj.weaver.patterns.FastMatchInfo)
*/
public FuzzyBoolean fastMatch(FastMatchInfo info) {
- try {
- return FuzzyBoolean.fromBoolean(
- this.matcher.couldMatchJoinPointsInType(
- Class.forName(info.getType().getName(),false,world.getClassLoader()))
- );
- } catch (ClassNotFoundException cnfEx) {
- return FuzzyBoolean.MAYBE;
+ if (info instanceof ReflectionFastMatchInfo) {
+ try {
+ return FuzzyBoolean.fromBoolean(
+ this.matcher.couldMatchJoinPointsInType(
+ Class.forName(info.getType().getName(),false,world.getClassLoader()),
+ ((ReflectionFastMatchInfo)info).getMatchingContext())
+ );
+ } catch (ClassNotFoundException cnfEx) {
+ return FuzzyBoolean.MAYBE;
+ }
}
+ throw new IllegalStateException("Can only match user-extension pcds against Reflection FastMatchInfo objects");
}
/* (non-Javadoc)
diff --git a/weaver/src/org/aspectj/weaver/internal/tools/PointcutExpressionImpl.java b/weaver/src/org/aspectj/weaver/internal/tools/PointcutExpressionImpl.java
index 631cadcad..d9361a781 100644
--- a/weaver/src/org/aspectj/weaver/internal/tools/PointcutExpressionImpl.java
+++ b/weaver/src/org/aspectj/weaver/internal/tools/PointcutExpressionImpl.java
@@ -14,6 +14,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
+import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.World;
import org.aspectj.weaver.ast.Literal;
@@ -23,13 +24,13 @@ import org.aspectj.weaver.patterns.ArgsAnnotationPointcut;
import org.aspectj.weaver.patterns.ArgsPointcut;
import org.aspectj.weaver.patterns.CflowPointcut;
import org.aspectj.weaver.patterns.ExposedState;
-import org.aspectj.weaver.patterns.FastMatchInfo;
import org.aspectj.weaver.patterns.IfPointcut;
import org.aspectj.weaver.patterns.NotAnnotationTypePattern;
import org.aspectj.weaver.patterns.NotPointcut;
import org.aspectj.weaver.patterns.Pointcut;
import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;
import org.aspectj.weaver.patterns.ThisOrTargetPointcut;
+import org.aspectj.weaver.reflect.ReflectionFastMatchInfo;
import org.aspectj.weaver.reflect.ReflectionShadow;
import org.aspectj.weaver.reflect.ShadowMatchImpl;
import org.aspectj.weaver.tools.DefaultMatchingContext;
@@ -69,7 +70,9 @@ public class PointcutExpressionImpl implements PointcutExpression {
}
public boolean couldMatchJoinPointsInType(Class aClass) {
- return pointcut.fastMatch(new FastMatchInfo(world.resolve(aClass.getName()),null)).maybeTrue();
+ ResolvedType matchType = world.resolve(aClass.getName());
+ ReflectionFastMatchInfo info = new ReflectionFastMatchInfo(matchType,null,this.matchContext);
+ return pointcut.fastMatch(info).maybeTrue();
}
public boolean mayNeedDynamicTest() {
diff --git a/weaver/src/org/aspectj/weaver/reflect/ReflectionFastMatchInfo.java b/weaver/src/org/aspectj/weaver/reflect/ReflectionFastMatchInfo.java
new file mode 100644
index 000000000..892fdabc5
--- /dev/null
+++ b/weaver/src/org/aspectj/weaver/reflect/ReflectionFastMatchInfo.java
@@ -0,0 +1,42 @@
+/* *******************************************************************
+ * Copyright (c) 2006 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Adrian Colyer Initial implementation
+ * ******************************************************************/
+package org.aspectj.weaver.reflect;
+
+import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.Shadow;
+import org.aspectj.weaver.patterns.FastMatchInfo;
+import org.aspectj.weaver.tools.MatchingContext;
+
+/**
+ * An implementation of FastMatchInfo that can also expose a
+ * MatchingContext.
+ *
+ * @author Adrian Colyer
+ * @since 1.5.1
+ */
+public class ReflectionFastMatchInfo extends FastMatchInfo {
+
+ private final MatchingContext context;
+
+ public ReflectionFastMatchInfo(ResolvedType type, Shadow.Kind kind, MatchingContext context) {
+ super(type,kind);
+ this.context = context;
+ }
+
+ /**
+ * @return Returns the matching context.
+ */
+ public MatchingContext getMatchingContext() {
+ return this.context;
+ }
+
+}
diff --git a/weaver/src/org/aspectj/weaver/tools/ContextBasedMatcher.java b/weaver/src/org/aspectj/weaver/tools/ContextBasedMatcher.java
index 92a636866..fc247dc90 100644
--- a/weaver/src/org/aspectj/weaver/tools/ContextBasedMatcher.java
+++ b/weaver/src/org/aspectj/weaver/tools/ContextBasedMatcher.java
@@ -23,14 +23,23 @@ package org.aspectj.weaver.tools;
*
*/
public interface ContextBasedMatcher {
-
+
/**
* return true iff this matcher could ever match
* a join point in the given type
+ * @deprecated use couldMatchJoinPointsInType(Class,MatchingContext) instead
*/
boolean couldMatchJoinPointsInType(Class aClass);
/**
+ * return true iff this matcher could ever match
+ * a join point in the given type, may also use any
+ * match context information available
+ * @since 1.5.1
+ */
+ boolean couldMatchJoinPointsInType(Class aClass, MatchingContext matchContext);
+
+ /**
* return true if matchesStatically can ever return
* FuzzyBoolean.MAYBE (necessitating a per-join point test
* to determine matching at a given join point).
diff --git a/weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java b/weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java
index bb678ff58..23acf58a5 100644
--- a/weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java
+++ b/weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java
@@ -60,6 +60,15 @@ public class PointcutDesignatorHandlerTests extends TestCase {
assertEquals("service.*",beanHandler.getExpressionLastAskedToParse());
}
+ public void testParseWithHandlerAndMultipleSegments() {
+ if (needToSkip) return;
+ PointcutParser parser = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution();
+ BeanDesignatorHandler beanHandler = new BeanDesignatorHandler();
+ parser.registerPointcutDesignatorHandler(beanHandler);
+ parser.parsePointcutExpression("bean(org.xyz.someapp..*)");
+ assertEquals("org.xyz.someapp..*",beanHandler.getExpressionLastAskedToParse());
+ }
+
public void testStaticMatch() throws Exception {
if (needToSkip) return;
PointcutParser parser = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution();
@@ -95,7 +104,19 @@ public class PointcutDesignatorHandlerTests extends TestCase {
assertFalse(sm.matchesJoinPoint(null, null, null).matches());
}
-
+ public void testFastMatch() {
+ if (needToSkip) return;
+ PointcutParser parser = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution();
+ BeanDesignatorHandler beanHandler = new BeanDesignatorHandler();
+ parser.registerPointcutDesignatorHandler(beanHandler);
+ PointcutExpression pc = parser.parsePointcutExpression("bean(myBean)");
+ DefaultMatchingContext context = new DefaultMatchingContext();
+ context.addContextBinding("beanName","myBean");
+ pc.setMatchingContext(context);
+ assertTrue(pc.couldMatchJoinPointsInType(String.class));
+ context.addContextBinding("beanName","yourBean");
+ assertFalse(pc.couldMatchJoinPointsInType(String.class));
+ }
private class BeanDesignatorHandler implements PointcutDesignatorHandler {
@@ -130,11 +151,19 @@ public class PointcutDesignatorHandlerTests extends TestCase {
}
+ public boolean couldMatchJoinPointsInType(Class aClass) {
+ return true;
+ }
+
/* (non-Javadoc)
* @see org.aspectj.weaver.tools.ContextBasedMatcher#couldMatchJoinPointsInType(java.lang.Class)
*/
- public boolean couldMatchJoinPointsInType(Class aClass) {
- return true;
+ public boolean couldMatchJoinPointsInType(Class aClass, MatchingContext context) {
+ if (this.beanNamePattern.equals(context.getBinding("beanName"))) {
+ return true;
+ } else {
+ return false;
+ }
}