@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2012 the original author or authors .
* Copyright 2002 - 2013 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -42,6 +42,7 @@ import org.aspectj.weaver.tools.PointcutParameter;
@@ -42,6 +42,7 @@ import org.aspectj.weaver.tools.PointcutParameter;
import org.aspectj.weaver.tools.PointcutParser ;
import org.aspectj.weaver.tools.PointcutPrimitive ;
import org.aspectj.weaver.tools.ShadowMatch ;
import org.springframework.aop.ClassFilter ;
import org.springframework.aop.IntroductionAwareMethodMatcher ;
import org.springframework.aop.MethodMatcher ;
@ -55,6 +56,7 @@ import org.springframework.beans.factory.BeanFactoryAware;
@@ -55,6 +56,7 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanFactoryUtils ;
import org.springframework.beans.factory.FactoryBean ;
import org.springframework.beans.factory.config.ConfigurableBeanFactory ;
import org.springframework.util.ClassUtils ;
import org.springframework.util.ObjectUtils ;
import org.springframework.util.StringUtils ;
@ -98,11 +100,11 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -98,11 +100,11 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
private static final Log logger = LogFactory . getLog ( AspectJExpressionPointcut . class ) ;
private Class pointcutDeclarationScope ;
private Class < ? > pointcutDeclarationScope ;
private String [ ] pointcutParameterNames = new String [ 0 ] ;
private Class [ ] pointcutParameterTypes = new Class [ 0 ] ;
private Class < ? > [ ] pointcutParameterTypes = new Class < ? > [ 0 ] ;
private BeanFactory beanFactory ;
@ -123,7 +125,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -123,7 +125,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
* @param paramNames the parameter names for the pointcut
* @param paramTypes the parameter types for the pointcut
* /
public AspectJExpressionPointcut ( Class declarationScope , String [ ] paramNames , Class [ ] paramTypes ) {
public AspectJExpressionPointcut ( Class < ? > declarationScope , String [ ] paramNames , Class < ? > [ ] paramTypes ) {
this . pointcutDeclarationScope = declarationScope ;
if ( paramNames . length ! = paramTypes . length ) {
throw new IllegalStateException (
@ -137,21 +139,21 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -137,21 +139,21 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
/ * *
* Set the declaration scope for the pointcut .
* /
public void setPointcutDeclarationScope ( Class pointcutDeclarationScope ) {
public void setPointcutDeclarationScope ( Class < ? > pointcutDeclarationScope ) {
this . pointcutDeclarationScope = pointcutDeclarationScope ;
}
/ * *
* Set the parameter names for the pointcut .
* /
public void setParameterNames ( String [ ] names ) {
public void setParameterNames ( String . . . names ) {
this . pointcutParameterNames = names ;
}
/ * *
* Set the parameter types for the pointcut .
* /
public void setParameterTypes ( Class [ ] types ) {
public void setParameterTypes ( Class < ? > . . . types ) {
this . pointcutParameterTypes = types ;
}
@ -188,9 +190,9 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -188,9 +190,9 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
* Build the underlying AspectJ pointcut expression .
* /
private PointcutExpression buildPointcutExpression ( ) {
ClassLoader cl = ( this . beanFactory instanceof ConfigurableBeanFactory ? ( ( ConfigurableBeanFactory ) this . beanFactory )
. getBeanClassLoader ( ) : Thread . currentThread ( )
. getContex tClassLoader( ) ) ;
ClassLoader cl = ( this . beanFactory instanceof ConfigurableBeanFactory ?
( ( ConfigurableBeanFactory ) this . beanFactory ) . getBeanClassLoader ( ) :
ClassUtils . getDefaul tClassLoader( ) ) ;
return buildPointcutExpression ( cl ) ;
}
@ -202,8 +204,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -202,8 +204,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
PointcutParameter [ ] pointcutParameters = new PointcutParameter [ this . pointcutParameterNames . length ] ;
for ( int i = 0 ; i < pointcutParameters . length ; i + + ) {
pointcutParameters [ i ] = parser . createPointcutParameter (
this . pointcutParameterNames [ i ] ,
this . pointcutParameterTypes [ i ] ) ;
this . pointcutParameterNames [ i ] , this . pointcutParameterTypes [ i ] ) ;
}
return parser . parsePointcutExpression (
replaceBooleanOperators ( getExpression ( ) ) ,
@ -244,20 +245,19 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -244,20 +245,19 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
return this . pointcutExpression ;
}
public boolean matches ( Class targetClass ) {
public boolean matches ( Class < ? > targetClass ) {
checkReadyToMatch ( ) ;
try {
return this . pointcutExpression . couldMatchJoinPointsInType ( targetClass ) ;
} catch ( ReflectionWorldException e ) {
logger . debug ( "PointcutExpression matching rejected target class" , e ) ;
}
catch ( ReflectionWorldException rwe ) {
logger . debug ( "PointcutExpression matching rejected target class" , rwe ) ;
try {
// Actually this is still a "maybe" - treat the pointcut as dynamic if we
// don't know enough yet
// Actually this is still a "maybe" - treat the pointcut as dynamic if we don't know enough yet
return getFallbackPointcutExpression ( targetClass ) . couldMatchJoinPointsInType ( targetClass ) ;
} catch ( BCException ex ) {
logger . debug (
"Fallback PointcutExpression matching rejected target class" ,
ex ) ;
}
catch ( BCException bce ) {
logger . debug ( "Fallback PointcutExpression matching rejected target class" , bce ) ;
return false ;
}
}
@ -267,7 +267,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -267,7 +267,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
}
public boolean matches ( Method method , Class targetClass , boolean beanHasIntroductions ) {
public boolean matches ( Method method , Class < ? > targetClass , boolean beanHasIntroductions ) {
checkReadyToMatch ( ) ;
Method targetMethod = AopUtils . getMostSpecificMethod ( method , targetClass ) ;
ShadowMatch shadowMatch = getShadowMatch ( targetMethod , method ) ;
@ -283,11 +283,19 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -283,11 +283,19 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
else {
// the maybe case
return ( beanHasIntroductions | | matchesIgnoringSubtypes ( shadowMatch ) | | matchesTarget ( shadowMatch , targetClass ) ) ;
if ( beanHasIntroductions ) {
return true ;
}
// A match test returned maybe - if there are any subtype sensitive variables
// involved in the test (this, target, at_this, at_target, at_annotation) then
// we say this is not a match as in Spring there will never be a different
// runtime subtype.
RuntimeTestWalker walker = getRuntimeTestWalker ( shadowMatch ) ;
return ( ! walker . testsSubtypeSensitiveVars ( ) | | walker . testTargetInstanceOfResidue ( targetClass ) ) ;
}
}
public boolean matches ( Method method , Class targetClass ) {
public boolean matches ( Method method , Class < ? > targetClass ) {
return matches ( method , targetClass , false ) ;
}
@ -296,7 +304,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -296,7 +304,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
return this . pointcutExpression . mayNeedDynamicTest ( ) ;
}
public boolean matches ( Method method , Class targetClass , Object [ ] args ) {
public boolean matches ( Method method , Class < ? > targetClass , Object [ ] args ) {
checkReadyToMatch ( ) ;
ShadowMatch shadowMatch = getShadowMatch ( AopUtils . getMostSpecificMethod ( method , targetClass ) , method ) ;
ShadowMatch originalShadowMatch = getShadowMatch ( method , method ) ;
@ -336,14 +344,13 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -336,14 +344,13 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
if ( ! originalMethodResidueTest . testThisInstanceOfResidue ( thisObject . getClass ( ) ) ) {
return false ;
}
}
if ( joinPointMatch . matches ( ) & & pmi ! = null ) {
bindParameters ( pmi , joinPointMatch ) ;
if ( joinPointMatch . matches ( ) ) {
bindParameters ( pmi , joinPointMatch ) ;
}
}
return joinPointMatch . matches ( ) ;
}
protected String getCurrentProxiedBeanName ( ) {
return ProxyCreationContext . getCurrentProxiedBeanName ( ) ;
}
@ -353,29 +360,14 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -353,29 +360,14 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
* Get a new pointcut expression based on a target class ' s loader , rather
* than the default .
* /
private PointcutExpression getFallbackPointcutExpression (
Class < ? > targetClass ) {
private PointcutExpression getFallbackPointcutExpression ( Class < ? > targetClass ) {
ClassLoader classLoader = targetClass . getClassLoader ( ) ;
return classLoader = = null ? this . pointcutExpression : buildPointcutExpression ( classLoader ) ;
}
/ * *
* A match test returned maybe - if there are any subtype sensitive variables
* involved in the test ( this , target , at_this , at_target , at_annotation ) then
* we say this is not a match as in Spring there will never be a different
* runtime subtype .
* /
private boolean matchesIgnoringSubtypes ( ShadowMatch shadowMatch ) {
return ! ( getRuntimeTestWalker ( shadowMatch ) . testsSubtypeSensitiveVars ( ) ) ;
}
private boolean matchesTarget ( ShadowMatch shadowMatch , Class targetClass ) {
return getRuntimeTestWalker ( shadowMatch ) . testTargetInstanceOfResidue ( targetClass ) ;
return ( classLoader ! = null ? buildPointcutExpression ( classLoader ) : this . pointcutExpression ) ;
}
private RuntimeTestWalker getRuntimeTestWalker ( ShadowMatch shadowMatch ) {
if ( shadowMatch instanceof DefensiveShadowMatch ) {
return new RuntimeTestWalker ( ( ( DefensiveShadowMatch ) shadowMatch ) . primary ) ;
return new RuntimeTestWalker ( ( ( DefensiveShadowMatch ) shadowMatch ) . primary ) ;
}
return new RuntimeTestWalker ( shadowMatch ) ;
}
@ -409,7 +401,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -409,7 +401,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
try {
fallbackPointcutExpression = getFallbackPointcutExpression ( methodToMatch . getDeclaringClass ( ) ) ;
shadowMatch = fallbackPointcutExpression . matchesMethodExecution ( methodToMatch ) ;
} catch ( ReflectionWorld . ReflectionWorldException e ) {
}
catch ( ReflectionWorld . ReflectionWorldException ex2 ) {
if ( targetMethod = = originalMethod ) {
shadowMatch = new ShadowMatchImpl ( org . aspectj . util . FuzzyBoolean . NO , null , null , null ) ;
}
@ -417,21 +410,22 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -417,21 +410,22 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
try {
shadowMatch = this . pointcutExpression . matchesMethodExecution ( originalMethod ) ;
}
catch ( ReflectionWorld . ReflectionWorldException ex2 ) {
catch ( ReflectionWorld . ReflectionWorldException ex3 ) {
// Could neither introspect the target class nor the proxy class ->
// let's simply consider this method as non-matching.
methodToMatch = originalMethod ;
fallbackPointcutExpression = getFallbackPointcutExpression ( methodToMatch . getDeclaringClass ( ) ) ;
try {
shadowMatch = fallbackPointcutExpression . matchesMethodExecution ( methodToMatch ) ;
} catch ( ReflectionWorld . ReflectionWorldException e2 ) {
}
catch ( ReflectionWorld . ReflectionWorldException ex4 ) {
shadowMatch = new ShadowMatchImpl ( org . aspectj . util . FuzzyBoolean . NO , null , null , null ) ;
}
}
}
}
}
if ( shadowMatch . maybeMatches ( ) & & fallbackPointcutExpression ! = null ) {
if ( shadowMatch . maybeMatches ( ) & & fallbackPointcutExpression ! = null ) {
shadowMatch = new DefensiveShadowMatch ( shadowMatch ,
fallbackPointcutExpression . matchesMethodExecution ( methodToMatch ) ) ;
}
@ -601,9 +595,11 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -601,9 +595,11 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
this . shadowMatchCache = new ConcurrentHashMap < Method , ShadowMatch > ( 32 ) ;
}
private static class DefensiveShadowMatch implements ShadowMatch {
private final ShadowMatch primary ;
private final ShadowMatch other ;
public DefensiveShadowMatch ( ShadowMatch primary , ShadowMatch other ) {
@ -612,31 +608,30 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -612,31 +608,30 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
public boolean alwaysMatches ( ) {
return primary . alwaysMatches ( ) ;
return this . primary . alwaysMatches ( ) ;
}
public boolean maybeMatches ( ) {
return primary . maybeMatches ( ) ;
return this . primary . maybeMatches ( ) ;
}
public boolean neverMatches ( ) {
return primary . neverMatches ( ) ;
return this . primary . neverMatches ( ) ;
}
public JoinPointMatch matchesJoinPoint ( Object thisObject ,
Object targetObject , Object [ ] args ) {
public JoinPointMatch matchesJoinPoint ( Object thisObject , Object targetObject , Object [ ] args ) {
try {
return primary . matchesJoinPoint ( thisObject , targetObject , args ) ;
} catch ( ReflectionWorldException e ) {
return other . matchesJoinPoint ( thisObject , targetObject , args ) ;
return this . primary . matchesJoinPoint ( thisObject , targetObject , args ) ;
}
catch ( ReflectionWorldException ex ) {
return this . other . matchesJoinPoint ( thisObject , targetObject , args ) ;
}
}
public void setMatchingContext ( MatchingContext aMatchContext ) {
primary . setMatchingContext ( aMatchContext ) ;
other . setMatchingContext ( aMatchContext ) ;
this . primary . setMatchingContext ( aMatchContext ) ;
this . other . setMatchingContext ( aMatchContext ) ;
}
}
}