org.aspectj.weaver.tools.PointcutExpression Java Examples

The following examples show how to use org.aspectj.weaver.tools.PointcutExpression. 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 spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #2
Source File: AspectJExpressionPointcut.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get a new pointcut expression based on a target class's loader rather than the default.
 */
private PointcutExpression getFallbackPointcutExpression(Class<?> targetClass) {
	try {
		ClassLoader classLoader = targetClass.getClassLoader();
		if (classLoader != null && classLoader != this.pointcutClassLoader) {
			return buildPointcutExpression(classLoader);
		}
	}
	catch (Throwable ex) {
		logger.debug("Failed to create fallback PointcutExpression", ex);
	}
	return null;
}
 
Example #3
Source File: AspectJExpressionPointcut.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build the underlying AspectJ pointcut expression.
 */
private PointcutExpression buildPointcutExpression(ClassLoader classLoader) {
	PointcutParser parser = initializePointcutParser(classLoader);
	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]);
	}
	return parser.parsePointcutExpression(replaceBooleanOperators(getExpression()),
			this.pointcutDeclarationScope, pointcutParameters);
}
 
Example #4
Source File: AspectJExpressionPointcut.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Build the underlying AspectJ pointcut expression.
 */
private PointcutExpression buildPointcutExpression(ClassLoader classLoader) {
	PointcutParser parser = initializePointcutParser(classLoader);
	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]);
	}
	return parser.parsePointcutExpression(replaceBooleanOperators(getExpression()),
			this.pointcutDeclarationScope, pointcutParameters);
}
 
Example #5
Source File: ExpressionMatcher.java    From defender with Apache License 2.0 5 votes vote down vote up
@Override
public boolean match(Caller caller, String pattern) {
	if(! pattern.startsWith("execution")) {
		pattern = "execution(" + pattern + ")";
	}
	
	PointcutExpression pe = cache.get(pattern);
	if(pe == null) {
		PointcutParser pp = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution();
		pe = pp.parsePointcutExpression(pattern);
		cache.set(pattern, pe);
	}
	ShadowMatch sm = pe.matchesMethodExecution(caller.getTargetMethod());
	return sm.alwaysMatches();
}
 
Example #6
Source File: AspectJExpressionPointcut.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Get a new pointcut expression based on a target class's loader rather than the default.
 */
private PointcutExpression getFallbackPointcutExpression(Class<?> targetClass) {
	try {
		ClassLoader classLoader = targetClass.getClassLoader();
		if (classLoader != null && classLoader != this.pointcutClassLoader) {
			return buildPointcutExpression(classLoader);
		}
	}
	catch (Throwable ex) {
		logger.debug("Failed to create fallback PointcutExpression", ex);
	}
	return null;
}
 
Example #7
Source File: AspectJExpressionPointcutTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testAndSubstitution() {
	Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
	PointcutExpression expr =
		((AspectJExpressionPointcut) pc).getPointcutExpression();
	assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression());
}
 
Example #8
Source File: AspectJExpressionPointcut.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Get a new pointcut expression based on a target class's loader rather than the default.
 */
@Nullable
private PointcutExpression getFallbackPointcutExpression(Class<?> targetClass) {
	try {
		ClassLoader classLoader = targetClass.getClassLoader();
		if (classLoader != null && classLoader != this.pointcutClassLoader) {
			return buildPointcutExpression(classLoader);
		}
	}
	catch (Throwable ex) {
		logger.debug("Failed to create fallback PointcutExpression", ex);
	}
	return null;
}
 
Example #9
Source File: AspectJExpressionPointcut.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Build the underlying AspectJ pointcut expression.
 */
private PointcutExpression buildPointcutExpression(@Nullable ClassLoader classLoader) {
	PointcutParser parser = initializePointcutParser(classLoader);
	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]);
	}
	return parser.parsePointcutExpression(replaceBooleanOperators(resolveExpression()),
			this.pointcutDeclarationScope, pointcutParameters);
}
 
Example #10
Source File: AspectJExpressionPointcut.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Check whether this pointcut is ready to match,
 * lazily building the underlying AspectJ pointcut expression.
 */
