Search in sources :

Example 1 with ASTAssignment

use of org.apache.commons.jexl2.parser.ASTAssignment in project datawave by NationalSecurityAgency.

the class JexlNodeFactory method shallowCopy.

/**
 * A shallow copy of the given JexlNode, creates a new node of the same type with the same parent and image. Children are not copied
 *
 * @param original
 * @return
 */
public static JexlNode shallowCopy(JexlNode original) {
    if (null == original) {
        throw new IllegalArgumentException();
    }
    JexlNode copy;
    Class<?> clz = original.getClass();
    if (ASTAndNode.class.isAssignableFrom(clz)) {
        copy = new ASTAndNode(ParserTreeConstants.JJTANDNODE);
    } else if (ASTBitwiseAndNode.class.isAssignableFrom(clz)) {
        copy = new ASTBitwiseAndNode(ParserTreeConstants.JJTBITWISEANDNODE);
    } else if (ASTBitwiseComplNode.class.isAssignableFrom(clz)) {
        copy = new ASTBitwiseComplNode(ParserTreeConstants.JJTBITWISECOMPLNODE);
    } else if (ASTBitwiseOrNode.class.isAssignableFrom(clz)) {
        copy = new ASTBitwiseOrNode(ParserTreeConstants.JJTBITWISEORNODE);
    } else if (ASTBitwiseXorNode.class.isAssignableFrom(clz)) {
        copy = new ASTBitwiseXorNode(ParserTreeConstants.JJTBITWISEXORNODE);
    } else if (ASTEmptyFunction.class.isAssignableFrom(clz)) {
        copy = new ASTEmptyFunction(ParserTreeConstants.JJTEMPTYFUNCTION);
    } else if (ASTEQNode.class.isAssignableFrom(clz)) {
        copy = new ASTEQNode(ParserTreeConstants.JJTEQNODE);
    } else if (ASTERNode.class.isAssignableFrom(clz)) {
        copy = new ASTERNode(ParserTreeConstants.JJTERNODE);
    } else if (ASTFalseNode.class.isAssignableFrom(clz)) {
        copy = new ASTFalseNode(ParserTreeConstants.JJTFALSENODE);
    } else if (ASTGENode.class.isAssignableFrom(clz)) {
        copy = new ASTGENode(ParserTreeConstants.JJTGENODE);
    } else if (ASTGTNode.class.isAssignableFrom(clz)) {
        copy = new ASTGTNode(ParserTreeConstants.JJTGTNODE);
    } else if (ASTIdentifier.class.isAssignableFrom(clz)) {
        copy = new ASTIdentifier(ParserTreeConstants.JJTIDENTIFIER);
    } else if (ASTLENode.class.isAssignableFrom(clz)) {
        copy = new ASTLENode(ParserTreeConstants.JJTLENODE);
    } else if (ASTLTNode.class.isAssignableFrom(clz)) {
        copy = new ASTLTNode(ParserTreeConstants.JJTLTNODE);
    } else if (ASTNENode.class.isAssignableFrom(clz)) {
        copy = new ASTNENode(ParserTreeConstants.JJTNENODE);
    } else if (ASTNRNode.class.isAssignableFrom(clz)) {
        copy = new ASTNRNode(ParserTreeConstants.JJTNRNODE);
    } else if (ASTNotNode.class.isAssignableFrom(clz)) {
        copy = new ASTNotNode(ParserTreeConstants.JJTNOTNODE);
    } else if (ASTNullLiteral.class.isAssignableFrom(clz)) {
        copy = new ASTNullLiteral(ParserTreeConstants.JJTNULLLITERAL);
    } else if (ASTNumberLiteral.class.isAssignableFrom(clz)) {
        copy = new ASTNumberLiteral(ParserTreeConstants.JJTNUMBERLITERAL);
        JexlNodes.setLiteral((ASTNumberLiteral) copy, ((ASTNumberLiteral) original).getLiteral());
    } else if (ASTOrNode.class.isAssignableFrom(clz)) {
        copy = new ASTOrNode(ParserTreeConstants.JJTORNODE);
    } else if (ASTStringLiteral.class.isAssignableFrom(clz)) {
        copy = new ASTStringLiteral(ParserTreeConstants.JJTSTRINGLITERAL);
        JexlNodes.setLiteral((ASTStringLiteral) copy, ((ASTStringLiteral) original).getLiteral());
    } else if (ASTTrueNode.class.isAssignableFrom(clz)) {
        copy = new ASTTrueNode(ParserTreeConstants.JJTTRUENODE);
    } else if (ASTReferenceExpression.class.isAssignableFrom(clz)) {
        copy = new ASTReferenceExpression(ParserTreeConstants.JJTREFERENCEEXPRESSION);
    } else if (ASTReference.class.isAssignableFrom(clz)) {
        copy = new ASTReference(ParserTreeConstants.JJTREFERENCE);
    } else if (ASTAdditiveNode.class.isAssignableFrom(clz)) {
        copy = new ASTAdditiveNode(ParserTreeConstants.JJTADDITIVENODE);
    } else if (ASTMethodNode.class.isAssignableFrom(clz)) {
        copy = new ASTMethodNode(ParserTreeConstants.JJTMETHODNODE);
    } else if (ASTFunctionNode.class.isAssignableFrom(clz)) {
        copy = new ASTFunctionNode(ParserTreeConstants.JJTFUNCTIONNODE);
    } else if (ASTMulNode.class.isAssignableFrom(clz)) {
        copy = new ASTMulNode(ParserTreeConstants.JJTMULNODE);
    } else if (ASTAssignment.class.isAssignableFrom(clz)) {
        copy = new ASTAssignment(ParserTreeConstants.JJTASSIGNMENT);
    } else {
        throw new UnsupportedOperationException();
    }
    copy.jjtSetParent(original.jjtGetParent());
    copy.image = original.image;
    return copy;
}
Also used : ASTReferenceExpression(org.apache.commons.jexl2.parser.ASTReferenceExpression) ASTNENode(org.apache.commons.jexl2.parser.ASTNENode) ASTNumberLiteral(org.apache.commons.jexl2.parser.ASTNumberLiteral) ASTMulNode(org.apache.commons.jexl2.parser.ASTMulNode) ASTBitwiseComplNode(org.apache.commons.jexl2.parser.ASTBitwiseComplNode) ASTMethodNode(org.apache.commons.jexl2.parser.ASTMethodNode) ASTBitwiseXorNode(org.apache.commons.jexl2.parser.ASTBitwiseXorNode) ASTOrNode(org.apache.commons.jexl2.parser.ASTOrNode) ASTStringLiteral(org.apache.commons.jexl2.parser.ASTStringLiteral) ASTBitwiseAndNode(org.apache.commons.jexl2.parser.ASTBitwiseAndNode) ASTNotNode(org.apache.commons.jexl2.parser.ASTNotNode) ASTGENode(org.apache.commons.jexl2.parser.ASTGENode) ASTERNode(org.apache.commons.jexl2.parser.ASTERNode) ASTAdditiveNode(org.apache.commons.jexl2.parser.ASTAdditiveNode) ASTNRNode(org.apache.commons.jexl2.parser.ASTNRNode) ASTTrueNode(org.apache.commons.jexl2.parser.ASTTrueNode) ASTIdentifier(org.apache.commons.jexl2.parser.ASTIdentifier) ASTAssignment(org.apache.commons.jexl2.parser.ASTAssignment) ASTGTNode(org.apache.commons.jexl2.parser.ASTGTNode) ASTNullLiteral(org.apache.commons.jexl2.parser.ASTNullLiteral) ASTLTNode(org.apache.commons.jexl2.parser.ASTLTNode) ASTReference(org.apache.commons.jexl2.parser.ASTReference) ASTBitwiseOrNode(org.apache.commons.jexl2.parser.ASTBitwiseOrNode) ASTFunctionNode(org.apache.commons.jexl2.parser.ASTFunctionNode) ASTLENode(org.apache.commons.jexl2.parser.ASTLENode) ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ASTFalseNode(org.apache.commons.jexl2.parser.ASTFalseNode) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode) ASTEmptyFunction(org.apache.commons.jexl2.parser.ASTEmptyFunction) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Example 2 with ASTAssignment

