    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements.  See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache License, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License.  You may obtain a copy of the License at
    008     *
    009     *      http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the License for the specific language governing permissions and
    015     * limitations under the License.
    016     */
    017
    018    package org.apache.commons.jexl2.parser;
    019
    020    /**
    021     * A class originally generated by JJTree:
    022     * /* JavaCCOptions:MULTI=true,NODE_USES_PARSER=true,VISITOR=true,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY= *\/
    023     * Worksaround issue https://javacc.dev.java.net/issues/show_bug.cgi?id=227
    024     * As soon as this issue if fixed and the maven plugin uses the correct version of Javacc, this
    025     * class can go away.
    026     *
    027     * The technical goal is to ensure every reference made in the parser was to a JexlNode; unfortunately,
    028     * as in javacc 4.1, it still uses a SimpleNode reference in the generated ParserVisitor.
    029     * Besides, there is no need to keep the parser around in the node.
    030     *
    031     * The functional goal is to a allow a <em>volatile</em> value in the node
    032     * so it can serve as a last evaluation cache even in multi-threaded executions.
    033     */
    034    public class SimpleNode implements Node {
    035      protected JexlNode parent;
    036      protected JexlNode[] children;
    037      protected int id;
    038      /** volatile value so it can be used as a last evaluation cache. */
    039      protected volatile Object value;
    040
    041      public SimpleNode(int i) {
    042        id = i;
    043      }
    044
    045      public SimpleNode(Parser p, int i) {
    046        this(i);
    047      }
    048
    049      public void jjtOpen() {
    050      }
    051
    052      public void jjtClose() {
    053      }
    054
    055      public void jjtSetParent(Node n) {
    056          parent = (JexlNode) n;
    057      }
    058
    059      public JexlNode jjtGetParent() {
    060          return parent;
    061      }
    062
    063      public void jjtAddChild(Node n, int i) {
    064        if (children == null) {
    065          children = new JexlNode[i + 1];
    066        } else if (i >= children.length) {
    067          JexlNode c[] = new JexlNode[i + 1];
    068          System.arraycopy(children, 0, c, 0, children.length);
    069          children = c;
    070        }
    071        children[i] = (JexlNode) n;
    072      }
    073
    074      public JexlNode jjtGetChild(int i) {
    075        return children[i];
    076      }
    077
    078      public int jjtGetNumChildren() {
    079        return (children == null) ? 0 : children.length;
    080      }
    081
    082      public void jjtSetValue(Object value) {
    083          this.value = value;
    084      }
    085
    086      public Object jjtGetValue() {
    087          return value;
    088      }
    089
    090      /** Accept the visitor. **/
    091      public Object jjtAccept(ParserVisitor visitor, Object data) {
    092        return visitor.visit(this, data);
    093      }
    094
    095      /** Accept the visitor. **/
    096      public Object childrenAccept(ParserVisitor visitor, Object data) {
    097        if (children != null) {
    098          for (int i = 0; i < children.length; ++i) {
    099            children[i].jjtAccept(visitor, data);
    100          }
    101        }
    102        return data;
    103      }
    104
    105      /* You can override these two methods in subclasses of SimpleNode to
    106         customize the way the JexlNode appears when the tree is dumped.  If
    107         your output uses more than one line you should override
    108         toString(String), otherwise overriding toString() is probably all
    109         you need to do. */
    110
    111      @Override
    112      public String toString() { return ParserTreeConstants.jjtNodeName[id]; }
    113      public String toString(String prefix) { return prefix + toString(); }
    114
    115      /* Override this method if you want to customize how the JexlNode dumps
    116         out its children. */
    117
    118      public void dump(String prefix) {
    119        System.out.println(toString(prefix));
    120        if (children != null) {
    121          for (int i = 0; i < children.length; ++i) {
    122      SimpleNode n = children[i];
    123      if (n != null) {
    124        n.dump(prefix + " ");
    125      }
    126          }
    127        }
    128      }
    129    }
    130
    131    /* JavaCC - OriginalChecksum=7dff880883d088a37c1e3197e4b455a0 (do not edit this line) */