private PointcutExpression obtainPointcutExpression() {
	if (getExpression() == null) {
		throw new IllegalStateException("Must set property 'expression' before attempting to match");
	}
	if (this.pointcutExpression == null) {
		this.pointcutClassLoader = determinePointcutClassLoader();
		this.pointcutExpression = buildPointcutExpression(this.pointcutClassLoader);
	}
	return this.pointcutExpression;
}
 
Example #11
Source File: AspectJExpressionPointcut.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Get a new pointcut expression based on a target class's loader rather than the default.
 */
@Nullable
private PointcutExpression getFallbackPointcutExpression(Class<?> targetClass) {
	try {
		ClassLoader classLoader = targetClass.getClassLoader();
		if (classLoader != null && classLoader != this.pointcutClassLoader) {
			return buildPointcutExpression(classLoader);
		}
	}
	catch (Throwable ex) {
		logger.debug("Failed to create fallback PointcutExpression", ex);
	}
	return null;
}
 
Example #12
Source File: AspectJExpressionPointcut.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Check whether this pointcut is ready to match,
 * lazily building the underlying AspectJ pointcut expression.
 */
private PointcutExpression obtainPointcutExpression() {
	if (getExpression() == null) {
		throw new IllegalStateException("Must set property 'expression' before attempting to match");
	}
	if (this.pointcutExpression == null) {
		this.pointcutClassLoader = determinePointcutClassLoader();
		this.pointcutExpression = buildPointcutExpression(this.pointcutClassLoader);
	}
	return this.pointcutExpression;
}
 
Example #13
Source File: AspectJExpressionPointcut.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Build the underlying AspectJ pointcut expression.
 */
private PointcutExpression buildPointcutExpression(@Nullable ClassLoader classLoader) {
	PointcutParser parser = initializePointcutParser(classLoader);
	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]);
	}
	return parser.parsePointcutExpression(replaceBooleanOperators(resolveExpression()),
			this.pointcutDeclarationScope, pointcutParameters);
}
 
Example #14
Source File: AspectJExpressionPointcut.java    From tiny-spring with Apache License 2.0 4 votes vote down vote up
private PointcutExpression buildPointcutExpression() {
	return pointcutParser.parsePointcutExpression(expression);
}
 
Example #15
Source File: AspectJExpressionPointcut.java    From tiny-spring with Apache License 2.0 4 votes vote down vote up
private PointcutExpression buildPointcutExpression() {
	return pointcutParser.parsePointcutExpression(expression);
}
 
Example #16
Source File: AspectJExpressionPointcut.java    From tiny-spring with Apache License 2.0 4 votes vote down vote up
private PointcutExpression buildPointcutExpression() {
	return pointcutParser.parsePointcutExpression(expression);
}
 
Example #17
Source File: AspectJExpressionPointcut.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Return the underlying AspectJ pointcut expression.
 */
public PointcutExpression getPointcutExpression() {
	checkReadyToMatch();
	return this.pointcutExpression;
}
 
Example #18
Source File: AspectJExpressionPointcut.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the underlying AspectJ pointcut expression.
 */
public PointcutExpression getPointcutExpression() {
	checkReadyToMatch();
	return this.pointcutExpression;
}
 
Example #19
Source File: ExpressionCache.java    From defender with Apache License 2.0 4 votes vote down vote up
@Override
public PointcutExpression get(String key) {
	return cacheMap.get(key);
}
 
Example #20
Source File: ExpressionCache.java    From defender with Apache License 2.0 4 votes vote down vote up
@Override
public void set(String key, PointcutExpression value) {
	cacheMap.putIfAbsent(key, value);
}
 
Example #21
Source File: AspectJExpressionPointcutTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@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());
}
 
Example #22
Source File: AspectJExpressionPointcutTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void testAndSubstitution() {
	Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
	PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
	assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression());
}
 
Example #23
Source File: AspectJExpressionPointcut.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the underlying AspectJ pointcut expression.
 */
public PointcutExpression getPointcutExpression() {
	return obtainPointcutExpression();
}
 
Example #24
Source File: AspectJExpressionPointcutTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@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());
}
 
Example #25
Source File: AspectJExpressionPointcutTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void testAndSubstitution() {
	Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
	PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
	assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression());
}
 
Example #26
Source File: AspectJExpressionPointcut.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the underlying AspectJ pointcut expression.
 */
public PointcutExpression getPointcutExpression() {
	return obtainPointcutExpression();
}