001    /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */
002    package org.extendj.ast;
003    
004    import java.util.HashSet;
005    import java.io.File;
006    import java.util.Set;
007    import java.util.Collections;
008    import java.util.Collection;
009    import java.util.ArrayList;
010    import beaver.*;
011    import java.util.*;
012    import java.io.ByteArrayOutputStream;
013    import java.io.PrintStream;
014    import java.lang.reflect.InvocationTargetException;
015    import java.lang.reflect.Method;
016    import org.jastadd.util.*;
017    import java.util.zip.*;
018    import java.io.*;
019    import org.jastadd.util.PrettyPrintable;
020    import org.jastadd.util.PrettyPrinter;
021    import java.io.FileNotFoundException;
022    import java.io.BufferedInputStream;
023    import java.io.DataInputStream;
024    /**
025     * @ast node
026     * @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:76
027     * @production FieldDecl : {@link MemberDecl} ::= <span class="component">{@link Modifiers}</span> <span class="component">TypeAccess:{@link Access}</span> <span class="component">{@link VariableDecl}*</span>;
028    
029     */
030    public class FieldDecl extends MemberDecl implements Cloneable {
031      /**
032       * @declaredat ASTNode:1
033       */
034      public FieldDecl() {
035        super();
036      }
037      /**
038       * Initializes the child array to the correct size.
039       * Initializes List and Opt nta children.
040       * @apilevel internal
041       * @ast method
042       * @declaredat ASTNode:10
043       */
044      public void init$Children() {
045        children = new ASTNode[3];
046        setChild(new List(), 2);
047      }
048      /**
049       * @declaredat ASTNode:14
050       */
051      public FieldDecl(Modifiers p0, Access p1, List<VariableDecl> p2) {
052        setChild(p0, 0);
053        setChild(p1, 1);
054        setChild(p2, 2);
055      }
056      /**
057       * @apilevel low-level
058       * @declaredat ASTNode:22
059       */
060      protected int numChildren() {
061        return 3;
062      }
063      /**
064       * @apilevel internal
065       * @declaredat ASTNode:28
066       */
067      public boolean mayHaveRewrite() {
068        return true;
069      }
070      /**
071       * @apilevel internal
072       * @declaredat ASTNode:34
073       */
074      public void flushAttrCache() {
075        super.flushAttrCache();
076      }
077      /**
078       * @apilevel internal
079       * @declaredat ASTNode:40
080       */
081      public void flushCollectionCache() {
082        super.flushCollectionCache();
083      }
084      /**
085       * @apilevel internal
086       * @declaredat ASTNode:46
087       */
088      public void flushRewriteCache() {
089        super.flushRewriteCache();
090      }
091      /**
092       * @apilevel internal
093       * @declaredat ASTNode:52
094       */
095      public FieldDecl clone() throws CloneNotSupportedException {
096        FieldDecl node = (FieldDecl) super.clone();
097        return node;
098      }
099      /**
100       * @apilevel internal
101       * @declaredat ASTNode:59
102       */
103      public FieldDecl copy() {
104        try {
105          FieldDecl node = (FieldDecl) clone();
106          node.parent = null;
107          if (children != null) {
108            node.children = (ASTNode[]) children.clone();
109          }
110          return node;
111        } catch (CloneNotSupportedException e) {
112          throw new Error("Error: clone not supported for " + getClass().getName());
113        }
114      }
115      /**
116       * Create a deep copy of the AST subtree at this node.
117       * The copy is dangling, i.e. has no parent.
118       * @return dangling copy of the subtree at this node
119       * @apilevel low-level
120       * @deprecated Please use treeCopy or treeCopyNoTransform instead
121       * @declaredat ASTNode:78
122       */
123      @Deprecated
124      public FieldDecl fullCopy() {
125        return treeCopyNoTransform();
126      }
127      /**
128       * Create a deep copy of the AST subtree at this node.
129       * The copy is dangling, i.e. has no parent.
130       * @return dangling copy of the subtree at this node
131       * @apilevel low-level
132       * @declaredat ASTNode:88
133       */
134      public FieldDecl treeCopyNoTransform() {
135        FieldDecl tree = (FieldDecl) copy();
136        if (children != null) {
137          for (int i = 0; i < children.length; ++i) {
138            ASTNode child = (ASTNode) children[i];
139            if (child != null) {
140              child = child.treeCopyNoTransform();
141              tree.setChild(child, i);
142            }
143          }
144        }
145        return tree;
146      }
147      /**
148       * Create a deep copy of the AST subtree at this node.
149       * The subtree of this node is traversed to trigger rewrites before copy.
150       * The copy is dangling, i.e. has no parent.
151       * @return dangling copy of the subtree at this node
152       * @apilevel low-level
153       * @declaredat ASTNode:108
154       */
155      public FieldDecl treeCopy() {
156        doFullTraversal();
157        return treeCopyNoTransform();
158      }
159      /**
160       * @apilevel internal
161       * @declaredat ASTNode:115
162       */
163      protected boolean is$Equal(ASTNode node) {
164        return super.is$Equal(node);    
165      }
166      /**
167       * Replaces the Modifiers child.
168       * @param node The new node to replace the Modifiers child.
169       * @apilevel high-level
170       */
171      public void setModifiers(Modifiers node) {
172        setChild(node, 0);
173      }
174      /**
175       * Retrieves the Modifiers child.
176       * @return The current node used as the Modifiers child.
177       * @apilevel high-level
178       */
179      @ASTNodeAnnotation.Child(name="Modifiers")
180      public Modifiers getModifiers() {
181        return (Modifiers) getChild(0);
182      }
183      /**
184       * Retrieves the Modifiers child.
185       * <p><em>This method does not invoke AST transformations.</em></p>
186       * @return The current node used as the Modifiers child.
187       * @apilevel low-level
188       */
189      public Modifiers getModifiersNoTransform() {
190        return (Modifiers) getChildNoTransform(0);
191      }
192      /**
193       * Replaces the TypeAccess child.
194       * @param node The new node to replace the TypeAccess child.
195       * @apilevel high-level
196       */
197      public void setTypeAccess(Access node) {
198        setChild(node, 1);
199      }
200      /**
201       * Retrieves the TypeAccess child.
202       * @return The current node used as the TypeAccess child.
203       * @apilevel high-level
204       */
205      @ASTNodeAnnotation.Child(name="TypeAccess")
206      public Access getTypeAccess() {
207        return (Access) getChild(1);
208      }
209      /**
210       * Retrieves the TypeAccess child.
211       * <p><em>This method does not invoke AST transformations.</em></p>
212       * @return The current node used as the TypeAccess child.
213       * @apilevel low-level
214       */
215      public Access getTypeAccessNoTransform() {
216        return (Access) getChildNoTransform(1);
217      }
218      /**
219       * Replaces the VariableDecl list.
220       * @param list The new list node to be used as the VariableDecl list.
221       * @apilevel high-level
222       */
223      public void setVariableDeclList(List<VariableDecl> list) {
224        setChild(list, 2);
225      }
226      /**
227       * Retrieves the number of children in the VariableDecl list.
228       * @return Number of children in the VariableDecl list.
229       * @apilevel high-level
230       */
231      public int getNumVariableDecl() {
232        return getVariableDeclList().getNumChild();
233      }
234      /**
235       * Retrieves the number of children in the VariableDecl list.
236       * Calling this method will not trigger rewrites.
237       * @return Number of children in the VariableDecl list.
238       * @apilevel low-level
239       */
240      public int getNumVariableDeclNoTransform() {
241        return getVariableDeclListNoTransform().getNumChildNoTransform();
242      }
243      /**
244       * Retrieves the element at index {@code i} in the VariableDecl list.
245       * @param i Index of the element to return.
246       * @return The element at position {@code i} in the VariableDecl list.
247       * @apilevel high-level
248       */
249      public VariableDecl getVariableDecl(int i) {
250        return (VariableDecl) getVariableDeclList().getChild(i);
251      }
252      /**
253       * Check whether the VariableDecl list has any children.
254       * @return {@code true} if it has at least one child, {@code false} otherwise.
255       * @apilevel high-level
256       */
257      public boolean hasVariableDecl() {
258        return getVariableDeclList().getNumChild() != 0;
259      }
260      /**
261       * Append an element to the VariableDecl list.
262       * @param node The element to append to the VariableDecl list.
263       * @apilevel high-level
264       */
265      public void addVariableDecl(VariableDecl node) {
266        List<VariableDecl> list = (parent == null) ? getVariableDeclListNoTransform() : getVariableDeclList();
267        list.addChild(node);
268      }
269      /**
270       * @apilevel low-level
271       */
272      public void addVariableDeclNoTransform(VariableDecl node) {
273        List<VariableDecl> list = getVariableDeclListNoTransform();
274        list.addChild(node);
275      }
276      /**
277       * Replaces the VariableDecl list element at index {@code i} with the new node {@code node}.
278       * @param node The new node to replace the old list element.
279       * @param i The list index of the node to be replaced.
280       * @apilevel high-level
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       */
291      @ASTNodeAnnotation.ListChild(name="VariableDecl")
292      public List<VariableDecl> getVariableDeclList() {
293        List<VariableDecl> list = (List<VariableDecl>) getChild(2);
294        return list;
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       */
302      public List<VariableDecl> getVariableDeclListNoTransform() {
303        return (List<VariableDecl>) getChildNoTransform(2);
304      }
305      /**
306       * Retrieves the VariableDecl list.
307       * @return The node representing the VariableDecl list.
308       * @apilevel high-level
309       */
310      public List<VariableDecl> getVariableDecls() {
311        return getVariableDeclList();
312      }
313      /**
314       * Retrieves the VariableDecl list.
315       * <p><em>This method does not invoke AST transformations.</em></p>
316       * @return The node representing the VariableDecl list.
317       * @apilevel low-level
318       */
319      public List<VariableDecl> getVariableDeclsNoTransform() {
320        return getVariableDeclListNoTransform();
321      }
322      /**
323       * @attribute syn
324       * @aspect Modifiers
325       * @declaredat /home/jesper/git/extendj/java4/frontend/Modifiers.jrag:284
326       */
327      @ASTNodeAnnotation.Attribute
328      public boolean isStatic() {
329        boolean isStatic_value = getModifiers().isStatic();
330    
331        return isStatic_value;
332      }
333      /**
334       * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36
335       * @apilevel internal
336       */
337      public NameType Define_nameType(ASTNode caller, ASTNode child) {
338        if (caller == getTypeAccessNoTransform()) {
339          // @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:104
340          return NameType.TYPE_NAME;
341        }
342        else {
343          return getParent().Define_nameType(this, caller);
344        }
345      }
346      protected boolean canDefine_nameType(ASTNode caller, ASTNode child) {
347        return true;
348      }
349      /**
350       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:601
351       * @apilevel internal
352       */
353      public TypeDecl Define_declType(ASTNode caller, ASTNode child) {
354        if (caller == getVariableDeclListNoTransform()) {
355          // @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:283
356          int childIndex = caller.getIndexOfChild(child);
357          return null;
358        }
359        else {
360          return getParent().Define_declType(this, caller);
361        }
362      }
363      protected boolean canDefine_declType(ASTNode caller, ASTNode child) {
364        return true;
365      }
366      /**
367       * @apilevel internal
368       */
369      public ASTNode rewriteTo() {
370        // Declared at /home/jesper/git/extendj/java4/frontend/VariableDeclaration.jrag:122
371        if (getNumVariableDecl() == 1) {
372          return rewriteRule0();
373        }
374        // Declared at /home/jesper/git/extendj/java4/frontend/VariableDeclaration.jrag:133
375        if (getParent().getParent() instanceof TypeDecl &&
376            ((TypeDecl)getParent().getParent()).getBodyDeclListNoTransform() == getParent() && getNumVariableDecl() > 1) {
377          List list = (List) getParent();
378          int i = list.getIndexOfChild(this);
379          List newList = rewriteTypeDecl_getBodyDecl();
380          // The first child is set by the normal rewrite loop.
381          for(int j = 1; j < newList.getNumChildNoTransform(); j++) {
382            list.insertChild(newList.getChildNoTransform(j), ++i);
383          }
384          return newList.getChildNoTransform(0);
385        }
386        return super.rewriteTo();
387      }
388      /**
389       * @declaredat /home/jesper/git/extendj/java4/frontend/VariableDeclaration.jrag:122
390       * @apilevel internal
391       */
392      private FieldDeclaration rewriteRule0() {
393    {
394          FieldDeclaration decl = getVariableDecl(0).createFieldDeclarationFrom(getModifiers(), getTypeAccess());
395          decl.setStart(start); // copy location information
396          decl.setEnd(end); // copy location information
397          return decl;
398        }  }
399      /**
400       * @declaredat /home/jesper/git/extendj/java4/frontend/VariableDeclaration.jrag:133
401       * @apilevel internal
402       */  private List rewriteTypeDecl_getBodyDecl() {
403    {
404          List varList = new List();
405          for (int j = 0; j < getNumVariableDecl(); j++) {
406            FieldDeclaration f = getVariableDecl(j).createFieldDeclarationFrom(
407                (Modifiers) getModifiers().treeCopyNoTransform(),
408                (Access) getTypeAccess().treeCopyNoTransform()
409                );
410            if (j == 0) {
411              f.setStart(start);
412            } else {
413              f.getModifiersNoTransform().clearLocations();
414              f.getTypeAccessNoTransform().clearLocations();
415            }
416            f.setFieldDecl(this);
417            varList.add(f);
418          }
419          return varList;
420        }  }
421    }