Search in sources :

Example 6 with ASTReference

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;
}
Also used : ASTReference(org.apache.commons.jexl2.parser.ASTReference)

Example 7 with ASTReference

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;
}
Also used : ASTReference(org.apache.commons.jexl2.parser.ASTReference)

Example 8 with ASTReference

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;
}
Also used : ASTStringLiteral(org.apache.commons.jexl2.parser.ASTStringLiteral) ASTIdentifier(org.apache.commons.jexl2.parser.ASTIdentifier) ASTAssignment(org.apache.commons.jexl2.parser.ASTAssignment) ASTReference(org.apache.commons.jexl2.parser.ASTReference)

Example 9 with ASTReference

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;
}
Also used : ASTReference(org.apache.commons.jexl2.parser.ASTReference)

Example 10 with ASTReference

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);
}
Also used : ASTOrNode(org.apache.commons.jexl2.parser.ASTOrNode) ASTReferenceExpression(org.apache.commons.jexl2.parser.ASTReferenceExpression) Tuple2(datawave.query.util.Tuple2) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ASTReference(org.apache.commons.jexl2.parser.ASTReference)

Aggregations

ASTReference (org.apache.commons.jexl2.parser.ASTReference)28 JexlNode (org.apache.commons.jexl2.parser.JexlNode)17 ASTReferenceExpression (org.apache.commons.jexl2.parser.ASTReferenceExpression)11 ASTIdentifier (org.apache.commons.jexl2.parser.ASTIdentifier)8 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)7 ASTOrNode (org.apache.commons.jexl2.parser.ASTOrNode)6 ASTStringLiteral (org.apache.commons.jexl2.parser.ASTStringLiteral)6 ASTEQNode (org.apache.commons.jexl2.parser.ASTEQNode)5 ArrayList (java.util.ArrayList)4 ASTERNode (org.apache.commons.jexl2.parser.ASTERNode)4 ASTNRNode (org.apache.commons.jexl2.parser.ASTNRNode)4 ASTIdentifierAccess (org.apache.commons.jexl3.parser.ASTIdentifierAccess)4 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)3 List (java.util.List)3 ASTAssignment (org.apache.commons.jexl2.parser.ASTAssignment)3 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)3 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)3 ASTNumberLiteral (org.apache.commons.jexl2.parser.ASTNumberLiteral)3 ASTIdentifier (org.apache.commons.jexl3.parser.ASTIdentifier)3 ASTReference (org.apache.commons.jexl3.parser.ASTReference)3