当前位置: 首页>>代码示例>>Java>>正文


Java Expression类代码示例

本文整理汇总了Java中com.mitchellbosecke.pebble.node.expression.Expression的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Expression类属于com.mitchellbosecke.pebble.node.expression包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
@Override
public void visit(PrintNode node) {
    Expression<?> expression = node.getExpression();

    if (expression instanceof TernaryExpression) {
        TernaryExpression ternary = (TernaryExpression) expression;
        Expression<?> left = ternary.getExpression2();
        Expression<?> right = ternary.getExpression3();
        if (!isSafe(left)) {
            ternary.setExpression2(escape(left));
        }
        if (!isSafe(right)) {
            ternary.setExpression3(escape(right));
        }
    } else {
        if (!isSafe(expression)) {
            node.setExpression(escape(expression));
        }
    }
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:21,代码来源:EscaperNodeVisitor.java

示例2: isSafe

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
private boolean isSafe(Expression<?> expression) {

        // check whether the autoescaper is even active
        if (!active.isEmpty() && !active.peek()) {
            return true;
        }

        boolean safe = false;

        // string literals are safe
        if (expression instanceof LiteralStringExpression) {
            safe = true;
        } else if (expression instanceof ParentFunctionExpression || expression instanceof BlockFunctionExpression) {
            safe = true;
        } else if (isSafeConcatenateExpr(expression)) {
            safe = true;
        }

        return safe;
    }
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:21,代码来源:EscaperNodeVisitor.java

示例3: parseTernaryExpression

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Expression<?> parseTernaryExpression(Expression<?> expression) throws ParserException {
    // if the next token isn't a ?, we're not dealing with a ternary
    // expression
    if (!stream.current().test(Token.Type.PUNCTUATION, "?"))
        return expression;

    stream.next();
    Expression<?> expression2 = parseExpression();
    stream.expect(Token.Type.PUNCTUATION, ":");
    Expression<?> expression3 = parseExpression();

    expression = new TernaryExpression((Expression<Boolean>) expression, expression2, expression3, this.stream
            .current().getLineNumber(), stream.getFilename());
    return expression;
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:ExpressionParser.java

示例4: parsePostfixExpression

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
/**
 * Determines if there is more to the provided expression than we originally
 * thought. We will look for the filter operator or perhaps we are getting
 * an attribute from a variable (ex. var.attribute or var['attribute'] or
 * var.attribute(bar)).
 *
 * @param node
 *            The expression that we have already discovered
 * @return Either the original expression that was passed in or a slightly
 *         modified version of it, depending on what was discovered.
 * @throws ParserException
 *             Thrown if a parsing error occurs.
 */
private Expression<?> parsePostfixExpression(Expression<?> node) throws ParserException {
    Token current;
    while (true) {
        current = stream.current();

        if (current.test(Token.Type.PUNCTUATION, ".") || current.test(Token.Type.PUNCTUATION, "[")) {

            // a period represents getting an attribute from a variable or
            // calling a method
            node = parseBeanAttributeExpression(node);

        } else if (current.test(Token.Type.PUNCTUATION, "(")) {

            // function call
            node = parseFunctionOrMacroInvocation(node);

        } else {
            break;
        }
    }
    return node;
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:36,代码来源:ExpressionParser.java

示例5: parseFunctionOrMacroInvocation

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
private Expression<?> parseFunctionOrMacroInvocation(Expression<?> node) throws ParserException {
    String functionName = ((FunctionOrMacroNameNode) node).getName();
    ArgumentsNode args = parseArguments();

    /*
     * The following core functions have their own Nodes and are rendered in
     * unique ways for the sake of performance.
     */
    switch (functionName) {
    case "parent":
        return new ParentFunctionExpression(parser.peekBlockStack(), stream.current().getLineNumber());
    case "block":
        return new BlockFunctionExpression(args, node.getLineNumber());
    }

    return new FunctionOrMacroInvocationExpression(functionName, args, node.getLineNumber());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:18,代码来源:ExpressionParser.java

示例6: parse

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip over the tag name token
    stream.next();

    // parameter expressions will be added here
    Map<String, Expression<?>> paramExpressionMap = parseParams(stream, parser);
    Expression<?> tagBodyExpression = null;
    if(hasContent) {
        tagBodyExpression = parseBody(stream, parser);
    }
    else {
        stream.expect(Token.Type.EXECUTE_END);
    }

    return new TemplateTagNode(lineNumber, paramExpressionMap, tagBodyExpression);
}
 
开发者ID:JavaEden,项目名称:Orchid,代码行数:21,代码来源:PebbleWrapperTemplateTag.java

示例7: visit

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
@Override
public void visit(IfNode node) {
    for (Pair<Expression<?>, BodyNode> pairs : node.getConditionsWithBodies()) {
        pairs.getLeft().accept(this);
        pairs.getRight().accept(this);
    }
    if (node.getElseBody() != null) {
        node.getElseBody().accept(this);
    }
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:11,代码来源:AbstractNodeVisitor.java

示例8: escape

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
/**
 * Simply wraps the input expression with a {@link EscapeFilter}.
 *
 * @param expression
 * @return
 */
private Expression<?> escape(Expression<?> expression) {

    /*
     * Build the arguments to the escape filter. The arguments will just
     * include the strategy being used.
     */
    List<NamedArgumentNode> namedArgs = new ArrayList<>();
    if (!strategies.isEmpty() && strategies.peek() != null) {
        String strategy = strategies.peek();
        namedArgs.add(new NamedArgumentNode("strategy",
                new LiteralStringExpression(strategy, expression.getLineNumber())));
    }
    ArgumentsNode args = new ArgumentsNode(null, namedArgs, expression.getLineNumber());

    /*
     * Create the filter invocation with the newly created named arguments.
     */
    FilterInvocationExpression filter = new FilterInvocationExpression("escape", args, expression.getLineNumber());

    /*
     * The given expression and the filter invocation now become a binary
     * expression which is what is returned.
     */
    FilterExpression binary = new FilterExpression();
    binary.setLeft(expression);
    binary.setRight(filter);
    return binary;
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:35,代码来源:EscaperNodeVisitor.java

示例9: isSafeConcatenateExpr

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
/**
 * Returns true if {@code expr} is a {@link ConcatenateExpression} made up
 * of two {@link LiteralStringExpression}s.
 */
private boolean isSafeConcatenateExpr(Expression<?> expr) {
    if (!(expr instanceof ConcatenateExpression)) {
        return false;
    }
    ConcatenateExpression cexpr = (ConcatenateExpression) expr;
    return cexpr.getLeftExpression() instanceof LiteralStringExpression
            && cexpr.getRightExpression() instanceof LiteralStringExpression;
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:13,代码来源:EscaperNodeVisitor.java

示例10: parseTestInvocationExpression

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
private Expression<?> parseTestInvocationExpression() throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = stream.current().getLineNumber();

    Token testToken = stream.expect(Token.Type.NAME);

    ArgumentsNode args = null;
    if (stream.current().test(Token.Type.PUNCTUATION, "(")) {
        args = this.parseArguments();
    } else {
        args = new ArgumentsNode(null, null, testToken.getLineNumber());
    }

    return new TestInvocationExpression(lineNumber, testToken.getValue(), args);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:16,代码来源:ExpressionParser.java

示例11: parseBeanAttributeExpression

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
/**
 * A bean attribute expression can either be an expression getting an
 * attribute from a variable in the context, or calling a method from a
 * variable.
 *
 * Ex. foo.bar or foo['bar'] or foo.bar('baz')
 *
 * @param node
 *            The expression parsed so far
 * @return NodeExpression The parsed subscript expression
 * @throws ParserException
 *             Thrown if a parsing error occurs.
 */
private Expression<?> parseBeanAttributeExpression(Expression<?> node) throws ParserException {
    TokenStream stream = parser.getStream();

    if (stream.current().test(Token.Type.PUNCTUATION, ".")) {

        // skip over the '.' token
        stream.next();

        Token token = stream.expect(Token.Type.NAME);

        ArgumentsNode args = null;
        if (stream.current().test(Token.Type.PUNCTUATION, "(")) {
            args = this.parseArguments();
            if (!args.getNamedArgs().isEmpty()) {
                throw new ParserException(null, "Can not use named arguments when calling a bean method", stream
                        .current().getLineNumber(), stream.getFilename());
            }
        }

        node = new GetAttributeExpression(node,
                new LiteralStringExpression(token.getValue(), token.getLineNumber()), args,
                stream.getFilename(), token.getLineNumber());

    } else if (stream.current().test(Token.Type.PUNCTUATION, "[")) {
        // skip over opening '[' bracket
        stream.next();

        node = new GetAttributeExpression(node, parseExpression(), stream.getFilename(), stream.current()
                .getLineNumber());

        // move past the closing ']' bracket
        stream.expect(Token.Type.PUNCTUATION, "]");
    }

    return node;
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:50,代码来源:ExpressionParser.java

示例12: parseArrayDefinitionExpression

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
private Expression<?> parseArrayDefinitionExpression() throws ParserException {
    TokenStream stream = parser.getStream();

    // expect the opening bracket and check for an empty array
    stream.expect(Token.Type.PUNCTUATION, "[");
    if (stream.current().test(Token.Type.PUNCTUATION, "]")) {
        stream.next();
        return new ArrayExpression(stream.current().getLineNumber());
    }

    // there's at least one expression in the array
    List<Expression<?>> elements = new ArrayList<>();
    while (true) {
        Expression<?> expr = parseExpression();
        elements.add(expr);
        if (stream.current().test(Token.Type.PUNCTUATION, "]")) {
            // this seems to be the end of the array
            break;
        }
        // expect the comma separator, until we either find a closing
        // bracket or fail the expect
        stream.expect(Token.Type.PUNCTUATION, ",");
    }

    // expect the closing bracket
    stream.expect(Token.Type.PUNCTUATION, "]");

    return new ArrayExpression(elements, stream.current().getLineNumber());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:30,代码来源:ExpressionParser.java

示例13: parseMapDefinitionExpression

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
private Expression<?> parseMapDefinitionExpression() throws ParserException {
    TokenStream stream = parser.getStream();

    // expect the opening brace and check for an empty map
    stream.expect(Token.Type.PUNCTUATION, "{");
    if (stream.current().test(Token.Type.PUNCTUATION, "}")) {
        stream.next();
        return new MapExpression(stream.current().getLineNumber());
    }

    // there's at least one expression in the map
    Map<Expression<?>, Expression<?>> elements = new HashMap<>();
    while (true) {
        // key : value
        Expression<?> keyExpr = parseExpression();
        stream.expect(Token.Type.PUNCTUATION, ":");
        Expression<?> valueExpr = parseExpression();
        elements.put(keyExpr, valueExpr);
        if (stream.current().test(Token.Type.PUNCTUATION, "}")) {
            // this seems to be the end of the map
            break;
        }
        // expect the comma separator, until we either find a closing brace
        // or fail the expect
        stream.expect(Token.Type.PUNCTUATION, ",");
    }

    // expect the closing brace
    stream.expect(Token.Type.PUNCTUATION, "}");

    return new MapExpression(elements, stream.current().getLineNumber());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:33,代码来源:ExpressionParser.java

示例14: parse

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {

    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip over the 'include' token
    stream.next();

    Expression<?> includeExpression = parser.getExpressionParser().parseExpression();

    Token current = stream.current();
    MapExpression mapExpression = null;

    // We check if there is an optional 'with' parameter on the include tag.
    if (current.getType().equals(Token.Type.NAME) && current.getValue().equals("with")) {

        // Skip over 'with'
        stream.next();

        Expression<?> parsedExpression = parser.getExpressionParser().parseExpression();

        if (parsedExpression instanceof MapExpression) {
            mapExpression = (MapExpression) parsedExpression;
        } else {
            throw new ParserException(null, String.format("Unexpected expression '%1s'.", parsedExpression
                    .getClass().getCanonicalName()), token.getLineNumber(), stream.getFilename());
        }

    }

    stream.expect(Token.Type.EXECUTE_END);

    return new IncludeNode(lineNumber, includeExpression, mapExpression);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:36,代码来源:IncludeTokenParser.java

示例15: parse

import com.mitchellbosecke.pebble.node.expression.Expression; //导入依赖的package包/类
@Override
public RenderableNode parse(Token token, Parser parser) throws ParserException {
    TokenStream stream = parser.getStream();
    int lineNumber = token.getLineNumber();

    // skip the 'extends' token
    stream.next();

    Expression<?> parentTemplateExpression = parser.getExpressionParser().parseExpression();

    stream.expect(Token.Type.EXECUTE_END);
    return new ExtendsNode(lineNumber, parentTemplateExpression);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:14,代码来源:ExtendsTokenParser.java


注:本文中的com.mitchellbosecke.pebble.node.expression.Expression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。