use of org.apache.commons.jexl3.parser.ASTReference in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method buildUntypedNewNode.
protected static JexlNode buildUntypedNewNode(JexlNode newNode, JexlNode literal, ASTIdentifier identifier) {
ASTReference literalReference = new ASTReference(ParserTreeConstants.JJTREFERENCE), identifierReference = new ASTReference(ParserTreeConstants.JJTREFERENCE);
literalReference.jjtAddChild(literal, 0);
literal.jjtSetParent(literalReference);
identifierReference.jjtAddChild(identifier, 0);
identifier.jjtSetParent(identifierReference);
newNode.jjtAddChild(literalReference, 0);
newNode.jjtAddChild(identifierReference, 1);
identifierReference.jjtSetParent(newNode);
literalReference.jjtSetParent(newNode);
return newNode;
}
use of org.apache.commons.jexl3.parser.ASTReference in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method buildUntypedDblIdentifierNode.
protected static JexlNode buildUntypedDblIdentifierNode(JexlNode newNode, JexlNode identifier1, JexlNode identifier2) {
ASTReference identifierReference1 = new ASTReference(ParserTreeConstants.JJTREFERENCE);
identifierReference1.jjtAddChild(identifier1, 0);
identifier1.jjtSetParent(identifierReference1);
ASTReference identifierReference2 = new ASTReference(ParserTreeConstants.JJTREFERENCE);
identifierReference2.jjtAddChild(identifier2, 0);
identifier2.jjtSetParent(identifierReference2);
newNode.jjtAddChild(identifierReference1, 0);
newNode.jjtAddChild(identifierReference2, 1);
identifierReference1.jjtSetParent(newNode);
identifierReference2.jjtSetParent(newNode);
return newNode;
}
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, String 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);
ASTStringLiteral literalNode = new ASTStringLiteral(ParserTreeConstants.JJTSTRINGLITERAL);
literalNode.jjtSetParent(assignNode);
literalNode.image = value;
assignNode.jjtAddChild(literalNode, 1);
return assignNode;
}
use of org.apache.commons.jexl3.parser.ASTReference in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method buildUntypedNewLiteralNode.
/**
* Like {@link #buildUntypedNewNode(JexlNode, ASTIdentifier, String)} except it does not wrap {@code literal} in an {@link ASTReference}
*
* @param newNode
* @param identifier
* @param literal
* @return
*/
protected static JexlNode buildUntypedNewLiteralNode(JexlNode newNode, ASTIdentifier identifier, JexlNode literal) {
ASTReference identifierReference = new ASTReference(ParserTreeConstants.JJTREFERENCE);
identifierReference.jjtAddChild(identifier, 0);
identifier.jjtSetParent(identifierReference);
newNode.jjtAddChild(identifierReference, 0);
newNode.jjtAddChild(literal, 1);
identifierReference.jjtSetParent(newNode);
literal.jjtSetParent(newNode);
return newNode;
}
use of org.apache.commons.jexl3.parser.ASTReference in project datawave by NationalSecurityAgency.
the class BooleanOptimizationRebuildingVisitor method prune.
/**
* Returns a tuple where the first element is the new node and the second element is the node that was pruned.
*
* @param currentNode
* @param newNode
* @param prunedNode
*/
private Tuple2<JexlNode, JexlNode> prune(JexlNode currentNode, JexlNode newNode, JexlNode prunedNode) {
for (int i = 0; i < currentNode.jjtGetNumChildren(); i++) {
JexlNode child = currentNode.jjtGetChild(i);
if (child instanceof ASTOrNode && child.jjtGetNumChildren() > prunedNode.jjtGetNumChildren()) {
if (prunedNode.jjtGetNumChildren() > 0) {
newNode.jjtAddChild(prunedNode, newNode.jjtGetNumChildren());
prunedNode.jjtSetParent(newNode);
}
prunedNode = child;
} else if (((child instanceof ASTReference) || (child instanceof ASTReferenceExpression) || child.getClass().equals(currentNode.getClass())) && hasChildOr(child)) {
Tuple2<JexlNode, JexlNode> nodes = prune(child, newNode, prunedNode);
newNode = nodes.first();
prunedNode = nodes.second();
} else {
newNode.jjtAddChild(child, newNode.jjtGetNumChildren());
child.jjtSetParent(newNode);
}
}
return new Tuple2<>(newNode, prunedNode);
}
Aggregations