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     * This node only exists to distinguish NTA-finally blocks from
026     * regular, non-NTA, blocks. This is required to avoid an endlessly
027     * recursive AST.
028     * @ast node
029     * @declaredat /home/jesper/git/extendj/java4/grammar/NTAFinally.ast:6
030     * @production NTAFinallyBlock : {@link Block};
031    
032     */
033    public class NTAFinallyBlock extends Block implements Cloneable {
034      /**
035       * @aspect NTAFinally
036       * @declaredat /home/jesper/git/extendj/java4/frontend/NTAFinally.jrag:91
037       */
038      private FinallyHost origin;
039      /**
040       * @aspect NTAFinally
041       * @declaredat /home/jesper/git/extendj/java4/frontend/NTAFinally.jrag:93
042       */
043      public NTAFinallyBlock(FinallyHost finallyHost) {
044        this.origin = finallyHost;
045      }
046      /**
047       * @declaredat ASTNode:1
048       */
049      public NTAFinallyBlock() {
050        super();
051      }
052      /**
053       * Initializes the child array to the correct size.
054       * Initializes List and Opt nta children.
055       * @apilevel internal
056       * @ast method
057       * @declaredat ASTNode:10
058       */
059      public void init$Children() {
060        children = new ASTNode[1];
061        setChild(new List(), 0);
062      }
063      /**
064       * @declaredat ASTNode:14
065       */
066      public NTAFinallyBlock(List<Stmt> p0) {
067        setChild(p0, 0);
068      }
069      /**
070       * @apilevel low-level
071       * @declaredat ASTNode:20
072       */
073      protected int numChildren() {
074        return 1;
075      }
076      /**
077       * @apilevel internal
078       * @declaredat ASTNode:26
079       */
080      public boolean mayHaveRewrite() {
081        return false;
082      }
083      /**
084       * @apilevel internal
085       * @declaredat ASTNode:32
086       */
087      public void flushAttrCache() {
088        super.flushAttrCache();
089      }
090      /**
091       * @apilevel internal
092       * @declaredat ASTNode:38
093       */
094      public void flushCollectionCache() {
095        super.flushCollectionCache();
096      }
097      /**
098       * @apilevel internal
099       * @declaredat ASTNode:44
100       */
101      public void flushRewriteCache() {
102        super.flushRewriteCache();
103      }
104      /**
105       * @apilevel internal
106       * @declaredat ASTNode:50
107       */
108      public NTAFinallyBlock clone() throws CloneNotSupportedException {
109        NTAFinallyBlock node = (NTAFinallyBlock) super.clone();
110        return node;
111      }
112      /**
113       * @apilevel internal
114       * @declaredat ASTNode:57
115       */
116      public NTAFinallyBlock copy() {
117        try {
118          NTAFinallyBlock node = (NTAFinallyBlock) clone();
119          node.parent = null;
120          if (children != null) {
121            node.children = (ASTNode[]) children.clone();
122          }
123          return node;
124        } catch (CloneNotSupportedException e) {
125          throw new Error("Error: clone not supported for " + getClass().getName());
126        }
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       * @deprecated Please use treeCopy or treeCopyNoTransform instead
134       * @declaredat ASTNode:76
135       */
136      @Deprecated
137      public NTAFinallyBlock fullCopy() {
138        return treeCopyNoTransform();
139      }
140      /**
141       * Create a deep copy of the AST subtree at this node.
142       * The copy is dangling, i.e. has no parent.
143       * @return dangling copy of the subtree at this node
144       * @apilevel low-level
145       * @declaredat ASTNode:86
146       */
147      public NTAFinallyBlock treeCopyNoTransform() {
148        NTAFinallyBlock tree = (NTAFinallyBlock) copy();
149        if (children != null) {
150          for (int i = 0; i < children.length; ++i) {
151            ASTNode child = (ASTNode) children[i];
152            if (child != null) {
153              child = child.treeCopyNoTransform();
154              tree.setChild(child, i);
155            }
156          }
157        }
158        return tree;
159      }
160      /**
161       * Create a deep copy of the AST subtree at this node.
162       * The subtree of this node is traversed to trigger rewrites before copy.
163       * The copy is dangling, i.e. has no parent.
164       * @return dangling copy of the subtree at this node
165       * @apilevel low-level
166       * @declaredat ASTNode:106
167       */
168      public NTAFinallyBlock treeCopy() {
169        doFullTraversal();
170        return treeCopyNoTransform();
171      }
172      /**
173       * @apilevel internal
174       * @declaredat ASTNode:113
175       */
176      protected boolean is$Equal(ASTNode node) {
177        return super.is$Equal(node);    
178      }
179      /**
180       * Replaces the Stmt list.
181       * @param list The new list node to be used as the Stmt list.
182       * @apilevel high-level
183       */
184      public void setStmtList(List<Stmt> list) {
185        setChild(list, 0);
186      }
187      /**
188       * Retrieves the number of children in the Stmt list.
189       * @return Number of children in the Stmt list.
190       * @apilevel high-level
191       */
192      public int getNumStmt() {
193        return getStmtList().getNumChild();
194      }
195      /**
196       * Retrieves the number of children in the Stmt list.
197       * Calling this method will not trigger rewrites.
198       * @return Number of children in the Stmt list.
199       * @apilevel low-level
200       */
201      public int getNumStmtNoTransform() {
202        return getStmtListNoTransform().getNumChildNoTransform();
203      }
204      /**
205       * Retrieves the element at index {@code i} in the Stmt list.
206       * @param i Index of the element to return.
207       * @return The element at position {@code i} in the Stmt list.
208       * @apilevel high-level
209       */
210      public Stmt getStmt(int i) {
211        return (Stmt) getStmtList().getChild(i);
212      }
213      /**
214       * Check whether the Stmt list has any children.
215       * @return {@code true} if it has at least one child, {@code false} otherwise.
216       * @apilevel high-level
217       */
218      public boolean hasStmt() {
219        return getStmtList().getNumChild() != 0;
220      }
221      /**
222       * Append an element to the Stmt list.
223       * @param node The element to append to the Stmt list.
224       * @apilevel high-level
225       */
226      public void addStmt(Stmt node) {
227        List<Stmt> list = (parent == null) ? getStmtListNoTransform() : getStmtList();
228        list.addChild(node);
229      }
230      /**
231       * @apilevel low-level
232       */
233      public void addStmtNoTransform(Stmt node) {
234        List<Stmt> list = getStmtListNoTransform();
235        list.addChild(node);
236      }
237      /**
238       * Replaces the Stmt list element at index {@code i} with the new node {@code node}.
239       * @param node The new node to replace the old list element.
240       * @param i The list index of the node to be replaced.
241       * @apilevel high-level
242       */
243      public void setStmt(Stmt node, int i) {
244        List<Stmt> list = getStmtList();
245        list.setChild(node, i);
246      }
247      /**
248       * Retrieves the Stmt list.
249       * @return The node representing the Stmt list.
250       * @apilevel high-level
251       */
252      @ASTNodeAnnotation.ListChild(name="Stmt")
253      public List<Stmt> getStmtList() {
254        List<Stmt> list = (List<Stmt>) getChild(0);
255        return list;
256      }
257      /**
258       * Retrieves the Stmt list.
259       * <p><em>This method does not invoke AST transformations.</em></p>
260       * @return The node representing the Stmt list.
261       * @apilevel low-level
262       */
263      public List<Stmt> getStmtListNoTransform() {
264        return (List<Stmt>) getChildNoTransform(0);
265      }
266      /**
267       * Retrieves the Stmt list.
268       * @return The node representing the Stmt list.
269       * @apilevel high-level
270       */
271      public List<Stmt> getStmts() {
272        return getStmtList();
273      }
274      /**
275       * Retrieves the Stmt list.
276       * <p><em>This method does not invoke AST transformations.</em></p>
277       * @return The node representing the Stmt list.
278       * @apilevel low-level
279       */
280      public List<Stmt> getStmtsNoTransform() {
281        return getStmtListNoTransform();
282      }
283      /**
284       * @declaredat /home/jesper/git/extendj/java4/frontend/BranchTarget.jrag:262
285       * @apilevel internal
286       */
287      public FinallyHost Define_enclosingFinally(ASTNode caller, ASTNode child, Stmt branch) {
288        int childIndex = this.getIndexOfChild(caller);
289        return origin.enclosingFinally(branch);
290      }
291      protected boolean canDefine_enclosingFinally(ASTNode caller, ASTNode child, Stmt branch) {
292        return true;
293      }
294      /**
295       * @apilevel internal
296       */
297      public ASTNode rewriteTo() {
298        return super.rewriteTo();
299      }
300    }