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/java5/grammar/Enums.ast:5
027     * @production EnumInstanceExpr : {@link ClassInstanceExpr} ::= <span class="component">{@link Access}</span> <span class="component">Arg:{@link Expr}*</span> <span class="component">[{@link TypeDecl}]</span>;
028    
029     */
030    public class EnumInstanceExpr extends ClassInstanceExpr implements Cloneable {
031      /**
032       * @declaredat ASTNode:1
033       */
034      public EnumInstanceExpr() {
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 Opt(), 0);
047        setChild(new List(), 2);
048      }
049      /**
050       * @declaredat ASTNode:15
051       */
052      public EnumInstanceExpr(Opt<TypeDecl> p0) {
053        setChild(p0, 0);
054      }
055      /**
056       * @apilevel low-level
057       * @declaredat ASTNode:21
058       */
059      protected int numChildren() {
060        return 1;
061      }
062      /**
063       * @apilevel internal
064       * @declaredat ASTNode:27
065       */
066      public boolean mayHaveRewrite() {
067        return false;
068      }
069      /**
070       * @apilevel internal
071       * @declaredat ASTNode:33
072       */
073      public void flushAttrCache() {
074        super.flushAttrCache();
075        getAccess_reset();
076        getArgList_reset();
077      }
078      /**
079       * @apilevel internal
080       * @declaredat ASTNode:41
081       */
082      public void flushCollectionCache() {
083        super.flushCollectionCache();
084      }
085      /**
086       * @apilevel internal
087       * @declaredat ASTNode:47
088       */
089      public void flushRewriteCache() {
090        super.flushRewriteCache();
091      }
092      /**
093       * @apilevel internal
094       * @declaredat ASTNode:53
095       */
096      public EnumInstanceExpr clone() throws CloneNotSupportedException {
097        EnumInstanceExpr node = (EnumInstanceExpr) super.clone();
098        return node;
099      }
100      /**
101       * @apilevel internal
102       * @declaredat ASTNode:60
103       */
104      public EnumInstanceExpr copy() {
105        try {
106          EnumInstanceExpr node = (EnumInstanceExpr) clone();
107          node.parent = null;
108          if (children != null) {
109            node.children = (ASTNode[]) children.clone();
110          }
111          return node;
112        } catch (CloneNotSupportedException e) {
113          throw new Error("Error: clone not supported for " + getClass().getName());
114        }
115      }
116      /**
117       * Create a deep copy of the AST subtree at this node.
118       * The copy is dangling, i.e. has no parent.
119       * @return dangling copy of the subtree at this node
120       * @apilevel low-level
121       * @deprecated Please use treeCopy or treeCopyNoTransform instead
122       * @declaredat ASTNode:79
123       */
124      @Deprecated
125      public EnumInstanceExpr fullCopy() {
126        return treeCopyNoTransform();
127      }
128      /**
129       * Create a deep copy of the AST subtree at this node.
130       * The copy is dangling, i.e. has no parent.
131       * @return dangling copy of the subtree at this node
132       * @apilevel low-level
133       * @declaredat ASTNode:89
134       */
135      public EnumInstanceExpr treeCopyNoTransform() {
136        EnumInstanceExpr tree = (EnumInstanceExpr) copy();
137        if (children != null) {
138          for (int i = 0; i < children.length; ++i) {
139            switch (i) {
140            case 1:
141              tree.children[i] = null;
142              continue;
143            case 2:
144              tree.children[i] = new List();
145              continue;
146            }
147            ASTNode child = (ASTNode) children[i];
148            if (child != null) {
149              child = child.treeCopyNoTransform();
150              tree.setChild(child, i);
151            }
152          }
153        }
154        return tree;
155      }
156      /**
157       * Create a deep copy of the AST subtree at this node.
158       * The subtree of this node is traversed to trigger rewrites before copy.
159       * The copy is dangling, i.e. has no parent.
160       * @return dangling copy of the subtree at this node
161       * @apilevel low-level
162       * @declaredat ASTNode:117
163       */
164      public EnumInstanceExpr treeCopy() {
165        doFullTraversal();
166        return treeCopyNoTransform();
167      }
168      /**
169       * @apilevel internal
170       * @declaredat ASTNode:124
171       */
172      protected boolean is$Equal(ASTNode node) {
173        return super.is$Equal(node);    
174      }
175      /**
176       * Replaces the optional node for the TypeDecl child. This is the <code>Opt</code>
177       * node containing the child TypeDecl, not the actual child!
178       * @param opt The new node to be used as the optional node for the TypeDecl child.
179       * @apilevel low-level
180       */
181      public void setTypeDeclOpt(Opt<TypeDecl> opt) {
182        setChild(opt, 0);
183      }
184      /**
185       * Replaces the (optional) TypeDecl child.
186       * @param node The new node to be used as the TypeDecl child.
187       * @apilevel high-level
188       */
189      public void setTypeDecl(TypeDecl node) {
190        getTypeDeclOpt().setChild(node, 0);
191      }
192      /**
193       * Check whether the optional TypeDecl child exists.
194       * @return {@code true} if the optional TypeDecl child exists, {@code false} if it does not.
195       * @apilevel high-level
196       */
197      public boolean hasTypeDecl() {
198        return getTypeDeclOpt().getNumChild() != 0;
199      }
200      /**
201       * Retrieves the (optional) TypeDecl child.
202       * @return The TypeDecl child, if it exists. Returns {@code null} otherwise.
203       * @apilevel low-level
204       */
205      public TypeDecl getTypeDecl() {
206        return (TypeDecl) getTypeDeclOpt().getChild(0);
207      }
208      /**
209       * Retrieves the optional node for the TypeDecl child. This is the <code>Opt</code> node containing the child TypeDecl, not the actual child!
210       * @return The optional node for child the TypeDecl child.
211       * @apilevel low-level
212       */
213      @ASTNodeAnnotation.OptChild(name="TypeDecl")
214      public Opt<TypeDecl> getTypeDeclOpt() {
215        return (Opt<TypeDecl>) getChild(0);
216      }
217      /**
218       * Retrieves the optional node for child TypeDecl. This is the <code>Opt</code> node containing the child TypeDecl, not the actual child!
219       * <p><em>This method does not invoke AST transformations.</em></p>
220       * @return The optional node for child TypeDecl.
221       * @apilevel low-level
222       */
223      public Opt<TypeDecl> getTypeDeclOptNoTransform() {
224        return (Opt<TypeDecl>) getChildNoTransform(0);
225      }
226      /**
227       * This method should not be called. This method throws an exception due to
228       * the corresponding child being an NTA shadowing a non-NTA child.
229       * @param node
230       * @apilevel internal
231       */
232      public void setAccess(Access node) {
233        throw new Error("Can not replace NTA child Access in EnumInstanceExpr!");
234      }
235      /**
236       * Retrieves the Access child.
237       * <p><em>This method does not invoke AST transformations.</em></p>
238       * @return The current node used as the Access child.
239       * @apilevel low-level
240       */
241      public Access getAccessNoTransform() {
242        return (Access) getChildNoTransform(1);
243      }
244      /**
245       * Retrieves the child position of the optional child Access.
246       * @return The the child position of the optional child Access.
247       * @apilevel low-level
248       */
249      protected int getAccessChildPosition() {
250        return 1;
251      }
252      /**
253       * This method should not be called. This method throws an exception due to
254       * the corresponding child being an NTA shadowing a non-NTA child.
255       * @param node
256       * @apilevel internal
257       */
258      public void setArgList(List<Expr> node) {
259        throw new Error("Can not replace NTA child ArgList in EnumInstanceExpr!");
260      }
261      /**
262       * Retrieves the number of children in the Arg list.
263       * @return Number of children in the Arg list.
264       * @apilevel high-level
265       */
266      public int getNumArg() {
267        return getArgList().getNumChild();
268      }
269      /**
270       * Retrieves the number of children in the Arg list.
271       * Calling this method will not trigger rewrites.
272       * @return Number of children in the Arg list.
273       * @apilevel low-level
274       */
275      public int getNumArgNoTransform() {
276        return getArgListNoTransform().getNumChildNoTransform();
277      }
278      /**
279       * Retrieves the element at index {@code i} in the Arg list.
280       * @param i Index of the element to return.
281       * @return The element at position {@code i} in the Arg list.
282       * @apilevel high-level
283       */
284      public Expr getArg(int i) {
285        return (Expr) getArgList().getChild(i);
286      }
287      /**
288       * Check whether the Arg list has any children.
289       * @return {@code true} if it has at least one child, {@code false} otherwise.
290       * @apilevel high-level
291       */
292      public boolean hasArg() {
293        return getArgList().getNumChild() != 0;
294      }
295      /**
296       * Append an element to the Arg list.
297       * @param node The element to append to the Arg list.
298       * @apilevel high-level
299       */
300      public void addArg(Expr node) {
301        List<Expr> list = (parent == null) ? getArgListNoTransform() : getArgList();
302        list.addChild(node);
303      }
304      /**
305       * @apilevel low-level
306       */
307      public void addArgNoTransform(Expr node) {
308        List<Expr> list = getArgListNoTransform();
309        list.addChild(node);
310      }
311      /**
312       * Replaces the Arg list element at index {@code i} with the new node {@code node}.
313       * @param node The new node to replace the old list element.
314       * @param i The list index of the node to be replaced.
315       * @apilevel high-level
316       */
317      public void setArg(Expr node, int i) {
318        List<Expr> list = getArgList();
319        list.setChild(node, i);
320      }
321      /**
322       * Retrieves the child position of the Arg list.
323       * @return The the child position of the Arg list.
324       * @apilevel low-level
325       */
326      protected int getArgListChildPosition() {
327        return 2;
328      }
329      /**
330       * Retrieves the Arg list.
331       * <p><em>This method does not invoke AST transformations.</em></p>
332       * @return The node representing the Arg list.
333       * @apilevel low-level
334       */
335      public List<Expr> getArgListNoTransform() {
336        return (List<Expr>) getChildNoTransform(2);
337      }
338      /**
339       * Retrieves the Arg list.
340       * @return The node representing the Arg list.
341       * @apilevel high-level
342       */
343      public List<Expr> getArgs() {
344        return getArgList();
345      }
346      /**
347       * Retrieves the Arg list.
348       * <p><em>This method does not invoke AST transformations.</em></p>
349       * @return The node representing the Arg list.
350       * @apilevel low-level
351       */
352      public List<Expr> getArgsNoTransform() {
353        return getArgListNoTransform();
354      }
355      /**
356       * @apilevel internal
357       */
358      protected boolean getAccess_computed = false;
359      /**
360       * @apilevel internal
361       */
362      protected Access getAccess_value;
363      /**
364       * @apilevel internal
365       */
366      private void getAccess_reset() {
367        getAccess_computed = false;
368        getAccess_value = null;
369      }
370      /**
371       * @attribute syn nta
372       * @aspect Enums
373       * @declaredat /home/jesper/git/extendj/java5/frontend/Enums.jrag:241
374       */
375      @ASTNodeAnnotation.Attribute
376      public Access getAccess() {
377        ASTNode$State state = state();
378        if (getAccess_computed) {
379          return (Access) getChild(getAccessChildPosition());
380        }
381        boolean intermediate = state.INTERMEDIATE_VALUE;
382        state.INTERMEDIATE_VALUE = false;
383        int num = state.boundariesCrossed;
384        boolean isFinal = this.is$Final();
385        getAccess_value = getAccess_compute();
386        setChild(getAccess_value, getAccessChildPosition());
387        if (isFinal && num == state().boundariesCrossed) {
388          getAccess_computed = true;
389        } else {
390        }
391        state.INTERMEDIATE_VALUE |= intermediate;
392    
393        Access node = (Access) this.getChild(getAccessChildPosition());
394        return node;
395      }
396      /**
397       * @apilevel internal
398       */
399      private Access getAccess_compute() {
400          return hostType().createQualifiedAccess();
401        }
402      /**
403       * @apilevel internal
404       */
405      protected boolean getArgList_computed = false;
406      /**
407       * @apilevel internal
408       */
409      protected List<Expr> getArgList_value;
410      /**
411       * @apilevel internal
412       */
413      private void getArgList_reset() {
414        getArgList_computed = false;
415        getArgList_value = null;
416      }
417      /**
418       * @attribute syn nta
419       * @aspect Enums
420       * @declaredat /home/jesper/git/extendj/java5/frontend/Enums.jrag:245
421       */
422      @ASTNodeAnnotation.Attribute
423      public List<Expr> getArgList() {
424        ASTNode$State state = state();
425        if (getArgList_computed) {
426          return (List<Expr>) getChild(getArgListChildPosition());
427        }
428        boolean intermediate = state.INTERMEDIATE_VALUE;
429        state.INTERMEDIATE_VALUE = false;
430        int num = state.boundariesCrossed;
431        boolean isFinal = this.is$Final();
432        getArgList_value = getArgList_compute();
433        setChild(getArgList_value, getArgListChildPosition());
434        if (isFinal && num == state().boundariesCrossed) {
435          getArgList_computed = true;
436        } else {
437        }
438        state.INTERMEDIATE_VALUE |= intermediate;
439    
440        List<Expr> node = (List<Expr>) this.getChild(getArgListChildPosition());
441        return node;
442      }
443      /**
444       * @apilevel internal
445       */
446      private List<Expr> getArgList_compute() {
447          EnumConstant ec = (EnumConstant) getParent().getParent();
448          List<EnumConstant> ecs = (List<EnumConstant>)ec.getParent();
449          int idx = ecs.getIndexOfChild(ec);
450          if (idx == -1) {
451            throw new Error("internal: cannot determine numeric value of enum constant");
452          }
453          List<Expr> argList = new List<Expr>();
454          argList.add(Literal.buildStringLiteral(ec.name()));
455          argList.add(Literal.buildIntegerLiteral(idx));
456          for (Expr arg : ec.getArgs()) {
457            argList.add((Expr) arg.treeCopyNoTransform());
458          }
459          return argList;
460        }
461      /**
462       * @apilevel internal
463       */
464      public ASTNode rewriteTo() {
465        return super.rewriteTo();
466      }
467    }