Example usage for org.springframework.expression.spel.ast SpelNodeImpl isCompilable

List of usage examples for org.springframework.expression.spel.ast SpelNodeImpl isCompilable

Introduction

In this page you can find the example usage for org.springframework.expression.spel.ast SpelNodeImpl isCompilable.

Prototype

public boolean isCompilable() 

Source Link

Document

Check whether a node can be compiled to bytecode.

Usage

From source file:org.springframework.expression.spel.standard.SpelCompiler.java

/**
 * 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
 *//* w ww. j  a  va2 s .  c  o  m*/
@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;
}