use of org.apache.commons.jexl3.parser.ASTReference in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method createExpression.
/**
* Creates a reference expression fro a child node
*
* @param childContainer
* @param wrappingContainer
* @return
*/
public static JexlNode createExpression(JexlNode childContainer, JexlNode wrappingContainer) {
ASTReference ref = new ASTReference(ParserTreeConstants.JJTREFERENCE);
ASTReferenceExpression exp = new ASTReferenceExpression(ParserTreeConstants.JJTREFERENCEEXPRESSION);
for (int i = 0; i < childContainer.jjtGetNumChildren(); i++) {
JexlNode child = childContainer.jjtGetChild(i);
child.jjtSetParent(ref);
exp.jjtAddChild(child, i);
i++;
}
exp.jjtSetParent(ref);
ref.jjtAddChild(exp, 0);
JexlNode newWrapper = shallowCopy(wrappingContainer);
ref.jjtSetParent(newWrapper);
newWrapper.jjtAddChild(ref, 0);
return newWrapper;
}
use of org.apache.commons.jexl3.parser.ASTReference in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method createAssignment.
/**
* Create an assignment node
*
* @param name
* @param value
* @return the assignment node
*/
public static ASTAssignment createAssignment(String name, boolean value) {
ASTAssignment assignNode = new ASTAssignment(ParserTreeConstants.JJTASSIGNMENT);
ASTReference refNode2 = new ASTReference(ParserTreeConstants.JJTREFERENCE);
refNode2.jjtSetParent(assignNode);
assignNode.jjtAddChild(refNode2, 0);
ASTIdentifier idNode = new ASTIdentifier(ParserTreeConstants.JJTIDENTIFIER);
idNode.image = name;
idNode.jjtSetParent(refNode2);
refNode2.jjtAddChild(idNode, 0);
if (value) {
ASTTrueNode trueNode = new ASTTrueNode(ParserTreeConstants.JJTTRUENODE);
trueNode.jjtSetParent(assignNode);
assignNode.jjtAddChild(trueNode, 1);
} else {
ASTFalseNode falseNode = new ASTFalseNode(ParserTreeConstants.JJTFALSENODE);
falseNode.jjtSetParent(assignNode);
assignNode.jjtAddChild(falseNode, 1);
}
return assignNode;
}
use of org.apache.commons.jexl3.parser.ASTReference in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method wrap.
/**
* Wrap an ASTAndNode or ASTOrNode in parenthesis if it has more than one child. Will return itself if wrapping is unnecessary.
*
* @param toWrap
* @return
*/
public static JexlNode wrap(JexlNode toWrap) {
if ((toWrap instanceof ASTAndNode || toWrap instanceof ASTOrNode) && toWrap.jjtGetNumChildren() > 1) {
ASTReference reference = new ASTReference(ParserTreeConstants.JJTREFERENCE);
ASTReferenceExpression parens = new ASTReferenceExpression(ParserTreeConstants.JJTREFERENCEEXPRESSION);
parens.jjtAddChild(toWrap, 0);
toWrap.jjtSetParent(parens);
reference.jjtAddChild(parens, 0);
parens.jjtSetParent(reference);
return reference;
}
return toWrap;
}
use of org.apache.commons.jexl3.parser.ASTReference in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method buildNewLiteralNode.
public static JexlNode buildNewLiteralNode(JexlNode original, String fieldName, String fieldValue) {
ASTReference literalReference = new ASTReference(ParserTreeConstants.JJTREFERENCE);
ASTStringLiteral literal = getLiteral(fieldValue);
literalReference.jjtAddChild(literal, 0);
literal.jjtSetParent(literalReference);
// we don't know whether the left or right side is the literal to replace. find it.
if (original.jjtGetChild(0) instanceof ASTReference && original.jjtGetChild(0).jjtGetChild(0) instanceof ASTIdentifier) {
// replace the original reference/literal (on left) with new reference/literal
original.jjtAddChild(literalReference, 1);
}
if (original.jjtGetChild(1) instanceof ASTReference && original.jjtGetChild(1).jjtGetChild(0) instanceof ASTIdentifier) {
// replace the original reference/literal (on right) with new reference/literal
original.jjtAddChild(literalReference, 0);
}
literalReference.jjtSetParent(original);
return original;
}
use of org.apache.commons.jexl3.parser.ASTReference in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method buildNewLiteralNode.
public static JexlNode buildNewLiteralNode(JexlNode original, String fieldName, Number fieldValue) {
ASTReference literalReference = new ASTReference(ParserTreeConstants.JJTREFERENCE);
ASTNumberLiteral literal = getLiteral(fieldValue);
literalReference.jjtAddChild(literal, 0);
literal.jjtSetParent(literalReference);
// we don't know whether the left or right side is the literal to replace. find it.
if (original.jjtGetChild(0) instanceof ASTReference && original.jjtGetChild(0).jjtGetChild(0) instanceof ASTIdentifier) {
// replace the original reference/literal (on left) with new reference/literal
original.jjtAddChild(literalReference, 1);
}
if (original.jjtGetChild(1) instanceof ASTReference && original.jjtGetChild(1).jjtGetChild(0) instanceof ASTIdentifier) {
// replace the original reference/literal (on right) with new reference/literal
original.jjtAddChild(literalReference, 0);
}
literalReference.jjtSetParent(original);
return original;
}
Aggregations