/** {@inheritDoc} */ public DebugInfo debugInfo() { JexlNode node = this; while (node != null) { if (node.value instanceof DebugInfo) { return (DebugInfo) node.value; } node = node.jjtGetParent(); } return null; }
public IndexLookupCallable(IndexLookup lookup, JexlNode currNode, boolean positive, boolean enforceTimeout, boolean ignoreComposites) { this.lookup = lookup; this.node = currNode; this.positive = positive; this.enforceTimeout = enforceTimeout; this.ignoreComposites = ignoreComposites; parentNode = currNode.jjtGetParent(); }
/** * This is the opposite of dereference in that this will climb back up reference and reference expression nodes that only contain one child. * * @param node * @return the parent reference/referenceexpression or this node */ public static JexlNode rereference(JexlNode node) { while (node.jjtGetParent() != null && node.jjtGetParent().jjtGetNumChildren() == 1 && (node.jjtGetParent() instanceof ASTReference || node.jjtGetParent() instanceof ASTReferenceExpression)) { node = node.jjtGetParent(); } return node; }
public static boolean isWithinOr(JexlNode node) { if (null != node && null != node.jjtGetParent()) { JexlNode parent = node.jjtGetParent(); if (parent instanceof ASTOrNode) { return true; } return isWithinOr(parent); } return false; }
/** * Determines if parent is a type * * @param currentNode * @param clazz * @return */ public static boolean isParent(final JexlNode currentNode, final Class<? extends JexlNode> clazz) { JexlNode parentNode = currentNode.jjtGetParent(); return parentNode.getClass().isAssignableFrom(clazz); }
public static boolean isWithinAnd(JexlNode node) { while (null != node && null != node.jjtGetParent()) { JexlNode parent = node.jjtGetParent(); if (parent instanceof ASTAndNode) { return true; } return isWithinAnd(parent); } return false; }
public static JexlNode promote(JexlNode parent, JexlNode child) { JexlNode grandpa = parent.jjtGetParent(); if (grandpa == null) { child.parent = null; return child; } else { return swap(parent.jjtGetParent(), parent, child); } }
public static boolean isWithinNot(JexlNode node) { while (null != node && null != node.jjtGetParent()) { JexlNode parent = node.jjtGetParent(); if (parent instanceof ASTNotNode) { return true; } return isWithinNot(parent); } return false; }
private boolean isWithinBoundedRange(JexlNode node) { if (node.jjtGetParent() instanceof ASTAndNode) { List<JexlNode> otherNodes = new ArrayList<>(); Map<LiteralRange<?>,List<JexlNode>> ranges = JexlASTHelper.getBoundedRangesIndexAgnostic((ASTAndNode) (node.jjtGetParent()), otherNodes, false); if (ranges.size() == 1 && otherNodes.isEmpty()) { return true; } } return false; }
private boolean isWithinBoundedRange(JexlNode node) { if (node.jjtGetParent() instanceof ASTAndNode) { List<JexlNode> otherNodes = new ArrayList<>(); Map<LiteralRange<?>,List<JexlNode>> ranges = JexlASTHelper.getBoundedRangesIndexAgnostic((ASTAndNode) (node.jjtGetParent()), otherNodes, false); if (ranges.size() == 1 && otherNodes.isEmpty()) { return true; } } return false; }
public static <T extends JexlNode> T swapLiterals(T operand, ASTReference literal) { JexlNode oldLiteral = findLiteral(operand); // we need the direct child of this operand (should be at most one level too deep) while (oldLiteral.jjtGetParent() != operand) { oldLiteral = oldLiteral.jjtGetParent(); } return JexlNodes.swap(operand, oldLiteral, literal); }
private static boolean isNodeNegated(JexlNode node) { JexlNode parent = node.jjtGetParent(); if (parent == null) { return false; } else { int numNegations = numNegations(parent); if (numNegations % 2 == 0) { return false; } else { return true; } } }
/** * @param node * @return */ public static ASTEvaluationOnly create(JexlNode node) { JexlNode parent = node.jjtGetParent(); ASTEvaluationOnly expr = new ASTEvaluationOnly(node); if (parent != null) { JexlNodes.replaceChild(parent, node, expr); } return expr; }
/** * @param node * @return */ public static IndexHoleMarkerJexlNode create(JexlNode node) { JexlNode parent = node.jjtGetParent(); IndexHoleMarkerJexlNode expr = new IndexHoleMarkerJexlNode(node); if (parent != null) { JexlNodes.replaceChild(parent, node, expr); } return expr; }
private static int numNegations(JexlNode node) { JexlNode parent = node.jjtGetParent(); if (parent == null) { return 0; } else if (parent instanceof ASTNotNode) { return 1 + numNegations(parent); } else { return numNegations(parent); } }
/** * @param node * @return */ public static ASTDelayedPredicate create(JexlNode node) { JexlNode parent = node.jjtGetParent(); ASTDelayedPredicate expr = new ASTDelayedPredicate(node); if (parent != null) { JexlNodes.replaceChild(parent, node, expr); } return expr; }
private JexlNode pushFunctionIntoExceededValueRange(Collection<JexlNode> functions, JexlNode range) { JexlNode source = ExceededValueThresholdMarkerJexlNode.getExceededValueThresholdSource(range); source = JexlASTHelper.dereference(source); JexlNode parent = source.jjtGetParent(); ASTAndNode andNode = new ASTAndNode(ParserTreeConstants.JJTANDNODE); JexlNode[] allChildren = new JexlNode[functions.size() + 1]; int i = 0; allChildren[i++] = source; for (JexlNode function : functions) { allChildren[i++] = function; } andNode = children(andNode, allChildren); children(parent, andNode); return range; }
private JexlNode pushFunctionIntoExceededValueRange(JexlNode filter, JexlNode range) { JexlNode source = ExceededValueThresholdMarkerJexlNode.getExceededValueThresholdSource(range); source = JexlASTHelper.dereference(source); JexlNode parent = source.jjtGetParent(); ASTAndNode andNode = new ASTAndNode(ParserTreeConstants.JJTANDNODE); andNode = children(andNode, source, filter); children(parent, andNode); return range; }
@Override public Object visit(ASTStringLiteral node, Object data) { // strings are always wrapped in a reference node, so the op is the gparent JexlNode op = node.jjtGetParent().jjtGetParent(); if (op instanceof ASTEQNode) { JexlNode field = JexlNodes.otherChild(op, node.jjtGetParent()).jjtGetChild(0); if (log.isTraceEnabled()) { log.trace("Found field " + JexlASTHelper.deconstructIdentifier(field.image) + "==" + node.getLiteral()); } values.addLiteral(node.getLiteral().toString(), JexlASTHelper.deconstructIdentifier(field.image)); } else if (op instanceof ASTERNode) { JexlNode field = JexlNodes.otherChild(op, node.jjtGetParent()).jjtGetChild(0); values.addPattern(node.getLiteral(), JexlASTHelper.deconstructIdentifier(field.image)); } return null; }
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; }