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     * The JSR 334 try with resources statement.
015     * @production TryWithResources : {@link TryStmt} ::= <span class="component">Resource:{@link ResourceDeclaration}*</span> <span class="component">{@link Block}</span> <span class="component">{@link CatchClause}*</span> <span class="component">[Finally:{@link Block}]</span>;
016     * @ast node
017     * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.ast:4
018     */
019    public class TryWithResources extends TryStmt implements Cloneable, VariableScope {
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 TryWithResources clone() throws CloneNotSupportedException {
035        TryWithResources node = (TryWithResources)super.clone();
036        node.localLookup_String_values = null;
037        node.localVariableDeclaration_String_values = null;
038        node.isDAafter_Variable_values = null;
039        node.catchableException_TypeDecl_values = null;
040        node.getTransformed_computed = false;
041        node.getTransformed_value = null;
042        node.handlesException_TypeDecl_values = null;
043        node.typeError_computed = false;
044        node.typeError_value = null;
045        node.typeRuntimeException_computed = false;
046        node.typeRuntimeException_value = null;
047        node.lookupVariable_String_values = null;
048        node.in$Circle(false);
049        node.is$Final(false);
050        return node;
051      }
052    /**
053     * @apilevel internal
054     */
055      @SuppressWarnings({"unchecked", "cast"})
056    public TryWithResources copy() {
057      
058      try {
059        TryWithResources node = (TryWithResources) clone();
060        node.parent = null;
061        if(children != null)
062          node.children = (ASTNode[]) children.clone();
063        
064        return node;
065      } catch (CloneNotSupportedException e) {
066        throw new Error("Error: clone not supported for " + getClass().getName());
067      }
068      
069    }/**
070     * Create a deep copy of the AST subtree at this node.
071     * The copy is dangling, i.e. has no parent.
072     * @return dangling copy of the subtree at this node
073     * @apilevel low-level
074     */
075      @SuppressWarnings({"unchecked", "cast"})
076    public TryWithResources fullCopy() {
077      
078      TryWithResources tree = (TryWithResources) copy();
079      if (children != null) {
080        for (int i = 0; i < children.length; ++i) {
081          
082          ASTNode child = (ASTNode) children[i];
083          if(child != null) {
084            child = child.fullCopy();
085            tree.setChild(child, i);
086          }
087        }
088      }
089      return tree;
090      
091    }  /**
092         * Exception error checks.
093         * @ast method 
094       * @aspect TryWithResources
095       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:40
096       */
097      public void exceptionHandling() {
098    
099                // Check exception handling of exceptions on auto closing of resource
100               for (ResourceDeclaration resource : getResourceList()) {
101                       MethodDecl close = lookupClose(resource);
102                       if (close == null) continue;
103                       for (Access exception : close.getExceptionList()) {
104                               TypeDecl exceptionType = exception.type();
105                               if (!twrHandlesException(exceptionType))
106                                       error("automatic closing of resource "+resource.name()+
107                                                       " may raise the uncaught exception "+exceptionType.fullName()+"; "+
108                                                       "it must be caught or declared as being thrown");
109                       }
110               }
111       }
112      /**
113        * Returns true if the try-with-resources statement can throw
114        * an exception of type (or a subtype of) catchType.
115        * @ast method 
116       * @aspect TryWithResources
117       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:181
118       */
119      protected boolean reachedException(TypeDecl catchType) {
120               boolean found = false;
121               // found is true if the exception type is caught by a catch clause
122               for(int i = 0; i < getNumCatchClause() && !found; i++)
123                       if(getCatchClause(i).handles(catchType))
124                               found = true;
125               // if an exception is thrown in the block and the exception is not caught and
126               // either there is no finally block or the finally block can complete normally
127               if(!found && (!hasFinally() || getFinally().canCompleteNormally()) )
128                       if(catchableException(catchType))
129                               return true;
130               // even if the exception is caught by the catch clauses they may 
131               // throw new exceptions
132               for(int i = 0; i < getNumCatchClause(); i++)
133                       if(getCatchClause(i).reachedException(catchType))
134                               return true;
135               return hasFinally() && getFinally().reachedException(catchType);
136       }
137      /**
138        * Pretty printing of try-with-resources
139        * @ast method 
140       * @aspect PrettyPrint
141       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:244
142       */
143      public void toString(StringBuffer sb) {
144               sb.append(indent() + "try (");
145               for (ResourceDeclaration resource : getResourceList()) {
146                       sb.append(resource.toString());
147               }
148               sb.append(") ");
149               getBlock().toString(sb);
150               for (CatchClause cc : getCatchClauseList()) {
151                       sb.append(" ");
152                       cc.toString(sb);
153               }
154               if (hasFinally()) {
155                       sb.append(" finally ");
156                       getFinally().toString(sb);
157               }
158       }
159      /**
160        * Code generation for the try-with-resources statement.
161        * @ast method 
162       * @aspect TryWithResources
163       * @declaredat /home/jesper/svn/JastAddJ/Java7Backend/TryWithResources.jrag:60
164       */
165      public void createBCode(CodeGeneration gen) {
166    
167               getTransformed().createBCode(gen);
168       }
169      /**
170       * @ast method 
171       * 
172       */
173      public TryWithResources() {
174        super();
175    
176    
177      }
178      /**
179       * Initializes the child array to the correct size.
180       * Initializes List and Opt nta children.
181       * @apilevel internal
182       * @ast method
183       * @ast method 
184       * 
185       */
186      public void init$Children() {
187        children = new ASTNode[4];
188        setChild(new List(), 0);
189        setChild(new List(), 2);
190        setChild(new Opt(), 3);
191      }
192      /**
193       * @ast method 
194       * 
195       */
196      public TryWithResources(List<ResourceDeclaration> p0, Block p1, List<CatchClause> p2, Opt<Block> p3) {
197        setChild(p0, 0);
198        setChild(p1, 1);
199        setChild(p2, 2);
200        setChild(p3, 3);
201      }
202      /**
203       * @apilevel low-level
204       * @ast method 
205       * 
206       */
207      protected int numChildren() {
208        return 4;
209      }
210      /**
211       * @apilevel internal
212       * @ast method 
213       * 
214       */
215      public boolean mayHaveRewrite() {
216        return false;
217      }
218      /**
219       * Replaces the Resource list.
220       * @param list The new list node to be used as the Resource list.
221       * @apilevel high-level
222       * @ast method 
223       * 
224       */
225      public void setResourceList(List<ResourceDeclaration> list) {
226        setChild(list, 0);
227      }
228      /**
229       * Retrieves the number of children in the Resource list.
230       * @return Number of children in the Resource list.
231       * @apilevel high-level
232       * @ast method 
233       * 
234       */
235      public int getNumResource() {
236        return getResourceList().getNumChild();
237      }
238      /**
239       * Retrieves the number of children in the Resource list.
240       * Calling this method will not trigger rewrites..
241       * @return Number of children in the Resource list.
242       * @apilevel low-level
243       * @ast method 
244       * 
245       */
246      public int getNumResourceNoTransform() {
247        return getResourceListNoTransform().getNumChildNoTransform();
248      }
249      /**
250       * Retrieves the element at index {@code i} in the Resource list..
251       * @param i Index of the element to return.
252       * @return The element at position {@code i} in the Resource list.
253       * @apilevel high-level
254       * @ast method 
255       * 
256       */
257      @SuppressWarnings({"unchecked", "cast"})
258      public ResourceDeclaration getResource(int i) {
259        return (ResourceDeclaration)getResourceList().getChild(i);
260      }
261      /**
262       * Append an element to the Resource list.
263       * @param node The element to append to the Resource list.
264       * @apilevel high-level
265       * @ast method 
266       * 
267       */
268      public void addResource(ResourceDeclaration node) {
269        List<ResourceDeclaration> list = (parent == null || state == null) ? getResourceListNoTransform() : getResourceList();
270        list.addChild(node);
271      }
272      /**
273       * @apilevel low-level
274       * @ast method 
275       * 
276       */
277      public void addResourceNoTransform(ResourceDeclaration node) {
278        List<ResourceDeclaration> list = getResourceListNoTransform();
279        list.addChild(node);
280      }
281      /**
282       * Replaces the Resource list element at index {@code i} with the new node {@code node}.
283       * @param node The new node to replace the old list element.
284       * @param i The list index of the node to be replaced.
285       * @apilevel high-level
286       * @ast method 
287       * 
288       */
289      public void setResource(ResourceDeclaration node, int i) {
290        List<ResourceDeclaration> list = getResourceList();
291        list.setChild(node, i);
292      }
293      /**
294       * Retrieves the Resource list.
295       * @return The node representing the Resource list.
296       * @apilevel high-level
297       * @ast method 
298       * 
299       */
300      public List<ResourceDeclaration> getResources() {
301        return getResourceList();
302      }
303      /**
304       * Retrieves the Resource list.
305       * <p><em>This method does not invoke AST transformations.</em></p>
306       * @return The node representing the Resource list.
307       * @apilevel low-level
308       * @ast method 
309       * 
310       */
311      public List<ResourceDeclaration> getResourcesNoTransform() {
312        return getResourceListNoTransform();
313      }
314      /**
315       * Retrieves the Resource list.
316       * @return The node representing the Resource list.
317       * @apilevel high-level
318       * @ast method 
319       * 
320       */
321      @SuppressWarnings({"unchecked", "cast"})
322      public List<ResourceDeclaration> getResourceList() {
323        List<ResourceDeclaration> list = (List<ResourceDeclaration>)getChild(0);
324        list.getNumChild();
325        return list;
326      }
327      /**
328       * Retrieves the Resource list.
329       * <p><em>This method does not invoke AST transformations.</em></p>
330       * @return The node representing the Resource list.
331       * @apilevel low-level
332       * @ast method 
333       * 
334       */
335      @SuppressWarnings({"unchecked", "cast"})
336      public List<ResourceDeclaration> getResourceListNoTransform() {
337        return (List<ResourceDeclaration>)getChildNoTransform(0);
338      }
339      /**
340       * Replaces the Block child.
341       * @param node The new node to replace the Block child.
342       * @apilevel high-level
343       * @ast method 
344       * 
345       */
346      public void setBlock(Block node) {
347        setChild(node, 1);
348      }
349      /**
350       * Retrieves the Block child.
351       * @return The current node used as the Block child.
352       * @apilevel high-level
353       * @ast method 
354       * 
355       */
356      public Block getBlock() {
357        return (Block)getChild(1);
358      }
359      /**
360       * Retrieves the Block child.
361       * <p><em>This method does not invoke AST transformations.</em></p>
362       * @return The current node used as the Block child.
363       * @apilevel low-level
364       * @ast method 
365       * 
366       */
367      public Block getBlockNoTransform() {
368        return (Block)getChildNoTransform(1);
369      }
370      /**
371       * Replaces the CatchClause list.
372       * @param list The new list node to be used as the CatchClause list.
373       * @apilevel high-level
374       * @ast method 
375       * 
376       */
377      public void setCatchClauseList(List<CatchClause> list) {
378        setChild(list, 2);
379      }
380      /**
381       * Retrieves the number of children in the CatchClause list.
382       * @return Number of children in the CatchClause list.
383       * @apilevel high-level
384       * @ast method 
385       * 
386       */
387      public int getNumCatchClause() {
388        return getCatchClauseList().getNumChild();
389      }
390      /**
391       * Retrieves the number of children in the CatchClause list.
392       * Calling this method will not trigger rewrites..
393       * @return Number of children in the CatchClause list.
394       * @apilevel low-level
395       * @ast method 
396       * 
397       */
398      public int getNumCatchClauseNoTransform() {
399        return getCatchClauseListNoTransform().getNumChildNoTransform();
400      }
401      /**
402       * Retrieves the element at index {@code i} in the CatchClause list..
403       * @param i Index of the element to return.
404       * @return The element at position {@code i} in the CatchClause list.
405       * @apilevel high-level
406       * @ast method 
407       * 
408       */
409      @SuppressWarnings({"unchecked", "cast"})
410      public CatchClause getCatchClause(int i) {
411        return (CatchClause)getCatchClauseList().getChild(i);
412      }
413      /**
414       * Append an element to the CatchClause list.
415       * @param node The element to append to the CatchClause list.
416       * @apilevel high-level
417       * @ast method 
418       * 
419       */
420      public void addCatchClause(CatchClause node) {
421        List<CatchClause> list = (parent == null || state == null) ? getCatchClauseListNoTransform() : getCatchClauseList();
422        list.addChild(node);
423      }
424      /**
425       * @apilevel low-level
426       * @ast method 
427       * 
428       */
429      public void addCatchClauseNoTransform(CatchClause node) {
430        List<CatchClause> list = getCatchClauseListNoTransform();
431        list.addChild(node);
432      }
433      /**
434       * Replaces the CatchClause list element at index {@code i} with the new node {@code node}.
435       * @param node The new node to replace the old list element.
436       * @param i The list index of the node to be replaced.
437       * @apilevel high-level
438       * @ast method 
439       * 
440       */
441      public void setCatchClause(CatchClause node, int i) {
442        List<CatchClause> list = getCatchClauseList();
443        list.setChild(node, i);
444      }
445      /**
446       * Retrieves the CatchClause list.
447       * @return The node representing the CatchClause list.
448       * @apilevel high-level
449       * @ast method 
450       * 
451       */
452      public List<CatchClause> getCatchClauses() {
453        return getCatchClauseList();
454      }
455      /**
456       * Retrieves the CatchClause list.
457       * <p><em>This method does not invoke AST transformations.</em></p>
458       * @return The node representing the CatchClause list.
459       * @apilevel low-level
460       * @ast method 
461       * 
462       */
463      public List<CatchClause> getCatchClausesNoTransform() {
464        return getCatchClauseListNoTransform();
465      }
466      /**
467       * Retrieves the CatchClause list.
468       * @return The node representing the CatchClause list.
469       * @apilevel high-level
470       * @ast method 
471       * 
472       */
473      @SuppressWarnings({"unchecked", "cast"})
474      public List<CatchClause> getCatchClauseList() {
475        List<CatchClause> list = (List<CatchClause>)getChild(2);
476        list.getNumChild();
477        return list;
478      }
479      /**
480       * Retrieves the CatchClause list.
481       * <p><em>This method does not invoke AST transformations.</em></p>
482       * @return The node representing the CatchClause list.
483       * @apilevel low-level
484       * @ast method 
485       * 
486       */
487      @SuppressWarnings({"unchecked", "cast"})
488      public List<CatchClause> getCatchClauseListNoTransform() {
489        return (List<CatchClause>)getChildNoTransform(2);
490      }
491      /**
492       * Replaces the optional node for the Finally child. This is the {@code Opt} node containing the child Finally, not the actual child!
493       * @param opt The new node to be used as the optional node for the Finally child.
494       * @apilevel low-level
495       * @ast method 
496       * 
497       */
498      public void setFinallyOpt(Opt<Block> opt) {
499        setChild(opt, 3);
500      }
501      /**
502       * Check whether the optional Finally child exists.
503       * @return {@code true} if the optional Finally child exists, {@code false} if it does not.
504       * @apilevel high-level
505       * @ast method 
506       * 
507       */
508      public boolean hasFinally() {
509        return getFinallyOpt().getNumChild() != 0;
510      }
511      /**
512       * Retrieves the (optional) Finally child.
513       * @return The Finally child, if it exists. Returns {@code null} otherwise.
514       * @apilevel low-level
515       * @ast method 
516       * 
517       */
518      @SuppressWarnings({"unchecked", "cast"})
519      public Block getFinally() {
520        return (Block)getFinallyOpt().getChild(0);
521      }
522      /**
523       * Replaces the (optional) Finally child.
524       * @param node The new node to be used as the Finally child.
525       * @apilevel high-level
526       * @ast method 
527       * 
528       */
529      public void setFinally(Block node) {
530        getFinallyOpt().setChild(node, 0);
531      }
532      /**
533       * @apilevel low-level
534       * @ast method 
535       * 
536       */
537      @SuppressWarnings({"unchecked", "cast"})
538      public Opt<Block> getFinallyOpt() {
539        return (Opt<Block>)getChild(3);
540      }
541      /**
542       * Retrieves the optional node for child Finally. This is the {@code Opt} node containing the child Finally, not the actual child!
543       * <p><em>This method does not invoke AST transformations.</em></p>
544       * @return The optional node for child Finally.
545       * @apilevel low-level
546       * @ast method 
547       * 
548       */
549      @SuppressWarnings({"unchecked", "cast"})
550      public Opt<Block> getFinallyOptNoTransform() {
551        return (Opt<Block>)getChildNoTransform(3);
552      }
553      /**
554        * This attribute computes whether or not the TWR statement
555        * has a catch clause which handles the exception.
556        * @attribute syn
557       * @aspect TryWithResources
558       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:60
559       */
560      public boolean catchHandlesException(TypeDecl exceptionType) {
561        ASTNode$State state = state();
562        try {
563               for (int i = 0; i < getNumCatchClause(); i++)
564                       if (getCatchClause(i).handles(exceptionType))
565                               return true;
566               return false;
567       }
568        finally {
569        }
570      }
571      /**
572        * Returns true if exceptions of type exceptionType are handled
573        * in the try-with-resources statement or any containing statement
574        * within the directly enclosing method or initializer block.
575        * @attribute syn
576       * @aspect TryWithResources
577       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:72
578       */
579      public boolean twrHandlesException(TypeDecl exceptionType) {
580        ASTNode$State state = state();
581        try {
582               if (catchHandlesException(exceptionType))
583                       return true;
584               if (hasFinally() && !getFinally().canCompleteNormally())
585                       return true;
586               return handlesException(exceptionType);
587       }
588        finally {
589        }
590      }
591      /**
592        * Lookup the close method declaration for the resource which is being used.
593        * @attribute syn
594       * @aspect TryWithResources
595       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:95
596       */
597      public MethodDecl lookupClose(ResourceDeclaration resource) {
598        ASTNode$State state = state();
599        try {
600               TypeDecl resourceType = resource.getTypeAccess().type();
601               for (MethodDecl method : (Collection<MethodDecl>) resourceType.memberMethods("close")) {
602                       if (method.getNumParameter() == 0) {
603                               return method;
604                       }
605               }
606               return null;
607               /* We can't throw a runtime exception here. If there is no close method it
608                * likely means that the resource type is not a subtype of java.lang.AutoCloseable
609                * and type checking will report this error.
610                */
611               //throw new RuntimeException("close() not found for resource type "+resourceType.fullName());
612       }
613        finally {
614        }
615      }
616      protected java.util.Map localLookup_String_values;
617      /**
618       * @attribute syn
619       * @aspect TryWithResources
620       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:128
621       */
622      @SuppressWarnings({"unchecked", "cast"})
623      public SimpleSet localLookup(String name) {
624        Object _parameters = name;
625        if(localLookup_String_values == null) localLookup_String_values = new java.util.HashMap(4);
626        if(localLookup_String_values.containsKey(_parameters)) {
627          return (SimpleSet)localLookup_String_values.get(_parameters);
628        }
629          ASTNode$State state = state();
630      int num = state.boundariesCrossed;
631      boolean isFinal = this.is$Final();
632        SimpleSet localLookup_String_value = localLookup_compute(name);
633      if(isFinal && num == state().boundariesCrossed){ localLookup_String_values.put(_parameters, localLookup_String_value); }
634            return localLookup_String_value;
635      }
636      /**
637       * @apilevel internal
638       */
639      private SimpleSet localLookup_compute(String name) {
640               VariableDeclaration v = localVariableDeclaration(name);
641               if (v != null) return v;
642               return lookupVariable(name);
643       }
644      protected java.util.Map localVariableDeclaration_String_values;
645      /**
646       * @attribute syn
647       * @aspect TryWithResources
648       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:133
649       */
650      @SuppressWarnings({"unchecked", "cast"})
651      public VariableDeclaration localVariableDeclaration(String name) {
652        Object _parameters = name;
653        if(localVariableDeclaration_String_values == null) localVariableDeclaration_String_values = new java.util.HashMap(4);
654        if(localVariableDeclaration_String_values.containsKey(_parameters)) {
655          return (VariableDeclaration)localVariableDeclaration_String_values.get(_parameters);
656        }
657          ASTNode$State state = state();
658      int num = state.boundariesCrossed;
659      boolean isFinal = this.is$Final();
660        VariableDeclaration localVariableDeclaration_String_value = localVariableDeclaration_compute(name);
661      if(isFinal && num == state().boundariesCrossed){ localVariableDeclaration_String_values.put(_parameters, localVariableDeclaration_String_value); }
662            return localVariableDeclaration_String_value;
663      }
664      /**
665       * @apilevel internal
666       */
667      private VariableDeclaration localVariableDeclaration_compute(String name) {
668               for (ResourceDeclaration resource : getResourceList())
669                       if (resource.declaresVariable(name))
670                               return resource;
671               return null;
672       }
673      protected java.util.Map isDAafter_Variable_values;
674      /**
675       * @attribute syn
676       * @aspect TryWithResources
677       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:167
678       */
679      @SuppressWarnings({"unchecked", "cast"})
680      public boolean isDAafter(Variable v) {
681        Object _parameters = v;
682        if(isDAafter_Variable_values == null) isDAafter_Variable_values = new java.util.HashMap(4);
683        if(isDAafter_Variable_values.containsKey(_parameters)) {
684          return ((Boolean)isDAafter_Variable_values.get(_parameters)).booleanValue();
685        }
686          ASTNode$State state = state();
687      int num = state.boundariesCrossed;
688      boolean isFinal = this.is$Final();
689        boolean isDAafter_Variable_value = isDAafter_compute(v);
690      if(isFinal && num == state().boundariesCrossed){ isDAafter_Variable_values.put(_parameters, Boolean.valueOf(isDAafter_Variable_value)); }
691            return isDAafter_Variable_value;
692      }
693      /**
694       * @apilevel internal
695       */
696      private boolean isDAafter_compute(Variable v) {  return getBlock().isDAafter(v);  }
697      /**
698        * True if the automatic closing of resources in this try-with-resources statement
699        * may throw an exception of type catchType.
700        * @attribute syn
701       * @aspect TryWithResources
702       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:204
703       */
704      public boolean resourceClosingException(TypeDecl catchType) {
705        ASTNode$State state = state();
706        try {
707               for (ResourceDeclaration resource : getResourceList()) {
708                       MethodDecl close = lookupClose(resource);
709                       if (close == null) continue;
710                       for (Access exception : close.getExceptionList()) {
711                               TypeDecl exceptionType = exception.type();
712                               if (catchType.mayCatch(exception.type()))
713                                       return true;
714                       }
715               }
716               return false;
717       }
718        finally {
719        }
720      }
721      /**
722        * True if the resource initialization of this try-with-resources statement
723        * may throw an exception of type catchType.
724        * @attribute syn
725       * @aspect TryWithResources
726       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:221
727       */
728      public boolean resourceInitializationException(TypeDecl catchType) {
729        ASTNode$State state = state();
730        try {
731               for (ResourceDeclaration resource : getResourceList()) {
732                       if (resource.reachedException(catchType))
733                               return true;
734               }
735               return false;
736       }
737        finally {
738        }
739      }
740      protected java.util.Map catchableException_TypeDecl_values;
741      /**
742        * @see AST.TryStmt#catchableException(TypeDecl) TryStmt.catchableException(TypeDecl)
743        * @attribute syn
744       * @aspect TryWithResources
745       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:232
746       */
747      @SuppressWarnings({"unchecked", "cast"})
748      public boolean catchableException(TypeDecl type) {
749        Object _parameters = type;
750        if(catchableException_TypeDecl_values == null) catchableException_TypeDecl_values = new java.util.HashMap(4);
751        if(catchableException_TypeDecl_values.containsKey(_parameters)) {
752          return ((Boolean)catchableException_TypeDecl_values.get(_parameters)).booleanValue();
753        }
754          ASTNode$State state = state();
755      int num = state.boundariesCrossed;
756      boolean isFinal = this.is$Final();
757        boolean catchableException_TypeDecl_value = catchableException_compute(type);
758      if(isFinal && num == state().boundariesCrossed){ catchableException_TypeDecl_values.put(_parameters, Boolean.valueOf(catchableException_TypeDecl_value)); }
759            return catchableException_TypeDecl_value;
760      }
761      /**
762       * @apilevel internal
763       */
764      private boolean catchableException_compute(TypeDecl type) {  return getBlock().reachedException(type) ||
765                       resourceClosingException(type) ||
766                       resourceInitializationException(type);  }
767      /**
768       * @apilevel internal
769       */
770      protected boolean getTransformed_computed = false;
771      /**
772       * @apilevel internal
773       */
774      protected Stmt getTransformed_value;
775      /**
776        * An NTA which is used for code generation.
777        *
778        * This NTA will handle the recursive nature of code
779        * generation for try-with-resources statements.
780        * @attribute syn
781       * @aspect TryWithResources
782       * @declaredat /home/jesper/svn/JastAddJ/Java7Backend/TryWithResources.jrag:17
783       */
784      @SuppressWarnings({"unchecked", "cast"})
785      public Stmt getTransformed() {
786        if(getTransformed_computed) {
787          return getTransformed_value;
788        }
789          ASTNode$State state = state();
790      int num = state.boundariesCrossed;
791      boolean isFinal = this.is$Final();
792        getTransformed_value = getTransformed_compute();
793        getTransformed_value.setParent(this);
794        getTransformed_value.is$Final = true;
795      if(true){ getTransformed_computed = true; }
796            return getTransformed_value;
797      }
798      /**
799       * @apilevel internal
800       */
801      private Stmt getTransformed_compute() {
802               if (getNumCatchClause() == 0 && !hasFinally()) {
803                       // transform to BasicTWR
804                       Block block;
805                       if (getNumResource() == 1) {
806                               block = (Block) getBlock().cloneSubtree();
807                       } else {
808                               block = new Block();
809                               List<ResourceDeclaration> resourceListTail =
810                                       new List<ResourceDeclaration>();
811                               for (int i = 1; i < getNumResource(); ++i) {
812                                       resourceListTail.add((ResourceDeclaration)
813                                                       getResource(i).cloneSubtree());
814                               }
815                               block.addStmt(new TryWithResources(
816                                                       resourceListTail,
817                                                       (Block) getBlock().cloneSubtree(),
818                                                       new List<CatchClause>(),
819                                                       new Opt<Block>()));
820                       }
821                       return new BasicTWR(
822                                       (ResourceDeclaration)
823                                       getResource(0).cloneSubtree(),
824                                       block);
825               } else {
826                       // transform to surrounding try stmt
827                       Block block = new Block();
828                       block.addStmt(new TryWithResources(
829                                               (List<ResourceDeclaration>)
830                                               getResourceList().cloneSubtree(),
831                                               (Block) getBlock().cloneSubtree(),
832                                               new List<CatchClause>(),
833                                               new Opt<Block>()));
834    
835                       return new TryStmt(block,
836                                       (List<CatchClause>) getCatchClauseList().cloneSubtree(),
837                                       (Opt<Block>) getFinallyOpt().cloneSubtree());
838               }
839       }
840      protected java.util.Map handlesException_TypeDecl_values;
841      /**
842        * Inherit the handlesException attribute from methoddecl.
843        * @attribute inh
844       * @aspect TryWithResources
845       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:83
846       */
847      @SuppressWarnings({"unchecked", "cast"})
848      public boolean handlesException(TypeDecl exceptionType) {
849        Object _parameters = exceptionType;
850        if(handlesException_TypeDecl_values == null) handlesException_TypeDecl_values = new java.util.HashMap(4);
851        if(handlesException_TypeDecl_values.containsKey(_parameters)) {
852          return ((Boolean)handlesException_TypeDecl_values.get(_parameters)).booleanValue();
853        }
854          ASTNode$State state = state();
855      int num = state.boundariesCrossed;
856      boolean isFinal = this.is$Final();
857        boolean handlesException_TypeDecl_value = getParent().Define_boolean_handlesException(this, null, exceptionType);
858      if(isFinal && num == state().boundariesCrossed){ handlesException_TypeDecl_values.put(_parameters, Boolean.valueOf(handlesException_TypeDecl_value)); }
859            return handlesException_TypeDecl_value;
860      }
861      /**
862       * @apilevel internal
863       */
864      protected boolean typeError_computed = false;
865      /**
866       * @apilevel internal
867       */
868      protected TypeDecl typeError_value;
869      /**
870       * @attribute inh
871       * @aspect TryWithResources
872       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:110
873       */
874      @SuppressWarnings({"unchecked", "cast"})
875      public TypeDecl typeError() {
876        if(typeError_computed) {
877          return typeError_value;
878        }
879          ASTNode$State state = state();
880      int num = state.boundariesCrossed;
881      boolean isFinal = this.is$Final();
882        typeError_value = getParent().Define_TypeDecl_typeError(this, null);
883      if(isFinal && num == state().boundariesCrossed){ typeError_computed = true; }
884            return typeError_value;
885      }
886      /**
887       * @apilevel internal
888       */
889      protected boolean typeRuntimeException_computed = false;
890      /**
891       * @apilevel internal
892       */
893      protected TypeDecl typeRuntimeException_value;
894      /**
895       * @attribute inh
896       * @aspect TryWithResources
897       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:111
898       */
899      @SuppressWarnings({"unchecked", "cast"})
900      public TypeDecl typeRuntimeException() {
901        if(typeRuntimeException_computed) {
902          return typeRuntimeException_value;
903        }
904          ASTNode$State state = state();
905      int num = state.boundariesCrossed;
906      boolean isFinal = this.is$Final();
907        typeRuntimeException_value = getParent().Define_TypeDecl_typeRuntimeException(this, null);
908      if(isFinal && num == state().boundariesCrossed){ typeRuntimeException_computed = true; }
909            return typeRuntimeException_value;
910      }
911      protected java.util.Map lookupVariable_String_values;
912      /**
913       * @attribute inh
914       * @aspect TryWithResources
915       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:141
916       */
917      @SuppressWarnings({"unchecked", "cast"})
918      public SimpleSet lookupVariable(String name) {
919        Object _parameters = name;
920        if(lookupVariable_String_values == null) lookupVariable_String_values = new java.util.HashMap(4);
921        if(lookupVariable_String_values.containsKey(_parameters)) {
922          return (SimpleSet)lookupVariable_String_values.get(_parameters);
923        }
924          ASTNode$State state = state();
925      int num = state.boundariesCrossed;
926      boolean isFinal = this.is$Final();
927        SimpleSet lookupVariable_String_value = getParent().Define_SimpleSet_lookupVariable(this, null, name);
928      if(isFinal && num == state().boundariesCrossed){ lookupVariable_String_values.put(_parameters, lookupVariable_String_value); }
929            return lookupVariable_String_value;
930      }
931      /**
932       * @attribute inh
933       * @aspect TryWithResources
934       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:145
935       */
936      @SuppressWarnings({"unchecked", "cast"})
937      public boolean resourcePreviouslyDeclared(String name) {
938          ASTNode$State state = state();
939        boolean resourcePreviouslyDeclared_String_value = getParent().Define_boolean_resourcePreviouslyDeclared(this, null, name);
940            return resourcePreviouslyDeclared_String_value;
941      }
942      /**
943       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:88
944       * @apilevel internal
945       */
946      public boolean Define_boolean_handlesException(ASTNode caller, ASTNode child, TypeDecl exceptionType) {
947        if(caller == getBlockNoTransform()) {
948          return twrHandlesException(exceptionType);
949        }
950        else if(caller == getResourceListNoTransform())  {
951        int i = caller.getIndexOfChild(child);
952        return twrHandlesException(exceptionType);
953      }
954        else {      return super.Define_boolean_handlesException(caller, child, exceptionType);
955        }
956      }
957      /**
958       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:113
959       * @apilevel internal
960       */
961      public boolean Define_boolean_reachableCatchClause(ASTNode caller, ASTNode child, TypeDecl exceptionType) {
962        if(caller == getCatchClauseListNoTransform())  { 
963        int childIndex = caller.getIndexOfChild(child);
964        {
965               for (int i = 0; i < childIndex; i++)
966                       if (getCatchClause(i).handles(exceptionType))
967                               return false;
968               if (catchableException(exceptionType))
969                       return true;
970               if (exceptionType.mayCatch(typeError()) || exceptionType.mayCatch(typeRuntimeException()))
971                       return true;
972               return false;
973       }
974      }
975        else {      return super.Define_boolean_reachableCatchClause(caller, child, exceptionType);
976        }
977      }
978      /**
979       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:127
980       * @apilevel internal
981       */
982      public SimpleSet Define_SimpleSet_lookupVariable(ASTNode caller, ASTNode child, String name) {
983        if(caller == getBlockNoTransform()) {
984          return localLookup(name);
985        }
986        else {      return getParent().Define_SimpleSet_lookupVariable(this, caller, name);
987        }
988      }
989      /**
990       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:142
991       * @apilevel internal
992       */
993      public VariableScope Define_VariableScope_outerScope(ASTNode caller, ASTNode child) {
994        if(caller == getResourceListNoTransform())  {
995        int i = caller.getIndexOfChild(child);
996        return this;
997      }
998        else {      return getParent().Define_VariableScope_outerScope(this, caller);
999        }
1000      }
1001      /**
1002       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:146
1003       * @apilevel internal
1004       */
1005      public boolean Define_boolean_resourcePreviouslyDeclared(ASTNode caller, ASTNode child, String name) {
1006        if(caller == getResourceListNoTransform())  { 
1007        int index = caller.getIndexOfChild(child);
1008        {
1009             for (int i = 0; i < index; ++i) {
1010                     if (getResource(i).name().equals(name))
1011                             return true;
1012             }
1013             return false;
1014     }
1015      }
1016        else {      return getParent().Define_boolean_resourcePreviouslyDeclared(this, caller, name);
1017        }
1018      }
1019      /**
1020       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/TryWithResources.jrag:173
1021       * @apilevel internal
1022       */
1023      public boolean Define_boolean_isDAbefore(ASTNode caller, ASTNode child, Variable v) {
1024        if(caller == getBlockNoTransform()) {
1025          return getNumResource() == 0 ? isDAbefore(v) :
1026             getResource(getNumResource() - 1).isDAafter(v);
1027        }
1028        else if(caller == getResourceListNoTransform())  {
1029        int index = caller.getIndexOfChild(child);
1030        return index == 0 ? isDAbefore(v) : getResource(index - 1).isDAafter(v);
1031      }
1032        else {      return super.Define_boolean_isDAbefore(caller, child, v);
1033        }
1034      }
1035      /**
1036       * @declaredat /home/jesper/svn/JastAddJ/Java7Backend/TryWithResources.jrag:286
1037       * @apilevel internal
1038       */
1039      public int Define_int_localNum(ASTNode caller, ASTNode child) {
1040        if(caller == getBlockNoTransform()) {
1041          return 100;
1042        }
1043        else if(caller == getResourceListNoTransform())  {
1044        int index = caller.getIndexOfChild(child);
1045        return 50;
1046      }
1047        else {      return super.Define_int_localNum(caller, child);
1048        }
1049      }
1050      /**
1051       * @apilevel internal
1052       */
1053      public ASTNode rewriteTo() {
1054        return super.rewriteTo();
1055      }
1056    }