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    /**
015     * @production VarDeclStmt : {@link Stmt} ::= <span class="component">{@link Modifiers}</span> <span class="component">TypeAccess:{@link Access}</span> <span class="component">{@link VariableDecl}*</span>;
016     * @ast node
017     * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:82
018     */
019    public class VarDeclStmt extends Stmt implements Cloneable {
020      /**
021       * @apilevel low-level
022       */
023      public void flushCache() {
024      }
025      /**
026       * @apilevel internal
027       */
028      public void flushCollectionCache() {
029      }
030      /**
031       * @apilevel internal
032       */
033      @SuppressWarnings({"unchecked", "cast"})
034      public VarDeclStmt clone() throws CloneNotSupportedException {
035        VarDeclStmt node = (VarDeclStmt)super.clone();
036        node.canCompleteNormally_computed = false;
037        node.in$Circle(false);
038        node.is$Final(false);
039        return node;
040      }
041    /**
042     * @apilevel internal
043     */
044      @SuppressWarnings({"unchecked", "cast"})
045    public VarDeclStmt copy() {
046      
047      try {
048        VarDeclStmt node = (VarDeclStmt) clone();
049        node.parent = null;
050        if(children != null)
051          node.children = (ASTNode[]) children.clone();
052        
053        return node;
054      } catch (CloneNotSupportedException e) {
055        throw new Error("Error: clone not supported for " + getClass().getName());
056      }
057      
058    }/**
059     * Create a deep copy of the AST subtree at this node.
060     * The copy is dangling, i.e. has no parent.
061     * @return dangling copy of the subtree at this node
062     * @apilevel low-level
063     */
064      @SuppressWarnings({"unchecked", "cast"})
065    public VarDeclStmt fullCopy() {
066      
067      VarDeclStmt tree = (VarDeclStmt) copy();
068      if (children != null) {
069        for (int i = 0; i < children.length; ++i) {
070          
071          ASTNode child = (ASTNode) children[i];
072          if(child != null) {
073            child = child.fullCopy();
074            tree.setChild(child, i);
075          }
076        }
077      }
078      return tree;
079      
080    }  /**
081       * @ast method 
082       * @aspect VariableDeclarationTransformation
083       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag:163
084       */
085      private List createVariableDeclarationList() {
086        List varList = new List();
087        for(int j = 0; j < getNumVariableDecl(); j++) {
088          VariableDeclaration v =
089            getVariableDecl(j).createVariableDeclarationFrom(
090              (Modifiers)getModifiers().fullCopy(),
091              (Access)getTypeAccess().fullCopy()
092            );
093          if(j == 0)
094            v.setStart(start);
095          else {
096            v.getModifiersNoTransform().clearLocations();
097            v.getTypeAccessNoTransform().clearLocations();
098          }
099          varList.add(v);
100        }
101        return varList;
102      }
103      /**
104       * @ast method 
105       * 
106       */
107      public VarDeclStmt() {
108        super();
109    
110    
111      }
112      /**
113       * Initializes the child array to the correct size.
114       * Initializes List and Opt nta children.
115       * @apilevel internal
116       * @ast method
117       * @ast method 
118       * 
119       */
120      public void init$Children() {
121        children = new ASTNode[3];
122        setChild(new List(), 2);
123      }
124      /**
125       * @ast method 
126       * 
127       */
128      public VarDeclStmt(Modifiers p0, Access p1, List<VariableDecl> p2) {
129        setChild(p0, 0);
130        setChild(p1, 1);
131        setChild(p2, 2);
132      }
133      /**
134       * @apilevel low-level
135       * @ast method 
136       * 
137       */
138      protected int numChildren() {
139        return 3;
140      }
141      /**
142       * @apilevel internal
143       * @ast method 
144       * 
145       */
146      public boolean mayHaveRewrite() {
147        return true;
148      }
149      /**
150       * Replaces the Modifiers child.
151       * @param node The new node to replace the Modifiers child.
152       * @apilevel high-level
153       * @ast method 
154       * 
155       */
156      public void setModifiers(Modifiers node) {
157        setChild(node, 0);
158      }
159      /**
160       * Retrieves the Modifiers child.
161       * @return The current node used as the Modifiers child.
162       * @apilevel high-level
163       * @ast method 
164       * 
165       */
166      public Modifiers getModifiers() {
167        return (Modifiers)getChild(0);
168      }
169      /**
170       * Retrieves the Modifiers child.
171       * <p><em>This method does not invoke AST transformations.</em></p>
172       * @return The current node used as the Modifiers child.
173       * @apilevel low-level
174       * @ast method 
175       * 
176       */
177      public Modifiers getModifiersNoTransform() {
178        return (Modifiers)getChildNoTransform(0);
179      }
180      /**
181       * Replaces the TypeAccess child.
182       * @param node The new node to replace the TypeAccess child.
183       * @apilevel high-level
184       * @ast method 
185       * 
186       */
187      public void setTypeAccess(Access node) {
188        setChild(node, 1);
189      }
190      /**
191       * Retrieves the TypeAccess child.
192       * @return The current node used as the TypeAccess child.
193       * @apilevel high-level
194       * @ast method 
195       * 
196       */
197      public Access getTypeAccess() {
198        return (Access)getChild(1);
199      }
200      /**
201       * Retrieves the TypeAccess child.
202       * <p><em>This method does not invoke AST transformations.</em></p>
203       * @return The current node used as the TypeAccess child.
204       * @apilevel low-level
205       * @ast method 
206       * 
207       */
208      public Access getTypeAccessNoTransform() {
209        return (Access)getChildNoTransform(1);
210      }
211      /**
212       * Replaces the VariableDecl list.
213       * @param list The new list node to be used as the VariableDecl list.
214       * @apilevel high-level
215       * @ast method 
216       * 
217       */
218      public void setVariableDeclList(List<VariableDecl> list) {
219        setChild(list, 2);
220      }
221      /**
222       * Retrieves the number of children in the VariableDecl list.
223       * @return Number of children in the VariableDecl list.
224       * @apilevel high-level
225       * @ast method 
226       * 
227       */
228      public int getNumVariableDecl() {
229        return getVariableDeclList().getNumChild();
230      }
231      /**
232       * Retrieves the number of children in the VariableDecl list.
233       * Calling this method will not trigger rewrites..
234       * @return Number of children in the VariableDecl list.
235       * @apilevel low-level
236       * @ast method 
237       * 
238       */
239      public int getNumVariableDeclNoTransform() {
240        return getVariableDeclListNoTransform().getNumChildNoTransform();
241      }
242      /**
243       * Retrieves the element at index {@code i} in the VariableDecl list..
244       * @param i Index of the element to return.
245       * @return The element at position {@code i} in the VariableDecl list.
246       * @apilevel high-level
247       * @ast method 
248       * 
249       */
250      @SuppressWarnings({"unchecked", "cast"})
251      public VariableDecl getVariableDecl(int i) {
252        return (VariableDecl)getVariableDeclList().getChild(i);
253      }
254      /**
255       * Append an element to the VariableDecl list.
256       * @param node The element to append to the VariableDecl list.
257       * @apilevel high-level
258       * @ast method 
259       * 
260       */
261      public void addVariableDecl(VariableDecl node) {
262        List<VariableDecl> list = (parent == null || state == null) ? getVariableDeclListNoTransform() : getVariableDeclList();
263        list.addChild(node);
264      }
265      /**
266       * @apilevel low-level
267       * @ast method 
268       * 
269       */
270      public void addVariableDeclNoTransform(VariableDecl node) {
271        List<VariableDecl> list = getVariableDeclListNoTransform();
272        list.addChild(node);
273      }
274      /**
275       * Replaces the VariableDecl list element at index {@code i} with the new node {@code node}.
276       * @param node The new node to replace the old list element.
277       * @param i The list index of the node to be replaced.
278       * @apilevel high-level
279       * @ast method 
280       * 
281       */
282      public void setVariableDecl(VariableDecl node, int i) {
283        List<VariableDecl> list = getVariableDeclList();
284        list.setChild(node, i);
285      }
286      /**
287       * Retrieves the VariableDecl list.
288       * @return The node representing the VariableDecl list.
289       * @apilevel high-level
290       * @ast method 
291       * 
292       */
293      public List<VariableDecl> getVariableDecls() {
294        return getVariableDeclList();
295      }
296      /**
297       * Retrieves the VariableDecl list.
298       * <p><em>This method does not invoke AST transformations.</em></p>
299       * @return The node representing the VariableDecl list.
300       * @apilevel low-level
301       * @ast method 
302       * 
303       */
304      public List<VariableDecl> getVariableDeclsNoTransform() {
305        return getVariableDeclListNoTransform();
306      }
307      /**
308       * Retrieves the VariableDecl list.
309       * @return The node representing the VariableDecl list.
310       * @apilevel high-level
311       * @ast method 
312       * 
313       */
314      @SuppressWarnings({"unchecked", "cast"})
315      public List<VariableDecl> getVariableDeclList() {
316        List<VariableDecl> list = (List<VariableDecl>)getChild(2);
317        list.getNumChild();
318        return list;
319      }
320      /**
321       * Retrieves the VariableDecl list.
322       * <p><em>This method does not invoke AST transformations.</em></p>
323       * @return The node representing the VariableDecl list.
324       * @apilevel low-level
325       * @ast method 
326       * 
327       */
328      @SuppressWarnings({"unchecked", "cast"})
329      public List<VariableDecl> getVariableDeclListNoTransform() {
330        return (List<VariableDecl>)getChildNoTransform(2);
331      }
332      /**
333       * @apilevel internal
334       */
335      protected boolean canCompleteNormally_computed = false;
336      /**
337       * @apilevel internal
338       */
339      protected boolean canCompleteNormally_value;
340      /**
341       * @attribute syn
342       * @aspect UnreachableStatements
343       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/UnreachableStatements.jrag:42
344       */
345      @SuppressWarnings({"unchecked", "cast"})
346      public boolean canCompleteNormally() {
347        if(canCompleteNormally_computed) {
348          return canCompleteNormally_value;
349        }
350          ASTNode$State state = state();
351      int num = state.boundariesCrossed;
352      boolean isFinal = this.is$Final();
353        canCompleteNormally_value = canCompleteNormally_compute();
354      if(isFinal && num == state().boundariesCrossed){ canCompleteNormally_computed = true; }
355            return canCompleteNormally_value;
356      }
357      /**
358       * @apilevel internal
359       */
360      private boolean canCompleteNormally_compute() {  return reachable();  }
361      /**
362       * @attribute syn
363       * @aspect PreciseRethrow
364       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/PreciseRethrow.jrag:55
365       */
366      public boolean modifiedInScope(Variable var) {
367        ASTNode$State state = state();
368        try {  return false;  }
369        finally {
370        }
371      }
372      /**
373       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/SyntacticClassification.jrag:84
374       * @apilevel internal
375       */
376      public NameType Define_NameType_nameType(ASTNode caller, ASTNode child) {
377        if(caller == getTypeAccessNoTransform()) {
378          return NameType.TYPE_NAME;
379        }
380        else {      return getParent().Define_NameType_nameType(this, caller);
381        }
382      }
383      /**
384       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:258
385       * @apilevel internal
386       */
387      public TypeDecl Define_TypeDecl_declType(ASTNode caller, ASTNode child) {
388        if(caller == getVariableDeclListNoTransform())  {
389        int childIndex = caller.getIndexOfChild(child);
390        return null;
391      }
392        else {      return getParent().Define_TypeDecl_declType(this, caller);
393        }
394      }
395      /**
396       * @apilevel internal
397       */
398      public ASTNode rewriteTo() {
399        // Declared in /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag at line 144
400        if(getNumVariableDecl() == 1) {
401          state().duringVariableDeclarationTransformation++;
402          ASTNode result = rewriteRule0();
403          state().duringVariableDeclarationTransformation--;
404          return result;
405        }
406    
407        // Declared in /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag at line 155
408        if(getParent().getParent() instanceof Block && 
409          ((Block)getParent().getParent()).getStmtListNoTransform() == getParent() && getNumVariableDecl() > 1) {
410        state().duringVariableDeclarationTransformation++;
411          List list = (List)getParent();
412          int i = list.getIndexOfChild(this);
413          List newList = rewriteBlock_getStmt();
414          for(int j = 1; j < newList.getNumChildNoTransform(); j++)
415            list.insertChild(newList.getChildNoTransform(j), ++i);
416            state().duringVariableDeclarationTransformation--;
417          return newList.getChildNoTransform(0);
418        }
419        // Declared in /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag at line 159
420        if(getParent().getParent() instanceof ForStmt && 
421          ((ForStmt)getParent().getParent()).getInitStmtListNoTransform() == getParent() && getNumVariableDecl() > 1) {
422        state().duringVariableDeclarationTransformation++;
423          List list = (List)getParent();
424          int i = list.getIndexOfChild(this);
425          List newList = rewriteForStmt_getInitStmt();
426          for(int j = 1; j < newList.getNumChildNoTransform(); j++)
427            list.insertChild(newList.getChildNoTransform(j), ++i);
428            state().duringVariableDeclarationTransformation--;
429          return newList.getChildNoTransform(0);
430        }
431        return super.rewriteTo();
432      }
433      /**
434       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag:144
435       * @apilevel internal
436       */  private VariableDeclaration rewriteRule0() {
437    {
438          VariableDeclaration decl = getVariableDecl(0).createVariableDeclarationFrom(getModifiers(), getTypeAccess());
439          decl.setStart(start); // copy location information
440          decl.setEnd(end); // copy location information
441          return decl;
442        }  }
443      /**
444       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag:155
445       * @apilevel internal
446       */  private List rewriteBlock_getStmt() {
447        return createVariableDeclarationList();
448      }
449      /**
450       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag:159
451       * @apilevel internal
452       */  private List rewriteForStmt_getInitStmt() {
453        return createVariableDeclarationList();
454      }
455    }