Search in sources :

Example 1 with LiteralDeepPropertyNode

use of org.mvel2.ast.LiteralDeepPropertyNode in project mvel by mvel.

the class AbstractParser method createPropertyToken.

/**
 * Generate a property token
 *
 * @param st  the start offset
 * @param end the end offset
 * @return an ast node
 */
private ASTNode createPropertyToken(int st, int end) {
    String tmp;
    if (isPropertyOnly(expr, st, end)) {
        if (pCtx != null && pCtx.hasImports()) {
            int find;
            if ((find = findFirst('.', st, end - st, expr)) != -1) {
                String iStr = new String(expr, st, find - st);
                if (pCtx.hasImport(iStr)) {
                    lastWasIdentifier = true;
                    return lastNode = new LiteralDeepPropertyNode(expr, find + 1, end - find - 1, fields, pCtx.getImport(iStr), pCtx);
                }
            } else {
                if (pCtx.hasImport(tmp = new String(expr, st, cursor - st))) {
                    lastWasIdentifier = true;
                    return lastNode = new LiteralNode(pCtx.getStaticOrClassImport(tmp), pCtx);
                }
            }
        }
        if (LITERALS.containsKey(tmp = new String(expr, st, end - st))) {
            lastWasIdentifier = true;
            return lastNode = new LiteralNode(LITERALS.get(tmp), pCtx);
        } else if (OPERATORS.containsKey(tmp)) {
            lastWasIdentifier = false;
            return lastNode = new OperatorNode(OPERATORS.get(tmp), expr, st, pCtx);
        } else if (lastWasIdentifier) {
            return procTypedNode(true);
        }
    }
    if (pCtx != null && isArrayType(expr, st, end)) {
        if (pCtx.hasImport(new String(expr, st, cursor - st - 2))) {
            lastWasIdentifier = true;
            TypeDescriptor typeDescriptor = new TypeDescriptor(expr, st, cursor - st, fields);
            try {
                return lastNode = new LiteralNode(typeDescriptor.getClassReference(pCtx), pCtx);
            } catch (ClassNotFoundException e) {
                throw new CompileException("could not resolve class: " + typeDescriptor.getClassName(), expr, st);
            }
        }
    }
    lastWasIdentifier = true;
    return lastNode = new ASTNode(expr, trimRight(st), trimLeft(end) - st, fields, pCtx);
}
Also used : LiteralNode(org.mvel2.ast.LiteralNode) LiteralDeepPropertyNode(org.mvel2.ast.LiteralDeepPropertyNode) TypeDescriptor(org.mvel2.ast.TypeDescriptor) ASTNode(org.mvel2.ast.ASTNode) CompileException(org.mvel2.CompileException) OperatorNode(org.mvel2.ast.OperatorNode)

Aggregations

CompileException (org.mvel2.CompileException)1 ASTNode (org.mvel2.ast.ASTNode)1 LiteralDeepPropertyNode (org.mvel2.ast.LiteralDeepPropertyNode)1 LiteralNode (org.mvel2.ast.LiteralNode)1 OperatorNode (org.mvel2.ast.OperatorNode)1 TypeDescriptor (org.mvel2.ast.TypeDescriptor)1