com.sap.cds.impl.parser.ExpressionParser Maven / Gradle / Ivy
/*******************************************************************
* © 2019 SAP SE or an SAP affiliate company. All rights reserved. *
*******************************************************************/
package com.sap.cds.impl.parser;
import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.collect.Lists;
import com.sap.cds.impl.parser.builder.ExpressionBuilder;
import com.sap.cds.ql.cqn.CqnExpression;
import com.sap.cds.ql.cqn.CqnPredicate;
import com.sap.cds.ql.cqn.CqnToken;
public class ExpressionParser {
private ExpressionParser() {
}
public static CqnExpression parse(String cqnExpr) {
ArrayNode expr = CqnParser.getDocumentContext(cqnExpr).read("$");
return ExpressionBuilder.create(parseTokens(expr)).build();
}
public static CqnExpression parse(JsonNode expr) {
return ExpressionBuilder.create(TokenParser.parse(expr)).build();
}
public static CqnExpression parse(ArrayNode where) {
if (where != null) {
return ExpressionBuilder.create(parseTokens(where)).build();
}
return null;
}
public static CqnPredicate parsePredicate(String cqnExpr) {
ArrayNode expr = CqnParser.getDocumentContext(cqnExpr).read("$");
return parsePredicate(expr);
}
public static List parseTokens(String cqnExpr) {
ArrayNode expr = CqnParser.getDocumentContext(cqnExpr).read("$");
return parseTokens(expr);
}
public static CqnPredicate parsePredicate(JsonNode expr) {
if (expr == null) {
return null;
}
if (expr.isArray()) {
List tokens = parseTokens((ArrayNode) expr);
return new ExprParser().parsePredicate(tokens);
}
return ExpressionBuilder.create(TokenParser.parse(expr)).buildPredicate();
}
public static List parseTokens(ArrayNode arrayNode) {
List tokens = Lists.newArrayList();
if (arrayNode != null) {
arrayNode.forEach(n -> tokens.add(TokenParser.parse(n)));
}
return tokens;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy