|
|
|
@ -18,6 +18,7 @@ package org.springframework.aop.aspectj; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.ObjectInputStream; |
|
|
|
import java.io.ObjectInputStream; |
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Proxy; |
|
|
|
import java.lang.reflect.Proxy; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
@ -86,6 +87,8 @@ import org.springframework.util.StringUtils; |
|
|
|
public class AspectJExpressionPointcut extends AbstractExpressionPointcut |
|
|
|
public class AspectJExpressionPointcut extends AbstractExpressionPointcut |
|
|
|
implements ClassFilter, IntroductionAwareMethodMatcher, BeanFactoryAware { |
|
|
|
implements ClassFilter, IntroductionAwareMethodMatcher, BeanFactoryAware { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String AJC_MAGIC = "ajc$"; |
|
|
|
|
|
|
|
|
|
|
|
private static final Set<PointcutPrimitive> SUPPORTED_PRIMITIVES = Set.of( |
|
|
|
private static final Set<PointcutPrimitive> SUPPORTED_PRIMITIVES = Set.of( |
|
|
|
PointcutPrimitive.EXECUTION, |
|
|
|
PointcutPrimitive.EXECUTION, |
|
|
|
PointcutPrimitive.ARGS, |
|
|
|
PointcutPrimitive.ARGS, |
|
|
|
@ -103,6 +106,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private Class<?> pointcutDeclarationScope; |
|
|
|
private Class<?> pointcutDeclarationScope; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean aspectCompiledByAjc; |
|
|
|
|
|
|
|
|
|
|
|
private String[] pointcutParameterNames = new String[0]; |
|
|
|
private String[] pointcutParameterNames = new String[0]; |
|
|
|
|
|
|
|
|
|
|
|
private Class<?>[] pointcutParameterTypes = new Class<?>[0]; |
|
|
|
private Class<?>[] pointcutParameterTypes = new Class<?>[0]; |
|
|
|
@ -134,7 +139,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut |
|
|
|
* @param paramTypes the parameter types 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; |
|
|
|
setPointcutDeclarationScope(declarationScope); |
|
|
|
if (paramNames.length != paramTypes.length) { |
|
|
|
if (paramNames.length != paramTypes.length) { |
|
|
|
throw new IllegalStateException( |
|
|
|
throw new IllegalStateException( |
|
|
|
"Number of pointcut parameter names must match number of pointcut parameter types"); |
|
|
|
"Number of pointcut parameter names must match number of pointcut parameter types"); |
|
|
|
@ -149,6 +154,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setPointcutDeclarationScope(Class<?> pointcutDeclarationScope) { |
|
|
|
public void setPointcutDeclarationScope(Class<?> pointcutDeclarationScope) { |
|
|
|
this.pointcutDeclarationScope = pointcutDeclarationScope; |
|
|
|
this.pointcutDeclarationScope = pointcutDeclarationScope; |
|
|
|
|
|
|
|
this.aspectCompiledByAjc = compiledByAjc(pointcutDeclarationScope); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -274,6 +280,11 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean matches(Class<?> targetClass) { |
|
|
|
public boolean matches(Class<?> targetClass) { |
|
|
|
if (this.pointcutParsingFailed) { |
|
|
|
if (this.pointcutParsingFailed) { |
|
|
|
|
|
|
|
// Pointcut parsing failed before below -> avoid trying again.
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.aspectCompiledByAjc && compiledByAjc(targetClass)) { |
|
|
|
|
|
|
|
// ajc-compiled aspect class for ajc-compiled target class -> already weaved.
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -536,6 +547,15 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut |
|
|
|
return resolveExpression().contains("@annotation"); |
|
|
|
return resolveExpression().contains("@annotation"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean compiledByAjc(Class<?> clazz) { |
|
|
|
|
|
|
|
for (Field field : clazz.getDeclaredFields()) { |
|
|
|
|
|
|
|
if (field.getName().startsWith(AJC_MAGIC)) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean equals(@Nullable Object other) { |
|
|
|
public boolean equals(@Nullable Object other) { |
|
|
|
|