Search in sources :

Example 1 with PointcutExpression

use of org.aspectj.weaver.tools.PointcutExpression in project spring-framework by spring-projects.

the class CallCountingInterceptor method testMultipleAndSubstitutions.

@Test
public void testMultipleAndSubstitutions() {
    Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
    PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
    assertEquals("execution(* *(..)) && args(String) && this(Object)", expr.getPointcutExpression());
}
Also used : Pointcut(org.springframework.aop.Pointcut) PointcutExpression(org.aspectj.weaver.tools.PointcutExpression) Test(org.junit.Test)

Example 2 with PointcutExpression

use of org.aspectj.weaver.tools.PointcutExpression in project spring-framework by spring-projects.

the class CallCountingInterceptor method testAndSubstitution.

@Test
public void testAndSubstitution() {
    Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
    PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
    assertEquals("execution(* *(..)) && args(String)", expr.getPointcutExpression());
}
Also used : Pointcut(org.springframework.aop.Pointcut) PointcutExpression(org.aspectj.weaver.tools.PointcutExpression) Test(org.junit.Test)

Example 3 with PointcutExpression

use of org.aspectj.weaver.tools.PointcutExpression in project spring-framework by spring-projects.

the class AspectJExpressionPointcut method getShadowMatch.

private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
    // Avoid lock contention for known Methods through concurrent access...
    ShadowMatch shadowMatch = this.shadowMatchCache.get(targetMethod);
    if (shadowMatch == null) {
        synchronized (this.shadowMatchCache) {
            // Not found - now check again with full lock...
            PointcutExpression fallbackExpression = null;
            Method methodToMatch = targetMethod;
            shadowMatch = this.shadowMatchCache.get(targetMethod);
            if (shadowMatch == null) {
                try {
                    try {
                        shadowMatch = this.pointcutExpression.matchesMethodExecution(methodToMatch);
                    } catch (ReflectionWorldException ex) {
                        // in a special ClassLoader. Let's try the declaring ClassLoader instead...
                        try {
                            fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass());
                            if (fallbackExpression != null) {
                                shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch);
                            }
                        } catch (ReflectionWorldException ex2) {
                            fallbackExpression = null;
                        }
                    }
                    if (shadowMatch == null && targetMethod != originalMethod) {
                        methodToMatch = originalMethod;
                        try {
                            shadowMatch = this.pointcutExpression.matchesMethodExecution(methodToMatch);
                        } catch (ReflectionWorldException ex3) {
                            // let's try the original method's declaring class before we give up...
                            try {
                                fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass());
                                if (fallbackExpression != null) {
                                    shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch);
                                }
                            } catch (ReflectionWorldException ex4) {
                                fallbackExpression = null;
                            }
                        }
                    }
                } catch (Throwable ex) {
                    // Possibly AspectJ 1.8.10 encountering an invalid signature
                    logger.debug("PointcutExpression matching rejected target method", ex);
                    fallbackExpression = null;
                }
                if (shadowMatch == null) {
                    shadowMatch = new ShadowMatchImpl(org.aspectj.util.FuzzyBoolean.NO, null, null, null);
                } else if (shadowMatch.maybeMatches() && fallbackExpression != null) {
                    shadowMatch = new DefensiveShadowMatch(shadowMatch, fallbackExpression.matchesMethodExecution(methodToMatch));
                }
                this.shadowMatchCache.put(targetMethod, shadowMatch);
            }
        }
    }
    return shadowMatch;
}
Also used : PointcutExpression(org.aspectj.weaver.tools.PointcutExpression) ShadowMatch(org.aspectj.weaver.tools.ShadowMatch) Method(java.lang.reflect.Method) ReflectionWorldException(org.aspectj.weaver.reflect.ReflectionWorld.ReflectionWorldException) ShadowMatchImpl(org.aspectj.weaver.reflect.ShadowMatchImpl)

Example 4 with PointcutExpression

use of org.aspectj.weaver.tools.PointcutExpression in project spring-security by spring-projects.

the class ProtectPointcutPostProcessor method postProcessBeforeInitialization.

public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    if (processedBeans.contains(beanName)) {
        // We already have the metadata for this bean
        return bean;
    }
    synchronized (processedBeans) {
        // check again synchronized this time
        if (processedBeans.contains(beanName)) {
            return bean;
        }
        // Obtain methods for the present bean
        Method[] methods;
        try {
            methods = bean.getClass().getMethods();
        } catch (Exception e) {
            throw new IllegalStateException(e.getMessage());
        }
        // expressions
        for (Method method : methods) {
            for (PointcutExpression expression : pointCutExpressions) {
                // Try for the bean class directly
                if (attemptMatch(bean.getClass(), method, expression, beanName)) {
                    // the "while" loop, not the "for" loop
                    break;
                }
            }
        }
        processedBeans.add(beanName);
    }
    return bean;
}
Also used : PointcutExpression(org.aspectj.weaver.tools.PointcutExpression) Method(java.lang.reflect.Method) BeansException(org.springframework.beans.BeansException)

Aggregations

PointcutExpression (org.aspectj.weaver.tools.PointcutExpression)4 Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 Pointcut (org.springframework.aop.Pointcut)2 ReflectionWorldException (org.aspectj.weaver.reflect.ReflectionWorld.ReflectionWorldException)1 ShadowMatchImpl (org.aspectj.weaver.reflect.ShadowMatchImpl)1 ShadowMatch (org.aspectj.weaver.tools.ShadowMatch)1 BeansException (org.springframework.beans.BeansException)1