001    /* This file was generated with JastAdd2 (http://jastadd.org) version R20130213 */
002    package AST;
003    
004    import java.util.HashSet;
005    import java.io.File;
006    import java.util.*;
007    import beaver.*;
008    import java.util.ArrayList;
009    import java.util.zip.*;
010    import java.io.*;
011    import java.io.FileNotFoundException;
012    import java.util.Collection;
013    /**
014     * @production List : {@link ASTNode};
015     * @ast node
016     * 
017     */
018    public class List<T extends ASTNode> extends ASTNode<T> implements Cloneable {
019      /**
020       * @apilevel low-level
021       */
022      public void flushCache() {
023      }
024      /**
025       * @apilevel internal
026       */
027      public void flushCollectionCache() {
028      }
029      /**
030       * @apilevel internal
031       */
032      @SuppressWarnings({"unchecked", "cast"})
033      public List<T> clone() throws CloneNotSupportedException {
034        List node = (List)super.clone();
035        node.in$Circle(false);
036        node.is$Final(false);
037        return node;
038      }
039    /**
040     * @apilevel internal
041     */
042      @SuppressWarnings({"unchecked", "cast"})
043    public List<T> copy() {
044      
045      try {
046        List node = (List) clone();
047        node.parent = null;
048        if(children != null)
049          node.children = (ASTNode[]) children.clone();
050        
051        return node;
052      } catch (CloneNotSupportedException e) {
053        throw new Error("Error: clone not supported for " + getClass().getName());
054      }
055      
056    }/**
057     * Create a deep copy of the AST subtree at this node.
058     * The copy is dangling, i.e. has no parent.
059     * @return dangling copy of the subtree at this node
060     * @apilevel low-level
061     */
062      @SuppressWarnings({"unchecked", "cast"})
063    public List<T> fullCopy() {
064      
065      List tree = (List) copy();
066      if (children != null) {
067        for (int i = 0; i < children.length; ++i) {
068          
069          ASTNode child = (ASTNode) children[i];
070          if(child != null) {
071            child = child.fullCopy();
072            tree.setChild(child, i);
073          }
074        }
075      }
076      return tree;
077      
078    }  /**
079       * @ast method 
080       * @aspect LookupParTypeDecl
081       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.jrag:977
082       */
083      public List substitute(Parameterization parTypeDecl) {
084        List list = new List();
085        for(int i = 0; i < getNumChild(); i++) {
086          ASTNode node = getChild(i);
087          if(node instanceof Access) {
088            Access a = (Access)node;
089            list.add(a.type().substitute(parTypeDecl));
090          }
091          else if(node instanceof VariableArityParameterDeclaration) {
092            VariableArityParameterDeclaration p = (VariableArityParameterDeclaration)node;
093            list.add(
094              new VariableArityParameterDeclarationSubstituted(
095                (Modifiers)p.getModifiers().fullCopy(),
096                // use the type acces since VariableArity adds to the dimension
097                p.getTypeAccess().type().substituteParameterType(parTypeDecl),
098                p.getID(),
099                p
100              )
101            );
102          }
103          else if(node instanceof ParameterDeclaration) {
104            ParameterDeclaration p = (ParameterDeclaration)node;
105            list.add(
106              new ParameterDeclarationSubstituted(
107                (Modifiers)p.getModifiers().fullCopy(),
108                p.type().substituteParameterType(parTypeDecl),
109                p.getID(),
110                p
111              )
112            );
113          }
114          else {
115            throw new Error("Can only substitute lists of access nodes but node number " + i + " is of type " + node.getClass().getName());
116          }
117        }
118        return list;
119      }
120      /**
121       * @ast method 
122       * 
123       */
124      public List() {
125        super();
126    
127    
128      }
129      /**
130       * Initializes the child array to the correct size.
131       * Initializes List and Opt nta children.
132       * @apilevel internal
133       * @ast method
134       * @ast method 
135       * 
136       */
137      public void init$Children() {
138      }
139      /**
140       * @ast method 
141       * 
142       */
143      public List<T> add(T node) {
144        addChild(node);
145        return this;
146      }
147      /**
148       * @ast method 
149       * 
150       */
151      public void insertChild(ASTNode node, int i) {
152        list$touched = true;
153        super.insertChild(node, i);
154      }
155      /**
156       * @ast method 
157       * 
158       */
159      public void addChild(T node) {
160        list$touched = true;
161        super.addChild(node);
162      }
163      /**
164       * @apilevel low-level
165       * @ast method 
166       * 
167       */
168      public void removeChild(int i) {
169        list$touched = true;
170        super.removeChild(i);
171      }
172      /**
173       * @ast method 
174       * 
175       */
176      public int getNumChild() {
177        if(list$touched) {
178          for(int i = 0; i < getNumChildNoTransform(); i++)
179            getChild(i);
180            list$touched = false;
181          }
182          return getNumChildNoTransform();
183      }
184      /**
185       * @ast method 
186       * 
187       */
188      
189      private boolean list$touched = true;
190      /**
191       * @apilevel internal
192       * @ast method 
193       * 
194       */
195      public boolean mayHaveRewrite() {
196        return true;
197      }
198      /**
199       * @attribute syn
200       * @aspect ImplicitConstructor
201       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/LookupConstructor.jrag:158
202       */
203      public boolean requiresDefaultConstructor() {
204        ASTNode$State state = state();
205        try {
206        if(getParent() instanceof ClassDecl) {
207          ClassDecl c = (ClassDecl)getParent();
208          return c.noConstructor() && c.getBodyDeclListNoTransform() == this && !(c instanceof AnonymousDecl);
209        }
210        return false;
211      }
212        finally {
213        }
214      }
215      /**
216       * @attribute syn
217       * @aspect CreateBCode
218       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:946
219       */
220      public boolean definesLabel() {
221        ASTNode$State state = state();
222        try {  return getParent().definesLabel();  }
223        finally {
224        }
225      }
226      /**
227       * @apilevel internal
228       */
229      public ASTNode rewriteTo() {
230        if(list$touched) {
231          for(int i = 0 ; i < getNumChildNoTransform(); i++)
232            getChild(i);
233          list$touched = false;
234          return this;
235        }
236        // Declared in /home/jesper/svn/JastAddJ/Java1.4Frontend/LookupConstructor.jrag at line 186
237        if(requiresDefaultConstructor()) {
238          state().duringImplicitConstructor++;
239          ASTNode result = rewriteRule0();
240          state().duringImplicitConstructor--;
241          return result;
242        }
243    
244        return super.rewriteTo();
245      }
246      /**
247       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/LookupConstructor.jrag:186
248       * @apilevel internal
249       */  private List rewriteRule0() {
250    {
251          ClassDecl c = (ClassDecl)getParent();
252          Modifiers m = new Modifiers();
253          if(c.isPublic()) m.addModifier(new Modifier("public"));
254          else if(c.isProtected()) m.addModifier(new Modifier("protected"));
255          else if(c.isPrivate()) m.addModifier(new Modifier("private"));
256          ConstructorDecl constructor = new ConstructorDecl(
257                m,
258                c.name(),
259                new List(),
260                new List(),
261                new Opt(),
262                new Block()
263          );
264          constructor.setDefaultConstructor();
265          c.addBodyDecl(constructor);
266          return this;
267        }  }
268    }