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     * A resource declaration in a try with resources statement.
015     * @production ResourceDeclaration : {@link VariableDeclaration};
016     * @ast node
017     * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.ast:9
018     */
019    public class ResourceDeclaration extends VariableDeclaration 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 ResourceDeclaration clone() throws CloneNotSupportedException {
035        ResourceDeclaration node = (ResourceDeclaration)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 ResourceDeclaration copy() {
045      
046      try {
047        ResourceDeclaration node = (ResourceDeclaration) 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 ResourceDeclaration fullCopy() {
065      
066      ResourceDeclaration tree = (ResourceDeclaration) 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         * Type checking for TWR.
081         * @ast method 
082       * @aspect TryWithResources
083       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:23
084       */
085      public void typeCheck() {
086                TypeDecl typeAutoCloseable = lookupType("java.lang", "AutoCloseable");
087                if (typeAutoCloseable == null)
088                        error("java.lang.AutoCloseable not found");
089                else if (!getTypeAccess().type().instanceOf(typeAutoCloseable))
090                        error("Resource specification must declare an AutoCloseable resource");
091        }
092      /**
093       * @ast method 
094       * @aspect TryWithResources
095       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:156
096       */
097      public void nameCheck() {
098                // Special name check for resource specification
099                if (resourcePreviouslyDeclared(name()))
100                       error("A resource with the name "+name()+
101                                       " has already been declared in this try statement.");
102    
103               // Do regular name check for variable declaration
104               super.nameCheck();
105       }
106      /**
107       * @ast method 
108       * 
109       */
110      public ResourceDeclaration() {
111        super();
112    
113    
114      }
115      /**
116       * Initializes the child array to the correct size.
117       * Initializes List and Opt nta children.
118       * @apilevel internal
119       * @ast method
120       * @ast method 
121       * 
122       */
123      public void init$Children() {
124        children = new ASTNode[3];
125        setChild(new Opt(), 2);
126      }
127      /**
128       * @ast method 
129       * 
130       */
131      public ResourceDeclaration(Modifiers p0, Access p1, String p2, Opt<Expr> p3) {
132        setChild(p0, 0);
133        setChild(p1, 1);
134        setID(p2);
135        setChild(p3, 2);
136      }
137      /**
138       * @ast method 
139       * 
140       */
141      public ResourceDeclaration(Modifiers p0, Access p1, beaver.Symbol p2, Opt<Expr> p3) {
142        setChild(p0, 0);
143        setChild(p1, 1);
144        setID(p2);
145        setChild(p3, 2);
146      }
147      /**
148       * @apilevel low-level
149       * @ast method 
150       * 
151       */
152      protected int numChildren() {
153        return 3;
154      }
155      /**
156       * @apilevel internal
157       * @ast method 
158       * 
159       */
160      public boolean mayHaveRewrite() {
161        return false;
162      }
163      /**
164       * Replaces the Modifiers child.
165       * @param node The new node to replace the Modifiers child.
166       * @apilevel high-level
167       * @ast method 
168       * 
169       */
170      public void setModifiers(Modifiers node) {
171        setChild(node, 0);
172      }
173      /**
174       * Retrieves the Modifiers child.
175       * @return The current node used as the Modifiers child.
176       * @apilevel high-level
177       * @ast method 
178       * 
179       */
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       * @ast method 
189       * 
190       */
191      public Modifiers getModifiersNoTransform() {
192        return (Modifiers)getChildNoTransform(0);
193      }
194      /**
195       * Replaces the TypeAccess child.
196       * @param node The new node to replace the TypeAccess child.
197       * @apilevel high-level
198       * @ast method 
199       * 
200       */
201      public void setTypeAccess(Access node) {
202        setChild(node, 1);
203      }
204      /**
205       * Retrieves the TypeAccess child.
206       * @return The current node used as the TypeAccess child.
207       * @apilevel high-level
208       * @ast method 
209       * 
210       */
211      public Access getTypeAccess() {
212        return (Access)getChild(1);
213      }
214      /**
215       * Retrieves the TypeAccess child.
216       * <p><em>This method does not invoke AST transformations.</em></p>
217       * @return The current node used as the TypeAccess child.
218       * @apilevel low-level
219       * @ast method 
220       * 
221       */
222      public Access getTypeAccessNoTransform() {
223        return (Access)getChildNoTransform(1);
224      }
225      /**
226       * Replaces the lexeme ID.
227       * @param value The new value for the lexeme ID.
228       * @apilevel high-level
229       * @ast method 
230       * 
231       */
232      public void setID(String value) {
233        tokenString_ID = value;
234      }
235      /**
236       * JastAdd-internal setter for lexeme ID using the Beaver parser.
237       * @apilevel internal
238       * @ast method 
239       * 
240       */
241      public void setID(beaver.Symbol symbol) {
242        if(symbol.value != null && !(symbol.value instanceof String))
243          throw new UnsupportedOperationException("setID is only valid for String lexemes");
244        tokenString_ID = (String)symbol.value;
245        IDstart = symbol.getStart();
246        IDend = symbol.getEnd();
247      }
248      /**
249       * Retrieves the value for the lexeme ID.
250       * @return The value for the lexeme ID.
251       * @apilevel high-level
252       * @ast method 
253       * 
254       */
255      public String getID() {
256        return tokenString_ID != null ? tokenString_ID : "";
257      }
258      /**
259       * Replaces the optional node for the Init child. This is the {@code Opt} node containing the child Init, not the actual child!
260       * @param opt The new node to be used as the optional node for the Init child.
261       * @apilevel low-level
262       * @ast method 
263       * 
264       */
265      public void setInitOpt(Opt<Expr> opt) {
266        setChild(opt, 2);
267      }
268      /**
269       * Check whether the optional Init child exists.
270       * @return {@code true} if the optional Init child exists, {@code false} if it does not.
271       * @apilevel high-level
272       * @ast method 
273       * 
274       */
275      public boolean hasInit() {
276        return getInitOpt().getNumChild() != 0;
277      }
278      /**
279       * Retrieves the (optional) Init child.
280       * @return The Init child, if it exists. Returns {@code null} otherwise.
281       * @apilevel low-level
282       * @ast method 
283       * 
284       */
285      @SuppressWarnings({"unchecked", "cast"})
286      public Expr getInit() {
287        return (Expr)getInitOpt().getChild(0);
288      }
289      /**
290       * Replaces the (optional) Init child.
291       * @param node The new node to be used as the Init child.
292       * @apilevel high-level
293       * @ast method 
294       * 
295       */
296      public void setInit(Expr node) {
297        getInitOpt().setChild(node, 0);
298      }
299      /**
300       * @apilevel low-level
301       * @ast method 
302       * 
303       */
304      @SuppressWarnings({"unchecked", "cast"})
305      public Opt<Expr> getInitOpt() {
306        return (Opt<Expr>)getChild(2);
307      }
308      /**
309       * Retrieves the optional node for child Init. This is the {@code Opt} node containing the child Init, not the actual child!
310       * <p><em>This method does not invoke AST transformations.</em></p>
311       * @return The optional node for child Init.
312       * @apilevel low-level
313       * @ast method 
314       * 
315       */
316      @SuppressWarnings({"unchecked", "cast"})
317      public Opt<Expr> getInitOptNoTransform() {
318        return (Opt<Expr>)getChildNoTransform(2);
319      }
320      /**
321        * Inherit the lookupType attribute in ResourceDeclaration.
322        * @attribute inh
323       * @aspect TryWithResources
324       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:18
325       */
326      @SuppressWarnings({"unchecked", "cast"})
327      public TypeDecl lookupType(String packageName, String typeName) {
328          ASTNode$State state = state();
329        TypeDecl lookupType_String_String_value = getParent().Define_TypeDecl_lookupType(this, null, packageName, typeName);
330            return lookupType_String_String_value;
331      }
332      /**
333       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:13
334       * @apilevel internal
335       */
336      public NameType Define_NameType_nameType(ASTNode caller, ASTNode child) {
337        if(caller == getTypeAccessNoTransform()) {
338          return NameType.TYPE_NAME;
339        }
340        else {      return super.Define_NameType_nameType(caller, child);
341        }
342      }
343      /**
344       * @apilevel internal
345       */
346      public ASTNode rewriteTo() {
347        return super.rewriteTo();
348      }
349    }