001    /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.3 */
002    package AST;
003    
004    import java.util.Collection;
005    import java.util.ArrayList;
006    import java.util.HashSet;
007    /**
008     * @ast node
009     * @production List : {@link ASTNode};
010    
011     */
012    public class List<T extends ASTNode> extends ASTNode<T> implements Cloneable {
013      /**
014       * @apilevel internal
015       */
016      public List<T> clone() throws CloneNotSupportedException {
017        List node = (List) super.clone();
018        node.in$Circle(false);
019        node.is$Final(false);
020        return node;
021      }
022      /**
023       * @apilevel internal
024       */
025      public List<T> copy() {
026        try {
027          List node = (List) clone();
028          node.parent = null;
029          if(children != null) {
030            node.children = (ASTNode[]) children.clone();
031          }
032          return node;
033        } catch (CloneNotSupportedException e) {
034          throw new Error("Error: clone not supported for " + getClass().getName());
035        }
036      }
037      /**
038       * Create a deep copy of the AST subtree at this node.
039       * The copy is dangling, i.e. has no parent.
040       * @return dangling copy of the subtree at this node
041       * @apilevel low-level
042       */
043      public List<T> fullCopy() {
044        List tree = (List) copy();
045        if (children != null) {
046          for (int i = 0; i < children.length; ++i) {
047            ASTNode child = (ASTNode) children[i];
048            if(child != null) {
049              child = child.fullCopy();
050              tree.setChild(child, i);
051            }
052          }
053        }
054        return tree;
055      }
056      /**
057       */
058      public List() {
059        super();
060      }
061      /**
062       * Initializes the child array to the correct size.
063       * Initializes List and Opt nta children.
064       * @apilevel internal
065       * @ast method
066       */
067      public void init$Children() {
068      }
069      /**
070       */
071      public List(T... initialChildren) {
072        children = new ASTNode[initialChildren.length];
073        for (int i = 0; i < children.length; ++i) {
074          addChild(initialChildren[i]);
075        }
076      }
077      /**
078       */
079      private boolean list$touched = true;
080      /**
081       */
082      public List<T> add(T node) {
083        addChild(node);
084        return this;
085      }
086      /**
087       */
088      public List<T> addAll(java.util.Collection<? extends T> c) {
089        for (T node : c) {
090          addChild(node);
091        }
092        return this;
093      }
094      /**
095       */
096      public void insertChild(ASTNode node, int i) {
097    
098        list$touched = true;
099    
100        super.insertChild(node, i);
101      }
102      /**
103       */
104      public void addChild(T node) {
105    
106        list$touched = true;
107    
108        super.addChild(node);
109      }
110      /**
111       * @apilevel low-level
112       */
113      public void removeChild(int i) {
114    
115        list$touched = true;
116    
117        super.removeChild(i);
118      }
119      /**
120       */
121      public int getNumChild() {
122    
123        if (list$touched) {
124          for (int i = 0; i < getNumChildNoTransform(); i++) {
125            getChild(i);
126          }
127          list$touched = false;
128        }
129    
130        return getNumChildNoTransform();
131      }
132      /**
133       * @apilevel internal
134       */
135      public boolean mayHaveRewrite() {
136        return true;
137      }
138      /**
139       * @apilevel low-level
140       */
141      public void flushCache() {
142        super.flushCache();
143      }
144      /**
145       * @apilevel internal
146       */
147      public void flushCollectionCache() {
148        super.flushCollectionCache();
149      }
150      /**
151       * @apilevel internal
152       */
153      public ASTNode rewriteTo() {    if(list$touched) {
154          for(int i = 0 ; i < getNumChildNoTransform(); i++) {
155            getChild(i);
156          }
157          list$touched = false;
158          return this;
159        }    return super.rewriteTo();
160      }}