Ensures that MatchingContext can be used in fast matching too.tags/POST_MEMORY_CHANGES
@@ -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) |
@@ -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() { |
@@ -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; | |||
} | |||
} |
@@ -23,13 +23,22 @@ 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 |
@@ -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; | |||
} | |||
} | |||