Java Code Examples for org.springframework.expression.spel.ast.SpelNodeImpl#isCompilable()

The following examples show how to use org.springframework.expression.spel.ast.SpelNodeImpl#isCompilable() . 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: SpelCompiler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Attempt compilation of the supplied expression. A check is made to see
 * if it is compilable before compilation proceeds. The check involves
 * visiting all the nodes in the expression Ast and ensuring enough state
 * is known about them that bytecode can be generated for them.
 * @param expression the expression to compile
 * @return an instance of the class implementing the compiled expression,
 * or {@code null} if compilation is not possible
 */
@Nullable
public CompiledExpression compile(SpelNodeImpl expression) {
	if (expression.isCompilable()) {
		if (logger.isDebugEnabled()) {
			logger.debug("SpEL: compiling " + expression.toStringAST());
		}
		Class<? extends CompiledExpression> clazz = createExpressionClass(expression);
		if (clazz != null) {
			try {
				return ReflectionUtils.accessibleConstructor(clazz).newInstance();
			}
			catch (Throwable ex) {
				throw new IllegalStateException("Failed to instantiate CompiledExpression", ex);
			}
		}
	}

	if (logger.isDebugEnabled()) {
		logger.debug("SpEL: unable to compile " + expression.toStringAST());
	}
	return null;
}
 
Example 2
Source File: SpelCompiler.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Attempt compilation of the supplied expression. A check is made to see
 * if it is compilable before compilation proceeds. The check involves
 * visiting all the nodes in the expression Ast and ensuring enough state
 * is known about them that bytecode can be generated for them.
 * @param expression the expression to compile
 * @return an instance of the class implementing the compiled expression,
 * or {@code null} if compilation is not possible
 */
@Nullable
public CompiledExpression compile(SpelNodeImpl expression) {
	if (expression.isCompilable()) {
		if (logger.isDebugEnabled()) {
			logger.debug("SpEL: compiling " + expression.toStringAST());
		}
		Class<? extends CompiledExpression> clazz = createExpressionClass(expression);
		if (clazz != null) {
			try {
				return ReflectionUtils.accessibleConstructor(clazz).newInstance();
			}
			catch (Throwable ex) {
				throw new IllegalStateException("Failed to instantiate CompiledExpression", ex);
			}
		}
	}

	if (logger.isDebugEnabled()) {
		logger.debug("SpEL: unable to compile " + expression.toStringAST());
	}
	return null;
}
 
Example 3
Source File: SpelCompiler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Attempt compilation of the supplied expression. A check is made to see
 * if it is compilable before compilation proceeds. The check involves
 * visiting all the nodes in the expression Ast and ensuring enough state
 * is known about them that bytecode can be generated for them.
 * @param expression the expression to compile
 * @return an instance of the class implementing the compiled expression,
 * or {@code null} if compilation is not possible
 */
public CompiledExpression compile(SpelNodeImpl expression) {
	if (expression.isCompilable()) {
		if (logger.isDebugEnabled()) {
			logger.debug("SpEL: compiling " + expression.toStringAST());
		}
		Class<? extends CompiledExpression> clazz = createExpressionClass(expression);
		if (clazz != null) {
			try {
				return clazz.newInstance();
			}
			catch (Throwable ex) {
				throw new IllegalStateException("Failed to instantiate CompiledExpression", ex);
			}
		}
	}

	if (logger.isDebugEnabled()) {
		logger.debug("SpEL: unable to compile " + expression.toStringAST());
	}
	return null;
}
 
Example 4
Source File: SpelCompiler.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt compilation of the supplied expression. A check is
 * made to see if it is compilable before compilation proceeds. The
 * check involves visiting all the nodes in the expression Ast and
 * ensuring enough state is known about them that bytecode can
 * be generated for them.
 * @param expression the expression to compile
 * @return an instance of the class implementing the compiled expression, or null
 * if compilation is not possible
 */
public CompiledExpression compile(SpelNodeImpl expression) {
	if (expression.isCompilable()) {
		if (logger.isDebugEnabled()) {
			logger.debug("SpEL: compiling " + expression.toStringAST());
		}
		Class<? extends CompiledExpression> clazz = createExpressionClass(expression);
		if (clazz != null) {
			try {
				return clazz.newInstance();
			}
			catch (Throwable ex) {
				throw new IllegalStateException("Failed to instantiate CompiledExpression", ex);
			}
		}
	}

	if (logger.isDebugEnabled()) {
		logger.debug("SpEL: unable to compile " + expression.toStringAST());
	}
	return null;
}