use of org.apache.commons.jexl2.parser.ASTAssignment 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 3 with ASTAssignment

use of org.apache.commons.jexl2.parser.ASTAssignment in project commons-jexl by apache.

the class Debugger method visit.

@Override
protected Object visit(final ASTJexlScript node, Object arg) {
    Object data = arg;
    // if lambda, produce parameters
    if (node instanceof ASTJexlLambda) {
        final JexlNode parent = node.jjtGetParent();
        // use lambda syntax if not assigned
        final boolean named = parent instanceof ASTAssignment;
        if (named) {
            builder.append("function");
        }
        builder.append('(');
        final String[] params = node.getParameters();
        if (params != null && params.length > 0) {
            builder.append(visitParameter(params[0], data));
            for (int p = 1; p < params.length; ++p) {
                builder.append(", ");
                builder.append(visitParameter(params[p], data));
            }
        }
        builder.append(')');
        if (named) {
            builder.append(' ');
        } else {
            builder.append("->");
        }
    // we will need a block...
    }
    // no parameters or done with them
    final int num = node.jjtGetNumChildren();
    if (num == 1 && !(node instanceof ASTJexlLambda)) {
        data = accept(node.jjtGetChild(0), data);
    } else {
        for (int i = 0; i < num; ++i) {
            final JexlNode child = node.jjtGetChild(i);
            acceptStatement(child, data);
        }
    }
    return data;
}
Also used : ASTJexlLambda(org.apache.commons.jexl3.parser.ASTJexlLambda) JexlNode(org.apache.commons.jexl3.parser.JexlNode) ASTAssignment(org.apache.commons.jexl3.parser.ASTAssignment)

