protected static JexlNode buildUntypedDblLiteralNode(JexlNode newNode, JexlNode literal1, JexlNode literal2) { newNode.jjtAddChild(literal1, 0); newNode.jjtAddChild(literal2, 1); literal1.jjtSetParent(newNode); literal2.jjtSetParent(newNode); return newNode; }
private void adopt(JexlNode parent, JexlNode child, int i) { if (child != null && parent != null) { child.jjtSetParent(parent); parent.jjtAddChild(child, i); } }
/** * Add the children JexlNodes to the parent JexlNode, correctly setting parent pointers, parenthesis, and reference nodes. * * @param parent * @param children * @return */ public static JexlNode setChildren(JexlNode parent, Iterable<? extends JexlNode> children) { int i = 0; JexlNodes.ensureCapacity(parent, Iterables.size(children)); // hopefully // we got // passed a // collection... for (JexlNode child : children) { parent.jjtAddChild(child, i); child.jjtSetParent(parent); i++; } return parent; }
/** * @param delayedPredicates * @return */ protected JexlNode reverseDepth(JexlNode parentNode, List<JexlNode> delayedPredicates) { JexlNode returnNode = ASTDelayedPredicate.create(parentNode); JexlNode newAnd = new ASTAndNode(ParserTreeConstants.JJTANDNODE); int i = 0; for (JexlNode delayedNode : delayedPredicates) { newAnd.jjtAddChild(delayedNode.jjtGetChild(0), i); i++; } newAnd.jjtSetParent(returnNode); returnNode.jjtAddChild(newAnd, 0); return returnNode; }
/** * 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; }
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; }
protected JexlNode flattenTree(JexlNode currentNode, JexlNode newNode, Object data) { if (!currentNode.getClass().equals(newNode.getClass())) { log.warn("newNode is not the same type as currentNode ... something has probably gone horribly wrong"); } for (int i = 0; i < currentNode.jjtGetNumChildren(); i++) { JexlNode node = (JexlNode) currentNode.jjtGetChild(i).jjtAccept(this, null); JexlNode dereferenced = JexlASTHelper.dereference(node); if (acceptableNodesToCombine(currentNode, dereferenced)) { flattenTree(dereferenced, newNode, data); } else { newNode.jjtAddChild(node, newNode.jjtGetNumChildren()); node.jjtSetParent(newNode); } } return newNode; }
private JexlNode reparent(JexlNode in, JexlNode out) { int j = 0; for (int i = in.jjtGetNumChildren() - 1; i >= 0; i--) { JexlNode kid = in.jjtGetChild(i); kid = (JexlNode) kid.jjtAccept(this, null); out.jjtAddChild(kid, j++); kid.jjtSetParent(out); } return out; }
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; }
current.jjtAddChild(bridgeTo, 0);
/** * Given the provide newNode, add the fieldName (as an identifier) and the literal * * @param newNode * @param identifier * @param literal * @return */ protected static JexlNode buildUntypedNewNode(JexlNode newNode, ASTIdentifier identifier, JexlNode literal) { 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(identifierReference, 0); newNode.jjtAddChild(literalReference, 1); identifierReference.jjtSetParent(newNode); literalReference.jjtSetParent(newNode); return newNode; }
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) { original.jjtAddChild(literalReference, 1); // replace the original reference/literal (on left) with new reference/literal } if (original.jjtGetChild(1) instanceof ASTReference && original.jjtGetChild(1).jjtGetChild(0) instanceof ASTIdentifier) { original.jjtAddChild(literalReference, 0); // replace the original reference/literal (on right) with new reference/literal } literalReference.jjtSetParent(original); return original; }
newNode.jjtAddChild(prunedNode, newNode.jjtGetNumChildren()); prunedNode.jjtSetParent(newNode); prunedNode = nodes.second(); } else { newNode.jjtAddChild(child, newNode.jjtGetNumChildren()); child.jjtSetParent(newNode);
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) { original.jjtAddChild(literalReference, 1); // replace the original reference/literal (on left) with new reference/literal } if (original.jjtGetChild(1) instanceof ASTReference && original.jjtGetChild(1).jjtGetChild(0) instanceof ASTIdentifier) { original.jjtAddChild(literalReference, 0); // replace the original reference/literal (on right) with new reference/literal } literalReference.jjtSetParent(original); return original; }
public static JexlNode copyInto(JexlNode root, JexlNode target) { RebuildingVisitor visitor = new RebuildingVisitor(); JexlNode copyRoot = (JexlNode) root.jjtAccept(visitor, null); if (null != copyRoot) { target.jjtSetParent(copyRoot.jjtGetParent()); for (int i = 0; i < copyRoot.jjtGetNumChildren(); i++) { JexlNode child = copyRoot.jjtGetChild(i); target.jjtAddChild(child, i); child.jjtSetParent(target); } } return target; }
@Override public Object visit(ASTAndNode node, Object data) { List<JexlNode> leaves = new ArrayList<>(); Map<LiteralRange<?>,List<JexlNode>> ranges = JexlASTHelper.getBoundedRanges(node, this.dataTypeFilter, this.helper, leaves, false); JexlNode andNode = JexlNodes.newInstanceOfType(node); andNode.image = node.image; andNode.jjtSetParent(node.jjtGetParent()); // We have a bounded range completely inside of an AND/OR if (!ranges.isEmpty()) { andNode = delayIndexBoundedRange(ranges, leaves, node, andNode, data); } else { // We have no bounded range to replace, just proceed as normal JexlNodes.ensureCapacity(andNode, node.jjtGetNumChildren()); for (int i = 0; i < node.jjtGetNumChildren(); i++) { JexlNode newChild = (JexlNode) node.jjtGetChild(i).jjtAccept(this, data); andNode.jjtAddChild(newChild, i); newChild.jjtSetParent(andNode); } } return andNode; }
@Override public Object visit(ASTAndNode node, Object data) { List<JexlNode> leaves = new ArrayList<>(); Map<LiteralRange<?>,List<JexlNode>> ranges = JexlASTHelper.getBoundedRangesIndexAgnostic(node, leaves, false); JexlNode andNode = JexlNodes.newInstanceOfType(node); andNode.image = node.image; andNode.jjtSetParent(node.jjtGetParent()); // We have a bounded range completely inside of an AND/OR if (!ranges.isEmpty()) { andNode = coalesceBoundedRanges(ranges, leaves, node, andNode, data); } else { // We have no bounded range to replace, just proceed as normal JexlNodes.ensureCapacity(andNode, node.jjtGetNumChildren()); for (int i = 0; i < node.jjtGetNumChildren(); i++) { JexlNode newChild = (JexlNode) node.jjtGetChild(i).jjtAccept(this, data); andNode.jjtAddChild(newChild, i); newChild.jjtSetParent(andNode); } } return andNode; }
@Override public Object visit(ASTAndNode node, Object data) { List<JexlNode> leaves = new ArrayList<>(); Map<LiteralRange<?>,List<JexlNode>> ranges = JexlASTHelper.getBoundedRanges(node, this.config.getDatatypeFilter(), this.helper, leaves, false); JexlNode andNode = JexlNodes.newInstanceOfType(node); andNode.image = node.image; andNode.jjtSetParent(node.jjtGetParent()); // We have a bounded range completely inside of an AND/OR if (!ranges.isEmpty()) { andNode = expandIndexBoundedRange(ranges, leaves, node, andNode, data); } else { // We have no bounded range to replace, just proceed as normal JexlNodes.ensureCapacity(andNode, node.jjtGetNumChildren()); for (int i = 0; i < node.jjtGetNumChildren(); i++) { JexlNode newChild = (JexlNode) node.jjtGetChild(i).jjtAccept(this, data); andNode.jjtAddChild(newChild, i); newChild.jjtSetParent(andNode); } } return andNode; }
newWrapper.jjtAddChild(ref, 0);
queryTree.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).jjtAddChild(newOr, 0); newOr.jjtSetParent(queryTree.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0));