protected void setupSource(JexlNode source) { this.jjtSetParent(source.jjtGetParent()); // create the assignment using the class name wrapped in an expression JexlNode refNode1 = JexlNodeFactory.createExpression(JexlNodeFactory.createAssignment(getClass().getSimpleName(), true)); // wrap the source in an expression JexlNode refNode2 = JexlNodeFactory.createExpression(source); // wrap the assignment and source in an AND node JexlNode andNode = JexlNodeFactory.createUnwrappedAndNode(Arrays.asList(refNode1, refNode2)); // wrap the and node with an expression (see JexlNodeFactory.createAndNode) ASTReferenceExpression refExpNode1 = new ASTReferenceExpression(ParserTreeConstants.JJTREFERENCEEXPRESSION); andNode.jjtSetParent(refExpNode1); refExpNode1.jjtAddChild(andNode, 0); // and make a child of this refExpNode1.jjtSetParent(this); this.jjtAddChild(refExpNode1, 0); }
/** * 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; }
/** * Creates a reference expression fro a child node * * @param child * @return */ public static JexlNode createExpression(JexlNode child) { ASTReference ref = new ASTReference(ParserTreeConstants.JJTREFERENCE); ASTReferenceExpression exp = new ASTReferenceExpression(ParserTreeConstants.JJTREFERENCEEXPRESSION); child.jjtSetParent(exp); exp.jjtAddChild(child, 0); exp.jjtSetParent(ref); ref.jjtAddChild(exp, 0); ref.jjtSetParent(child.jjtGetParent()); return ref; }
JexlNode child = childContainer.jjtGetChild(i); child.jjtSetParent(ref); exp.jjtAddChild(child, i); i++;
JexlNode newNode = (JexlNode) node.jjtGetChild(i).jjtAccept(this, null); newNode.jjtSetParent(expression); expression.jjtAddChild(newNode, expression.jjtGetNumChildren());