Example 4 with ASTAssignment

use of org.apache.commons.jexl2.parser.ASTAssignment in project datawave by NationalSecurityAgency.

the class RangeStream method visit.

@Override
public Object visit(ASTAssignment node, Object data) {
    // If we have an assignment of shards/days, then generate a stream of shards/days
    String identifier = JexlASTHelper.getIdentifier(node);
    if (Constants.SHARD_DAY_HINT.equals(identifier)) {
        JexlNode myNode = JexlNodeFactory.createExpression(node);
        String[] shardsAndDays = StringUtils.split(JexlASTHelper.getLiteralValue(node).toString(), ',');
        if (shardsAndDays.length > 0) {
            return ScannerStream.withData(createIndexScanList(shardsAndDays).iterator(), myNode);
        } else {
            return ScannerStream.noData(myNode);
        }
    }
    return null;
}
Also used : ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) ExceededOrThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode) IndexHoleMarkerJexlNode(datawave.query.jexl.nodes.IndexHoleMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)

Example 5 with ASTAssignment

use of org.apache.commons.jexl2.parser.ASTAssignment 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)

Aggregations

ASTAssignment (org.apache.commons.jexl2.parser.ASTAssignment)4 ASTIdentifier (org.apache.commons.jexl2.parser.ASTIdentifier)3 ASTReference (org.apache.commons.jexl2.parser.ASTReference)3 ExceededTermThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)2 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)2 ASTFalseNode (org.apache.commons.jexl2.parser.ASTFalseNode)2 ASTStringLiteral (org.apache.commons.jexl2.parser.ASTStringLiteral)2 ASTTrueNode (org.apache.commons.jexl2.parser.ASTTrueNode)2 JexlNode (org.apache.commons.jexl2.parser.JexlNode)2 ExceededOrThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode)1 IndexHoleMarkerJexlNode (datawave.query.jexl.nodes.IndexHoleMarkerJexlNode)1 ASTAdditiveNode (org.apache.commons.jexl2.parser.ASTAdditiveNode)1 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)1 ASTBitwiseAndNode (org.apache.commons.jexl2.parser.ASTBitwiseAndNode)1 ASTBitwiseComplNode (org.apache.commons.jexl2.parser.ASTBitwiseComplNode)1 ASTBitwiseOrNode (org.apache.commons.jexl2.parser.ASTBitwiseOrNode)1 ASTBitwiseXorNode (org.apache.commons.jexl2.parser.ASTBitwiseXorNode)1 ASTEQNode (org.apache.commons.jexl2.parser.ASTEQNode)1 ASTERNode (org.apache.commons.jexl2.parser.ASTERNode)1 ASTEmptyFunction (org.apache.commons.jexl2.parser.ASTEmptyFunction)1