Java Code Examples for org.springframework.aop.Pointcut#getMethodMatcher()

The following examples show how to use org.springframework.aop.Pointcut#getMethodMatcher() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AspectJExpressionPointcutTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testMatchWithTypePattern() throws Exception {
	String expression = "execution(* *..TestBean.*Age(..))";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
	assertMatchesGetAge(methodMatcher);
	assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
}
 
Example 2
Source File: AspectJExpressionPointcutTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testMatchWithArgs() throws Exception {
	String expression = "execution(void org.springframework.tests.sample.beans.TestBean.setSomeNumber(Number)) && args(Double)";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertTrue("Should match with setSomeNumber with Double input",
			methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Double(12)}));
	assertFalse("Should not match setSomeNumber with Integer input",
			methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Integer(11)}));
	assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class, null));
	assertTrue("Should be a runtime match", methodMatcher.isRuntime());
}
 
Example 3
Source File: AspectJExpressionPointcutTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testMatchWithTypePattern() throws Exception {
	String expression = "execution(* *..TestBean.*Age(..))";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
	assertMatchesGetAge(methodMatcher);
	assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
}
 
Example 4
Source File: AspectJExpressionPointcutTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testMatchExplicit() {
	String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
	assertMatchesGetAge(methodMatcher);
	assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class));
}
 
Example 5
Source File: Pointcuts.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Perform the least expensive check for a pointcut match.
 * @param pointcut the pointcut to match
 * @param method the candidate method
 * @param targetClass the target class
 * @param args arguments to the method
 * @return whether there's a runtime match
 */
public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object[] args) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	if (pointcut == Pointcut.TRUE) {
		return true;
	}
	if (pointcut.getClassFilter().matches(targetClass)) {
		// Only check if it gets past first hurdle.
		MethodMatcher mm = pointcut.getMethodMatcher();
		if (mm.matches(method, targetClass)) {
			// We may need additional runtime (argument) check.
			return (!mm.isRuntime() || mm.matches(method, targetClass, args));
		}
	}
	return false;
}
 
Example 6
Source File: Pointcuts.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Perform the least expensive check for a pointcut match.
 * @param pointcut the pointcut to match
 * @param method the candidate method
 * @param targetClass the target class
 * @param args arguments to the method
 * @return whether there's a runtime match
 */
public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object... args) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	if (pointcut == Pointcut.TRUE) {
		return true;
	}
	if (pointcut.getClassFilter().matches(targetClass)) {
		// Only check if it gets past first hurdle.
		MethodMatcher mm = pointcut.getMethodMatcher();
		if (mm.matches(method, targetClass)) {
			// We may need additional runtime (argument) check.
			return (!mm.isRuntime() || mm.matches(method, targetClass, args));
		}
	}
	return false;
}
 
Example 7
Source File: AspectJExpressionPointcutTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testMatchWithArgs() throws Exception {
	String expression = "execution(void org.springframework.tests.sample.beans.TestBean.setSomeNumber(Number)) && args(Double)";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertTrue("Should match with setSomeNumber with Double input",
			methodMatcher.matches(setSomeNumber, TestBean.class, new Double(12)));
	assertFalse("Should not match setSomeNumber with Integer input",
			methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11)));
	assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class));
	assertTrue("Should be a runtime match", methodMatcher.isRuntime());
}
 
Example 8
Source File: AspectJExpressionPointcutTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testMatchExplicit() {
	String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
	assertMatchesGetAge(methodMatcher);
	assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class));
}
 
Example 9
Source File: Pointcuts.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Perform the least expensive check for a pointcut match.
 * @param pointcut the pointcut to match
 * @param method the candidate method
 * @param targetClass the target class
 * @param args arguments to the method
 * @return whether there's a runtime match
 */
public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object... args) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	if (pointcut == Pointcut.TRUE) {
		return true;
	}
	if (pointcut.getClassFilter().matches(targetClass)) {
		// Only check if it gets past first hurdle.
		MethodMatcher mm = pointcut.getMethodMatcher();
		if (mm.matches(method, targetClass)) {
			// We may need additional runtime (argument) check.
			return (!mm.isRuntime() || mm.matches(method, targetClass, args));
		}
	}
	return false;
}
 
Example 10
Source File: AspectJExpressionPointcutTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testMatchWithArgs() throws Exception {
	String expression = "execution(void org.springframework.tests.sample.beans.TestBean.setSomeNumber(Number)) && args(Double)";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertTrue("Should match with setSomeNumber with Double input",
			methodMatcher.matches(setSomeNumber, TestBean.class, new Double(12)));
	assertFalse("Should not match setSomeNumber with Integer input",
			methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11)));
	assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class));
	assertTrue("Should be a runtime match", methodMatcher.isRuntime());
}
 
Example 11
Source File: AspectJExpressionPointcutTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testMatchWithTypePattern() throws Exception {
	String expression = "execution(* *..TestBean.*Age(..))";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
	assertMatchesGetAge(methodMatcher);
	assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
}
 
Example 12
Source File: AspectJExpressionPointcutTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testMatchExplicit() {
	String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
	assertMatchesGetAge(methodMatcher);
	assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class));
}
 
Example 13
Source File: Pointcuts.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Perform the least expensive check for a pointcut match.
 * @param pointcut the pointcut to match
 * @param method the candidate method
 * @param targetClass the target class
 * @param args arguments to the method
 * @return whether there's a runtime match
 */
public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object... args) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	if (pointcut == Pointcut.TRUE) {
		return true;
	}
	if (pointcut.getClassFilter().matches(targetClass)) {
		// Only check if it gets past first hurdle.
		MethodMatcher mm = pointcut.getMethodMatcher();
		if (mm.matches(method, targetClass)) {
			// We may need additional runtime (argument) check.
			return (!mm.isRuntime() || mm.matches(method, targetClass, args));
		}
	}
	return false;
}
 
Example 14
Source File: ComposablePointcut.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Create a ComposablePointcut based on the given Pointcut.
 * @param pointcut the original Pointcut
 */
public ComposablePointcut(Pointcut pointcut) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	this.classFilter = pointcut.getClassFilter();
	this.methodMatcher = pointcut.getMethodMatcher();
}
 
Example 15
Source File: ComposablePointcut.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a ComposablePointcut based on the given Pointcut.
 * @param pointcut the original Pointcut
 */
public ComposablePointcut(Pointcut pointcut) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	this.classFilter = pointcut.getClassFilter();
	this.methodMatcher = pointcut.getMethodMatcher();
}
 
Example 16
Source File: ComposablePointcut.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Create a ComposablePointcut based on the given Pointcut.
 * @param pointcut the original Pointcut
 */
public ComposablePointcut(Pointcut pointcut) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	this.classFilter = pointcut.getClassFilter();
	this.methodMatcher = pointcut.getMethodMatcher();
}
 
Example 17
Source File: ComposablePointcut.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Create a ComposablePointcut based on the given Pointcut.
 * @param pointcut the original Pointcut
 */
public ComposablePointcut(Pointcut pointcut) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	this.classFilter = pointcut.getClassFilter();
	this.methodMatcher = pointcut.getMethodMatcher();
}