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/java8/grammar/LambdaAnonymousDecl.ast:1
027     * @production LambdaAnonymousDecl : {@link AnonymousDecl};
028    
029     */
030    public class LambdaAnonymousDecl extends AnonymousDecl implements Cloneable {
031      /**
032       * @declaredat ASTNode:1
033       */
034      public LambdaAnonymousDecl() {
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[5];
046        setChild(new List(), 1);
047        setChild(new Opt(), 2);
048        setChild(new Opt(), 3);
049        setChild(new List(), 4);
050      }
051      /**
052       * @declaredat ASTNode:17
053       */
054      public LambdaAnonymousDecl(Modifiers p0, String p1, List<BodyDecl> p2) {
055        setChild(p0, 0);
056        setID(p1);
057        setChild(p2, 1);
058      }
059      /**
060       * @declaredat ASTNode:22
061       */
062      public LambdaAnonymousDecl(Modifiers p0, beaver.Symbol p1, List<BodyDecl> p2) {
063        setChild(p0, 0);
064        setID(p1);
065        setChild(p2, 1);
066      }
067      /**
068       * @apilevel low-level
069       * @declaredat ASTNode:30
070       */
071      protected int numChildren() {
072        return 2;
073      }
074      /**
075       * @apilevel internal
076       * @declaredat ASTNode:36
077       */
078      public boolean mayHaveRewrite() {
079        return false;
080      }
081      /**
082       * @apilevel internal
083       * @declaredat ASTNode:42
084       */
085      public void flushAttrCache() {
086        super.flushAttrCache();
087        unqualifiedLookupMethod_String_reset();
088        enclosingLambda_reset();
089      }
090      /**
091       * @apilevel internal
092       * @declaredat ASTNode:50
093       */
094      public void flushCollectionCache() {
095        super.flushCollectionCache();
096      }
097      /**
098       * @apilevel internal
099       * @declaredat ASTNode:56
100       */
101      public void flushRewriteCache() {
102        super.flushRewriteCache();
103      }
104      /**
105       * @apilevel internal
106       * @declaredat ASTNode:62
107       */
108      public LambdaAnonymousDecl clone() throws CloneNotSupportedException {
109        LambdaAnonymousDecl node = (LambdaAnonymousDecl) super.clone();
110        return node;
111      }
112      /**
113       * @apilevel internal
114       * @declaredat ASTNode:69
115       */
116      public LambdaAnonymousDecl copy() {
117        try {
118          LambdaAnonymousDecl node = (LambdaAnonymousDecl) 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:88
135       */
136      @Deprecated
137      public LambdaAnonymousDecl 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:98
146       */
147      public LambdaAnonymousDecl treeCopyNoTransform() {
148        LambdaAnonymousDecl tree = (LambdaAnonymousDecl) copy();
149        if (children != null) {
150          for (int i = 0; i < children.length; ++i) {
151            switch (i) {
152            case 2:
153            case 3:
154              tree.children[i] = new Opt();
155              continue;
156            case 4:
157              tree.children[i] = new List();
158              continue;
159            }
160            ASTNode child = (ASTNode) children[i];
161            if (child != null) {
162              child = child.treeCopyNoTransform();
163              tree.setChild(child, i);
164            }
165          }
166        }
167        return tree;
168      }
169      /**
170       * Create a deep copy of the AST subtree at this node.
171       * The subtree of this node is traversed to trigger rewrites before copy.
172       * The copy is dangling, i.e. has no parent.
173       * @return dangling copy of the subtree at this node
174       * @apilevel low-level
175       * @declaredat ASTNode:127
176       */
177      public LambdaAnonymousDecl treeCopy() {
178        doFullTraversal();
179        return treeCopyNoTransform();
180      }
181      /**
182       * @apilevel internal
183       * @declaredat ASTNode:134
184       */
185      protected boolean is$Equal(ASTNode node) {
186        return super.is$Equal(node) && (tokenString_ID == ((LambdaAnonymousDecl)node).tokenString_ID);    
187      }
188      /**
189       * Replaces the Modifiers child.
190       * @param node The new node to replace the Modifiers child.
191       * @apilevel high-level
192       */
193      public void setModifiers(Modifiers node) {
194        setChild(node, 0);
195      }
196      /**
197       * Retrieves the Modifiers child.
198       * @return The current node used as the Modifiers child.
199       * @apilevel high-level
200       */
201      @ASTNodeAnnotation.Child(name="Modifiers")
202      public Modifiers getModifiers() {
203        return (Modifiers) getChild(0);
204      }
205      /**
206       * Retrieves the Modifiers child.
207       * <p><em>This method does not invoke AST transformations.</em></p>
208       * @return The current node used as the Modifiers child.
209       * @apilevel low-level
210       */
211      public Modifiers getModifiersNoTransform() {
212        return (Modifiers) getChildNoTransform(0);
213      }
214      /**
215       * Replaces the lexeme ID.
216       * @param value The new value for the lexeme ID.
217       * @apilevel high-level
218       */
219      public void setID(String value) {
220        tokenString_ID = value;
221      }
222      /**
223       * JastAdd-internal setter for lexeme ID using the Beaver parser.
224       * @param symbol Symbol containing the new value for the lexeme ID
225       * @apilevel internal
226       */
227      public void setID(beaver.Symbol symbol) {
228        if (symbol.value != null && !(symbol.value instanceof String))
229        throw new UnsupportedOperationException("setID is only valid for String lexemes");
230        tokenString_ID = (String)symbol.value;
231        IDstart = symbol.getStart();
232        IDend = symbol.getEnd();
233      }
234      /**
235       * Retrieves the value for the lexeme ID.
236       * @return The value for the lexeme ID.
237       * @apilevel high-level
238       */
239      @ASTNodeAnnotation.Token(name="ID")
240      public String getID() {
241        return tokenString_ID != null ? tokenString_ID : "";
242      }
243      /**
244       * Replaces the BodyDecl list.
245       * @param list The new list node to be used as the BodyDecl list.
246       * @apilevel high-level
247       */
248      public void setBodyDeclList(List<BodyDecl> list) {
249        setChild(list, 1);
250      }
251      /**
252       * Retrieves the number of children in the BodyDecl list.
253       * @return Number of children in the BodyDecl list.
254       * @apilevel high-level
255       */
256      public int getNumBodyDecl() {
257        return getBodyDeclList().getNumChild();
258      }
259      /**
260       * Retrieves the number of children in the BodyDecl list.
261       * Calling this method will not trigger rewrites.
262       * @return Number of children in the BodyDecl list.
263       * @apilevel low-level
264       */
265      public int getNumBodyDeclNoTransform() {
266        return getBodyDeclListNoTransform().getNumChildNoTransform();
267      }
268      /**
269       * Retrieves the element at index {@code i} in the BodyDecl list.
270       * @param i Index of the element to return.
271       * @return The element at position {@code i} in the BodyDecl list.
272       * @apilevel high-level
273       */
274      public BodyDecl getBodyDecl(int i) {
275        return (BodyDecl) getBodyDeclList().getChild(i);
276      }
277      /**
278       * Check whether the BodyDecl list has any children.
279       * @return {@code true} if it has at least one child, {@code false} otherwise.
280       * @apilevel high-level
281       */
282      public boolean hasBodyDecl() {
283        return getBodyDeclList().getNumChild() != 0;
284      }
285      /**
286       * Append an element to the BodyDecl list.
287       * @param node The element to append to the BodyDecl list.
288       * @apilevel high-level
289       */
290      public void addBodyDecl(BodyDecl node) {
291        List<BodyDecl> list = (parent == null) ? getBodyDeclListNoTransform() : getBodyDeclList();
292        list.addChild(node);
293      }
294      /**
295       * @apilevel low-level
296       */
297      public void addBodyDeclNoTransform(BodyDecl node) {
298        List<BodyDecl> list = getBodyDeclListNoTransform();
299        list.addChild(node);
300      }
301      /**
302       * Replaces the BodyDecl list element at index {@code i} with the new node {@code node}.
303       * @param node The new node to replace the old list element.
304       * @param i The list index of the node to be replaced.
305       * @apilevel high-level
306       */
307      public void setBodyDecl(BodyDecl node, int i) {
308        List<BodyDecl> list = getBodyDeclList();
309        list.setChild(node, i);
310      }
311      /**
312       * Retrieves the BodyDecl list.
313       * @return The node representing the BodyDecl list.
314       * @apilevel high-level
315       */
316      @ASTNodeAnnotation.ListChild(name="BodyDecl")
317      public List<BodyDecl> getBodyDeclList() {
318        List<BodyDecl> list = (List<BodyDecl>) getChild(1);
319        return list;
320      }
321      /**
322       * Retrieves the BodyDecl list.
323       * <p><em>This method does not invoke AST transformations.</em></p>
324       * @return The node representing the BodyDecl list.
325       * @apilevel low-level
326       */
327      public List<BodyDecl> getBodyDeclListNoTransform() {
328        return (List<BodyDecl>) getChildNoTransform(1);
329      }
330      /**
331       * Retrieves the BodyDecl list.
332       * @return The node representing the BodyDecl list.
333       * @apilevel high-level
334       */
335      public List<BodyDecl> getBodyDecls() {
336        return getBodyDeclList();
337      }
338      /**
339       * Retrieves the BodyDecl list.
340       * <p><em>This method does not invoke AST transformations.</em></p>
341       * @return The node representing the BodyDecl list.
342       * @apilevel low-level
343       */
344      public List<BodyDecl> getBodyDeclsNoTransform() {
345        return getBodyDeclListNoTransform();
346      }
347      /**
348       * Replaces the (optional) ImplicitConstructor child.
349       * @param node The new node to be used as the ImplicitConstructor child.
350       * @apilevel high-level
351       */
352      public void setImplicitConstructor(ConstructorDecl node) {
353        getImplicitConstructorOpt().setChild(node, 0);
354      }
355      /**
356       * Check whether the optional ImplicitConstructor child exists.
357       * @return {@code true} if the optional ImplicitConstructor child exists, {@code false} if it does not.
358       * @apilevel high-level
359       */
360      public boolean hasImplicitConstructor() {
361        return getImplicitConstructorOpt().getNumChild() != 0;
362      }
363      /**
364       * Retrieves the (optional) ImplicitConstructor child.
365       * @return The ImplicitConstructor child, if it exists. Returns {@code null} otherwise.
366       * @apilevel low-level
367       */
368      public ConstructorDecl getImplicitConstructor() {
369        return (ConstructorDecl) getImplicitConstructorOpt().getChild(0);
370      }
371      /**
372       * Retrieves the optional node for child ImplicitConstructor. This is the <code>Opt</code> node containing the child ImplicitConstructor, not the actual child!
373       * <p><em>This method does not invoke AST transformations.</em></p>
374       * @return The optional node for child ImplicitConstructor.
375       * @apilevel low-level
376       */
377      public Opt<ConstructorDecl> getImplicitConstructorOptNoTransform() {
378        return (Opt<ConstructorDecl>) getChildNoTransform(2);
379      }
380      /**
381       * Retrieves the child position of the optional child ImplicitConstructor.
382       * @return The the child position of the optional child ImplicitConstructor.
383       * @apilevel low-level
384       */
385      protected int getImplicitConstructorOptChildPosition() {
386        return 2;
387      }
388      /**
389       * This method should not be called. This method throws an exception due to
390       * the corresponding child being an NTA shadowing a non-NTA child.
391       * @param node
392       * @apilevel internal
393       */
394      public void setSuperClassOpt(Opt<Access> node) {
395        throw new Error("Can not replace NTA child SuperClassOpt in LambdaAnonymousDecl!");
396      }
397      /**
398       * Replaces the (optional) SuperClass child.
399       * @param node The new node to be used as the SuperClass child.
400       * @apilevel high-level
401       */
402      public void setSuperClass(Access node) {
403        getSuperClassOpt().setChild(node, 0);
404      }
405      /**
406       * Check whether the optional SuperClass child exists.
407       * @return {@code true} if the optional SuperClass child exists, {@code false} if it does not.
408       * @apilevel high-level
409       */
410      public boolean hasSuperClass() {
411        return getSuperClassOpt().getNumChild() != 0;
412      }
413      /**
414       * Retrieves the (optional) SuperClass child.
415       * @return The SuperClass child, if it exists. Returns {@code null} otherwise.
416       * @apilevel low-level
417       */
418      public Access getSuperClass() {
419        return (Access) getSuperClassOpt().getChild(0);
420      }
421      /**
422       * Retrieves the optional node for child SuperClass. This is the <code>Opt</code> node containing the child SuperClass, not the actual child!
423       * <p><em>This method does not invoke AST transformations.</em></p>
424       * @return The optional node for child SuperClass.
425       * @apilevel low-level
426       */
427      public Opt<Access> getSuperClassOptNoTransform() {
428        return (Opt<Access>) getChildNoTransform(3);
429      }
430      /**
431       * Retrieves the child position of the optional child SuperClass.
432       * @return The the child position of the optional child SuperClass.
433       * @apilevel low-level
434       */
435      protected int getSuperClassOptChildPosition() {
436        return 3;
437      }
438      /**
439       * This method should not be called. This method throws an exception due to
440       * the corresponding child being an NTA shadowing a non-NTA child.
441       * @param node
442       * @apilevel internal
443       */
444      public void setImplementsList(List<Access> node) {
445        throw new Error("Can not replace NTA child ImplementsList in LambdaAnonymousDecl!");
446      }
447      /**
448       * Retrieves the number of children in the Implements list.
449       * @return Number of children in the Implements list.
450       * @apilevel high-level
451       */
452      public int getNumImplements() {
453        return getImplementsList().getNumChild();
454      }
455      /**
456       * Retrieves the number of children in the Implements list.
457       * Calling this method will not trigger rewrites.
458       * @return Number of children in the Implements list.
459       * @apilevel low-level
460       */
461      public int getNumImplementsNoTransform() {
462        return getImplementsListNoTransform().getNumChildNoTransform();
463      }
464      /**
465       * Retrieves the element at index {@code i} in the Implements list.
466       * @param i Index of the element to return.
467       * @return The element at position {@code i} in the Implements list.
468       * @apilevel high-level
469       */
470      public Access getImplements(int i) {
471        return (Access) getImplementsList().getChild(i);
472      }
473      /**
474       * Check whether the Implements list has any children.
475       * @return {@code true} if it has at least one child, {@code false} otherwise.
476       * @apilevel high-level
477       */
478      public boolean hasImplements() {
479        return getImplementsList().getNumChild() != 0;
480      }
481      /**
482       * Append an element to the Implements list.
483       * @param node The element to append to the Implements list.
484       * @apilevel high-level
485       */
486      public void addImplements(Access node) {
487        List<Access> list = (parent == null) ? getImplementsListNoTransform() : getImplementsList();
488        list.addChild(node);
489      }
490      /**
491       * @apilevel low-level
492       */
493      public void addImplementsNoTransform(Access node) {
494        List<Access> list = getImplementsListNoTransform();
495        list.addChild(node);
496      }
497      /**
498       * Replaces the Implements list element at index {@code i} with the new node {@code node}.
499       * @param node The new node to replace the old list element.
500       * @param i The list index of the node to be replaced.
501       * @apilevel high-level
502       */
503      public void setImplements(Access node, int i) {
504        List<Access> list = getImplementsList();
505        list.setChild(node, i);
506      }
507      /**
508       * Retrieves the child position of the Implements list.
509       * @return The the child position of the Implements list.
510       * @apilevel low-level
511       */
512      protected int getImplementsListChildPosition() {
513        return 4;
514      }
515      /**
516       * Retrieves the Implements list.
517       * <p><em>This method does not invoke AST transformations.</em></p>
518       * @return The node representing the Implements list.
519       * @apilevel low-level
520       */
521      public List<Access> getImplementsListNoTransform() {
522        return (List<Access>) getChildNoTransform(4);
523      }
524      /**
525       * Retrieves the Implements list.
526       * @return The node representing the Implements list.
527       * @apilevel high-level
528       */
529      public List<Access> getImplementss() {
530        return getImplementsList();
531      }
532      /**
533       * Retrieves the Implements list.
534       * <p><em>This method does not invoke AST transformations.</em></p>
535       * @return The node representing the Implements list.
536       * @apilevel low-level
537       */
538      public List<Access> getImplementssNoTransform() {
539        return getImplementsListNoTransform();
540      }
541      /**
542       * @apilevel internal
543       */
544      protected java.util.Map unqualifiedLookupMethod_String_values;
545      /**
546       * @apilevel internal
547       */
548      private void unqualifiedLookupMethod_String_reset() {
549        unqualifiedLookupMethod_String_values = null;
550      }
551      /**
552       * @attribute syn
553       * @aspect LookupMethod
554       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupMethod.jrag:58
555       */
556      @ASTNodeAnnotation.Attribute
557      public Collection unqualifiedLookupMethod(String name) {
558        Object _parameters = name;
559        if (unqualifiedLookupMethod_String_values == null) unqualifiedLookupMethod_String_values = new org.jastadd.util.RobustMap(new java.util.HashMap());
560        ASTNode$State state = state();
561        if (unqualifiedLookupMethod_String_values.containsKey(_parameters)) {
562          return (Collection) unqualifiedLookupMethod_String_values.get(_parameters);
563        }
564        boolean intermediate = state.INTERMEDIATE_VALUE;
565        state.INTERMEDIATE_VALUE = false;
566        int num = state.boundariesCrossed;
567        boolean isFinal = this.is$Final();
568        Collection unqualifiedLookupMethod_String_value = unqualifiedLookupMethod_compute(name);
569        if (isFinal && num == state().boundariesCrossed) {
570          unqualifiedLookupMethod_String_values.put(_parameters, unqualifiedLookupMethod_String_value);
571        } else {
572        }
573        state.INTERMEDIATE_VALUE |= intermediate;
574    
575        return unqualifiedLookupMethod_String_value;
576      }
577      /**
578       * @apilevel internal
579       */
580      private Collection unqualifiedLookupMethod_compute(String name) {
581          if (getParent().getParent().getParent() instanceof MethodReference) {
582            return ((MethodReference) getParent().getParent().getParent()).lookupMethod(name);
583          } else if (getParent().getParent().getParent() instanceof ConstructorReference) {
584            return ((ConstructorReference) getParent().getParent().getParent()).lookupMethod(name);
585          } else {
586            return enclosingLambda().lookupMethod(name);
587          }
588        }
589      /**
590       * @attribute inh
591       * @aspect EnclosingLambda
592       * @declaredat /home/jesper/git/extendj/java8/frontend/EnclosingLambda.jrag:37
593       */
594      /**
595       * @attribute inh
596       * @aspect EnclosingLambda
597       * @declaredat /home/jesper/git/extendj/java8/frontend/EnclosingLambda.jrag:37
598       */
599      @ASTNodeAnnotation.Attribute
600      public LambdaExpr enclosingLambda() {
601        ASTNode$State state = state();
602        if (enclosingLambda_computed) {
603          return enclosingLambda_value;
604        }
605        boolean intermediate = state.INTERMEDIATE_VALUE;
606        state.INTERMEDIATE_VALUE = false;
607        int num = state.boundariesCrossed;
608        boolean isFinal = this.is$Final();
609        enclosingLambda_value = getParent().Define_enclosingLambda(this, null);
610        if (isFinal && num == state().boundariesCrossed) {
611          enclosingLambda_computed = true;
612        } else {
613        }
614        state.INTERMEDIATE_VALUE |= intermediate;
615    
616        return enclosingLambda_value;
617      }
618      /**
619       * @apilevel internal
620       */
621      protected boolean enclosingLambda_computed = false;
622      /**
623       * @apilevel internal
624       */
625      protected LambdaExpr enclosingLambda_value;
626      /**
627       * @apilevel internal
628       */
629      private void enclosingLambda_reset() {
630        enclosingLambda_computed = false;
631        enclosingLambda_value = null;
632      }
633      /**
634       * @apilevel internal
635       */
636      public ASTNode rewriteTo() {
637        return super.rewriteTo();
638      }
639    }