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 VariableDecl : {@link ASTNode} ::= <span class="component">&lt;ID:String&gt;</span> <span class="component">{@link Dims}*</span> <span class="component">[Init:{@link Expr}]</span>;
016     * @ast node
017     * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:85
018     */
019    public class VariableDecl extends ASTNode<ASTNode> 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 VariableDecl clone() throws CloneNotSupportedException {
035        VariableDecl node = (VariableDecl)super.clone();
036        node.in$Circle(false);
037        node.is$Final(false);
038        return node;
039      }
040    /**
041     * @apilevel internal
042     */
043      @SuppressWarnings({"unchecked", "cast"})
044    public VariableDecl copy() {
045      
046      try {
047        VariableDecl node = (VariableDecl) clone();
048        node.parent = null;
049        if(children != null)
050          node.children = (ASTNode[]) children.clone();
051        
052        return node;
053      } catch (CloneNotSupportedException e) {
054        throw new Error("Error: clone not supported for " + getClass().getName());
055      }
056      
057    }/**
058     * Create a deep copy of the AST subtree at this node.
059     * The copy is dangling, i.e. has no parent.
060     * @return dangling copy of the subtree at this node
061     * @apilevel low-level
062     */
063      @SuppressWarnings({"unchecked", "cast"})
064    public VariableDecl fullCopy() {
065      
066      VariableDecl tree = (VariableDecl) copy();
067      if (children != null) {
068        for (int i = 0; i < children.length; ++i) {
069          
070          ASTNode child = (ASTNode) children[i];
071          if(child != null) {
072            child = child.fullCopy();
073            tree.setChild(child, i);
074          }
075        }
076      }
077      return tree;
078      
079    }  /**
080       * @ast method 
081       * @aspect VariableDeclarationTransformation
082       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag:182
083       */
084      public VariableDeclaration createVariableDeclarationFrom(Modifiers modifiers, Access type) {
085        VariableDeclaration decl = new VariableDeclaration(
086          modifiers,
087          type.addArrayDims(getDimsList()),
088          getID(),
089          getInitOpt()
090        );
091        decl.setStart(start); // copy location information
092        decl.setEnd(end); // copy location information
093        decl.IDstart = IDstart;
094        decl.IDend = IDend;
095        return decl;
096      }
097      /**
098       * @ast method 
099       * @aspect VariableDeclarationTransformation
100       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag:196
101       */
102      public FieldDeclaration createFieldDeclarationFrom(Modifiers modifiers, Access type) {
103        FieldDeclaration decl = new FieldDeclaration(
104          modifiers,
105          type.addArrayDims(getDimsList()),
106          getID(),
107          getInitOpt()
108        );
109        decl.setStart(start); // copy location information
110        decl.setEnd(end); // copy location information
111        decl.IDstart = IDstart;
112        decl.IDend = IDend;
113        return decl;
114      }
115      /**
116       * @ast method 
117       * 
118       */
119      public VariableDecl() {
120        super();
121    
122    
123      }
124      /**
125       * Initializes the child array to the correct size.
126       * Initializes List and Opt nta children.
127       * @apilevel internal
128       * @ast method
129       * @ast method 
130       * 
131       */
132      public void init$Children() {
133        children = new ASTNode[2];
134        setChild(new List(), 0);
135        setChild(new Opt(), 1);
136      }
137      /**
138       * @ast method 
139       * 
140       */
141      public VariableDecl(String p0, List<Dims> p1, Opt<Expr> p2) {
142        setID(p0);
143        setChild(p1, 0);
144        setChild(p2, 1);
145      }
146      /**
147       * @ast method 
148       * 
149       */
150      public VariableDecl(beaver.Symbol p0, List<Dims> p1, Opt<Expr> p2) {
151        setID(p0);
152        setChild(p1, 0);
153        setChild(p2, 1);
154      }
155      /**
156       * @apilevel low-level
157       * @ast method 
158       * 
159       */
160      protected int numChildren() {
161        return 2;
162      }
163      /**
164       * @apilevel internal
165       * @ast method 
166       * 
167       */
168      public boolean mayHaveRewrite() {
169        return false;
170      }
171      /**
172       * Replaces the lexeme ID.
173       * @param value The new value for the lexeme ID.
174       * @apilevel high-level
175       * @ast method 
176       * 
177       */
178      public void setID(String value) {
179        tokenString_ID = value;
180      }
181      /**
182       * @apilevel internal
183       * @ast method 
184       * 
185       */
186      
187      /**
188       * @apilevel internal
189       */
190      protected String tokenString_ID;
191      /**
192       * @ast method 
193       * 
194       */
195      
196      public int IDstart;
197      /**
198       * @ast method 
199       * 
200       */
201      
202      public int IDend;
203      /**
204       * JastAdd-internal setter for lexeme ID using the Beaver parser.
205       * @apilevel internal
206       * @ast method 
207       * 
208       */
209      public void setID(beaver.Symbol symbol) {
210        if(symbol.value != null && !(symbol.value instanceof String))
211          throw new UnsupportedOperationException("setID is only valid for String lexemes");
212        tokenString_ID = (String)symbol.value;
213        IDstart = symbol.getStart();
214        IDend = symbol.getEnd();
215      }
216      /**
217       * Retrieves the value for the lexeme ID.
218       * @return The value for the lexeme ID.
219       * @apilevel high-level
220       * @ast method 
221       * 
222       */
223      public String getID() {
224        return tokenString_ID != null ? tokenString_ID : "";
225      }
226      /**
227       * Replaces the Dims list.
228       * @param list The new list node to be used as the Dims list.
229       * @apilevel high-level
230       * @ast method 
231       * 
232       */
233      public void setDimsList(List<Dims> list) {
234        setChild(list, 0);
235      }
236      /**
237       * Retrieves the number of children in the Dims list.
238       * @return Number of children in the Dims list.
239       * @apilevel high-level
240       * @ast method 
241       * 
242       */
243      public int getNumDims() {
244        return getDimsList().getNumChild();
245      }
246      /**
247       * Retrieves the number of children in the Dims list.
248       * Calling this method will not trigger rewrites..
249       * @return Number of children in the Dims list.
250       * @apilevel low-level
251       * @ast method 
252       * 
253       */
254      public int getNumDimsNoTransform() {
255        return getDimsListNoTransform().getNumChildNoTransform();
256      }
257      /**
258       * Retrieves the element at index {@code i} in the Dims list..
259       * @param i Index of the element to return.
260       * @return The element at position {@code i} in the Dims list.
261       * @apilevel high-level
262       * @ast method 
263       * 
264       */
265      @SuppressWarnings({"unchecked", "cast"})
266      public Dims getDims(int i) {
267        return (Dims)getDimsList().getChild(i);
268      }
269      /**
270       * Append an element to the Dims list.
271       * @param node The element to append to the Dims list.
272       * @apilevel high-level
273       * @ast method 
274       * 
275       */
276      public void addDims(Dims node) {
277        List<Dims> list = (parent == null || state == null) ? getDimsListNoTransform() : getDimsList();
278        list.addChild(node);
279      }
280      /**
281       * @apilevel low-level
282       * @ast method 
283       * 
284       */
285      public void addDimsNoTransform(Dims node) {
286        List<Dims> list = getDimsListNoTransform();
287        list.addChild(node);
288      }
289      /**
290       * Replaces the Dims list element at index {@code i} with the new node {@code node}.
291       * @param node The new node to replace the old list element.
292       * @param i The list index of the node to be replaced.
293       * @apilevel high-level
294       * @ast method 
295       * 
296       */
297      public void setDims(Dims node, int i) {
298        List<Dims> list = getDimsList();
299        list.setChild(node, i);
300      }
301      /**
302       * Retrieves the Dims list.
303       * @return The node representing the Dims list.
304       * @apilevel high-level
305       * @ast method 
306       * 
307       */
308      public List<Dims> getDimss() {
309        return getDimsList();
310      }
311      /**
312       * Retrieves the Dims list.
313       * <p><em>This method does not invoke AST transformations.</em></p>
314       * @return The node representing the Dims list.
315       * @apilevel low-level
316       * @ast method 
317       * 
318       */
319      public List<Dims> getDimssNoTransform() {
320        return getDimsListNoTransform();
321      }
322      /**
323       * Retrieves the Dims list.
324       * @return The node representing the Dims list.
325       * @apilevel high-level
326       * @ast method 
327       * 
328       */
329      @SuppressWarnings({"unchecked", "cast"})
330      public List<Dims> getDimsList() {
331        List<Dims> list = (List<Dims>)getChild(0);
332        list.getNumChild();
333        return list;
334      }
335      /**
336       * Retrieves the Dims list.
337       * <p><em>This method does not invoke AST transformations.</em></p>
338       * @return The node representing the Dims list.
339       * @apilevel low-level
340       * @ast method 
341       * 
342       */
343      @SuppressWarnings({"unchecked", "cast"})
344      public List<Dims> getDimsListNoTransform() {
345        return (List<Dims>)getChildNoTransform(0);
346      }
347      /**
348       * Replaces the optional node for the Init child. This is the {@code Opt} node containing the child Init, not the actual child!
349       * @param opt The new node to be used as the optional node for the Init child.
350       * @apilevel low-level
351       * @ast method 
352       * 
353       */
354      public void setInitOpt(Opt<Expr> opt) {
355        setChild(opt, 1);
356      }
357      /**
358       * Check whether the optional Init child exists.
359       * @return {@code true} if the optional Init child exists, {@code false} if it does not.
360       * @apilevel high-level
361       * @ast method 
362       * 
363       */
364      public boolean hasInit() {
365        return getInitOpt().getNumChild() != 0;
366      }
367      /**
368       * Retrieves the (optional) Init child.
369       * @return The Init child, if it exists. Returns {@code null} otherwise.
370       * @apilevel low-level
371       * @ast method 
372       * 
373       */
374      @SuppressWarnings({"unchecked", "cast"})
375      public Expr getInit() {
376        return (Expr)getInitOpt().getChild(0);
377      }
378      /**
379       * Replaces the (optional) Init child.
380       * @param node The new node to be used as the Init child.
381       * @apilevel high-level
382       * @ast method 
383       * 
384       */
385      public void setInit(Expr node) {
386        getInitOpt().setChild(node, 0);
387      }
388      /**
389       * @apilevel low-level
390       * @ast method 
391       * 
392       */
393      @SuppressWarnings({"unchecked", "cast"})
394      public Opt<Expr> getInitOpt() {
395        return (Opt<Expr>)getChild(1);
396      }
397      /**
398       * Retrieves the optional node for child Init. This is the {@code Opt} node containing the child Init, not the actual child!
399       * <p><em>This method does not invoke AST transformations.</em></p>
400       * @return The optional node for child Init.
401       * @apilevel low-level
402       * @ast method 
403       * 
404       */
405      @SuppressWarnings({"unchecked", "cast"})
406      public Opt<Expr> getInitOptNoTransform() {
407        return (Opt<Expr>)getChildNoTransform(1);
408      }
409      /**
410       * @attribute syn
411       * @aspect Variables
412       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/VariableDeclaration.jrag:84
413       */
414      public String name() {
415        ASTNode$State state = state();
416        try {  return getID();  }
417        finally {
418        }
419      }
420      /**
421       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:41
422       * @apilevel internal
423       */
424      public boolean Define_boolean_isSource(ASTNode caller, ASTNode child) {
425        if(caller == getInitOptNoTransform()) {
426          return true;
427        }
428        else {      return getParent().Define_boolean_isSource(this, caller);
429        }
430      }
431      /**
432       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/InnerClasses.jrag:69
433       * @apilevel internal
434       */
435      public TypeDecl Define_TypeDecl_expectedType(ASTNode caller, ASTNode child) {
436        if(caller == getInitOptNoTransform()) {
437          return null;
438        }
439        else {      return getParent().Define_TypeDecl_expectedType(this, caller);
440        }
441      }
442      /**
443       * @apilevel internal
444       */
445      public ASTNode rewriteTo() {
446        return super.rewriteTo();
447      }
448    }