org.apache.el.parser.AstIdentifier Java Examples

The following examples show how to use org.apache.el.parser.AstIdentifier. 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: ExpressionBuilder.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public MethodExpression createMethodExpression(Class<?> expectedReturnType,
        Class<?>[] expectedParamTypes) throws ELException {
    Node n = this.build();
    if (!n.isParametersProvided() && expectedParamTypes == null) {
        throw new NullPointerException(MessageFactory
                .get("error.method.nullParms"));
    }
    if (n instanceof AstValue || n instanceof AstIdentifier) {
        return new MethodExpressionImpl(expression, n, this.fnMapper,
                this.varMapper, expectedReturnType, expectedParamTypes);
    } else if (n instanceof AstLiteralExpression) {
        return new MethodExpressionLiteral(expression, expectedReturnType,
                expectedParamTypes);
    } else {
        throw new ELException("Not a Valid Method Expression: "
                + expression);
    }
}
 
Example #2
Source File: ExpressionBuilder.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
public MethodExpression createMethodExpression(Class<?> expectedReturnType,
        Class<?>[] expectedParamTypes) throws ELException {
    Node n = this.build();
    if (!n.isParametersProvided() && expectedParamTypes == null) {
        throw new NullPointerException(MessageFactory
                .get("error.method.nullParms"));
    }
    if (n instanceof AstValue || n instanceof AstIdentifier) {
        return new MethodExpressionImpl(expression, n, this.fnMapper,
                this.varMapper, expectedReturnType, expectedParamTypes);
    } else if (n instanceof AstLiteralExpression) {
        return new MethodExpressionLiteral(expression, expectedReturnType,
                expectedParamTypes);
    } else {
        throw new ELException("Not a Valid Method Expression: "
                + expression);
    }
}
 
Example #3
Source File: ExpressionBuilder.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
public MethodExpression createMethodExpression(Class<?> expectedReturnType,
        Class<?>[] expectedParamTypes) throws ELException {
    Node n = this.build();
    if (!n.isParametersProvided() && expectedParamTypes == null) {
        throw new NullPointerException(MessageFactory
                .get("error.method.nullParms"));
    }
    if (n instanceof AstValue || n instanceof AstIdentifier) {
        return new MethodExpressionImpl(expression, n, this.fnMapper,
                this.varMapper, expectedReturnType, expectedParamTypes);
    } else if (n instanceof AstLiteralExpression) {
        return new MethodExpressionLiteral(expression, expectedReturnType,
                expectedParamTypes);
    } else {
        throw new ELException("Not a Valid Method Expression: "
                + expression);
    }
}
 
Example #4
Source File: RuleVerifyUtils.java    From proctor with Apache License 2.0 6 votes vote down vote up
private static Node checkUndefinedIdentifier(final Node node, final ELContext elContext, final Set<String> absentIdentifiers) {
    if (node instanceof AstIdentifier) {
        final String name = node.getImage();
        final boolean hasVariable = elContext.getVariableMapper().resolveVariable(name) != null;
        if (!hasVariable && !absentIdentifiers.contains(name)) {
            return node;
        }
    } else {
        for (int i = 0; i < node.jjtGetNumChildren(); i++) {
            final Node result = checkUndefinedIdentifier(node.jjtGetChild(i), elContext, absentIdentifiers);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
 
Example #5
Source File: ExpressionBuilder.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(Node node) throws ELException {
    if (node instanceof AstFunction) {

        AstFunction funcNode = (AstFunction) node;

        if (this.fnMapper == null) {
            throw new ELException(MessageFactory.get("error.fnMapper.null"));
        }
        Method m = fnMapper.resolveFunction(funcNode.getPrefix(), funcNode
                .getLocalName());
        if (m == null) {
            throw new ELException(MessageFactory.get(
                    "error.fnMapper.method", funcNode.getOutputName()));
        }
        int pcnt = m.getParameterTypes().length;
        if (node.jjtGetNumChildren() != pcnt) {
            throw new ELException(MessageFactory.get(
                    "error.fnMapper.paramcount", funcNode.getOutputName(),
                    "" + pcnt, "" + node.jjtGetNumChildren()));
        }
    } else if (node instanceof AstIdentifier && this.varMapper != null) {
        String variable = ((AstIdentifier) node).getImage();

        // simply capture it
        this.varMapper.resolveVariable(variable);
    }
}
 
Example #6
Source File: ExpressionBuilder.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(Node node) throws ELException {
    if (node instanceof AstFunction) {

        AstFunction funcNode = (AstFunction) node;

        if (this.fnMapper == null) {
            throw new ELException(MessageFactory.get("error.fnMapper.null"));
        }
        Method m = fnMapper.resolveFunction(funcNode.getPrefix(), funcNode
                .getLocalName());
        if (m == null) {
            throw new ELException(MessageFactory.get(
                    "error.fnMapper.method", funcNode.getOutputName()));
        }
        int pcnt = m.getParameterTypes().length;
        if (node.jjtGetNumChildren() != pcnt) {
            throw new ELException(MessageFactory.get(
                    "error.fnMapper.paramcount", funcNode.getOutputName(),
                    "" + pcnt, "" + node.jjtGetNumChildren()));
        }
    } else if (node instanceof AstIdentifier && this.varMapper != null) {
        String variable = ((AstIdentifier) node).getImage();

        // simply capture it
        this.varMapper.resolveVariable(variable);
    }
}
 
Example #7
Source File: ExpressionBuilder.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public void visit(Node node) throws ELException {
    if (node instanceof AstFunction) {

        AstFunction funcNode = (AstFunction) node;

        Method m = null;

        if (this.fnMapper != null) {
            m = fnMapper.resolveFunction(funcNode.getPrefix(), funcNode
                    .getLocalName());
        }

        // References to variables that refer to lambda expressions will be
        // parsed as functions. This is handled at runtime but at this point
        // need to treat it as a variable rather than a function.
        if (m == null && this.varMapper != null &&
                funcNode.getPrefix().length() == 0) {
            this.varMapper.resolveVariable(funcNode.getLocalName());
            return;
        }

        if (this.fnMapper == null) {
            throw new ELException(MessageFactory.get("error.fnMapper.null"));
        }

        if (m == null) {
            throw new ELException(MessageFactory.get(
                    "error.fnMapper.method", funcNode.getOutputName()));
        }

        int methodParameterCount = m.getParameterTypes().length;
        // AstFunction->MethodParameters->Parameters()
        int inputParameterCount = node.jjtGetChild(0).jjtGetNumChildren();
        if (m.isVarArgs() && inputParameterCount < methodParameterCount - 1 ||
                !m.isVarArgs() && inputParameterCount != methodParameterCount) {
            throw new ELException(MessageFactory.get(
                    "error.fnMapper.paramcount", funcNode.getOutputName(),
                    "" + methodParameterCount, "" + node.jjtGetChild(0).jjtGetNumChildren()));
        }
    } else if (node instanceof AstIdentifier && this.varMapper != null) {
        String variable = ((AstIdentifier) node).getImage();

        // simply capture it
        this.varMapper.resolveVariable(variable);
    }
}