Search in sources :

Example 26 with ASTReference

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;
}
Also used : ASTReferenceExpression(org.apache.commons.jexl2.parser.ASTReferenceExpression) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode) ASTReference(org.apache.commons.jexl2.parser.ASTReference)

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

Example 28 with ASTReference

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

Example 29 with ASTReference

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

Example 30 with ASTReference

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

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