use of org.apache.commons.jexl2.parser.ASTIdentifier in project datawave by NationalSecurityAgency.
the class JexlASTHelper method getIdentifierOpLiteral.
public static IdentifierOpLiteral getIdentifierOpLiteral(JexlNode node) {
// ensure we have the pattern we expect here
if (node.jjtGetNumChildren() == 2) {
JexlNode child1 = JexlASTHelper.dereference(node.jjtGetChild(0));
JexlNode child2 = JexlASTHelper.dereference(node.jjtGetChild(1));
if (child1 instanceof ASTIdentifier && isLiteral(child2)) {
return new IdentifierOpLiteral((ASTIdentifier) child1, node, child2);
}
if (child2 instanceof ASTIdentifier && isLiteral(child1)) {
// this should no longer happen after the fix to groom the query by reordering binary expressions that
// have the literal on the left side
// if this is a range op, i must reverse the logic:
node = (JexlNode) node.jjtAccept(new InvertNodeVisitor(), null);
return new IdentifierOpLiteral((ASTIdentifier) child2, node, child1);
}
}
return null;
}
use of org.apache.commons.jexl2.parser.ASTIdentifier 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;
}
use of org.apache.commons.jexl2.parser.ASTIdentifier 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.jexl2.parser.ASTIdentifier 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.jexl2.parser.ASTIdentifier in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method buildUntypedNewNode.
/**
* Assign the field name and value to the given newNode
*
* @param newNode
* @param fieldName
* @param fieldValue
* @return
*/
protected static JexlNode buildUntypedNewNode(JexlNode newNode, ASTIdentifier fieldName, String fieldValue) {
ASTStringLiteral literal = new ASTStringLiteral(ParserTreeConstants.JJTSTRINGLITERAL);
literal.image = fieldValue;
return buildUntypedNewNode(newNode, fieldName, literal);
}
Aggregations