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/Annotations.ast:3
027     * @production AnnotationMethodDecl : {@link MethodDecl} ::= <span class="component">[DefaultValue:{@link ElementValue}]</span>;
028    
029     */
030    public class AnnotationMethodDecl extends MethodDecl implements Cloneable {
031      /**
032       * @aspect Annotations
033       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:203
034       */
035      public void typeCheck() {
036        super.typeCheck();
037        if (hasDefaultValue() && !type().commensurateWith(getDefaultValue())) {
038          errorf("%s is not commensurate with %s",
039              type().typeName(), getDefaultValue().type().typeName());
040        }
041      }
042      /**
043       * @aspect Java5PrettyPrint
044       * @declaredat /home/jesper/git/extendj/java5/frontend/PrettyPrint.jadd:84
045       */
046      public void prettyPrint(PrettyPrinter out) {
047        if (hasDocComment()) {
048          out.print(docComment());
049        }
050        if (!out.isNewLine()) {
051          out.println();
052        }
053        out.print(getModifiers());
054        out.print(getTypeAccess());
055        out.print(" ");
056        out.print(getID());
057        out.print("()");
058        if (hasDefaultValue()) {
059          out.print(" default ");
060          out.print(getDefaultValue());
061        }
062        out.print(";");
063      }
064      /**
065       * @declaredat ASTNode:1
066       */
067      public AnnotationMethodDecl() {
068        super();
069      }
070      /**
071       * Initializes the child array to the correct size.
072       * Initializes List and Opt nta children.
073       * @apilevel internal
074       * @ast method
075       * @declaredat ASTNode:10
076       */
077      public void init$Children() {
078        children = new ASTNode[6];
079        setChild(new List(), 2);
080        setChild(new List(), 3);
081        setChild(new Opt(), 4);
082        setChild(new Opt(), 5);
083      }
084      /**
085       * @declaredat ASTNode:17
086       */
087      public AnnotationMethodDecl(Modifiers p0, Access p1, String p2, List<ParameterDeclaration> p3, List<Access> p4, Opt<Block> p5, Opt<ElementValue> p6) {
088        setChild(p0, 0);
089        setChild(p1, 1);
090        setID(p2);
091        setChild(p3, 2);
092        setChild(p4, 3);
093        setChild(p5, 4);
094        setChild(p6, 5);
095      }
096      /**
097       * @declaredat ASTNode:26
098       */
099      public AnnotationMethodDecl(Modifiers p0, Access p1, beaver.Symbol p2, List<ParameterDeclaration> p3, List<Access> p4, Opt<Block> p5, Opt<ElementValue> p6) {
100        setChild(p0, 0);
101        setChild(p1, 1);
102        setID(p2);
103        setChild(p3, 2);
104        setChild(p4, 3);
105        setChild(p5, 4);
106        setChild(p6, 5);
107      }
108      /**
109       * @apilevel low-level
110       * @declaredat ASTNode:38
111       */
112      protected int numChildren() {
113        return 6;
114      }
115      /**
116       * @apilevel internal
117       * @declaredat ASTNode:44
118       */
119      public boolean mayHaveRewrite() {
120        return false;
121      }
122      /**
123       * @apilevel internal
124       * @declaredat ASTNode:50
125       */
126      public void flushAttrCache() {
127        super.flushAttrCache();
128        attributes_reset();
129      }
130      /**
131       * @apilevel internal
132       * @declaredat ASTNode:57
133       */
134      public void flushCollectionCache() {
135        super.flushCollectionCache();
136      }
137      /**
138       * @apilevel internal
139       * @declaredat ASTNode:63
140       */
141      public void flushRewriteCache() {
142        super.flushRewriteCache();
143      }
144      /**
145       * @apilevel internal
146       * @declaredat ASTNode:69
147       */
148      public AnnotationMethodDecl clone() throws CloneNotSupportedException {
149        AnnotationMethodDecl node = (AnnotationMethodDecl) super.clone();
150        return node;
151      }
152      /**
153       * @apilevel internal
154       * @declaredat ASTNode:76
155       */
156      public AnnotationMethodDecl copy() {
157        try {
158          AnnotationMethodDecl node = (AnnotationMethodDecl) clone();
159          node.parent = null;
160          if (children != null) {
161            node.children = (ASTNode[]) children.clone();
162          }
163          return node;
164        } catch (CloneNotSupportedException e) {
165          throw new Error("Error: clone not supported for " + getClass().getName());
166        }
167      }
168      /**
169       * Create a deep copy of the AST subtree at this node.
170       * The copy is dangling, i.e. has no parent.
171       * @return dangling copy of the subtree at this node
172       * @apilevel low-level
173       * @deprecated Please use treeCopy or treeCopyNoTransform instead
174       * @declaredat ASTNode:95
175       */
176      @Deprecated
177      public AnnotationMethodDecl fullCopy() {
178        return treeCopyNoTransform();
179      }
180      /**
181       * Create a deep copy of the AST subtree at this node.
182       * The copy is dangling, i.e. has no parent.
183       * @return dangling copy of the subtree at this node
184       * @apilevel low-level
185       * @declaredat ASTNode:105
186       */
187      public AnnotationMethodDecl treeCopyNoTransform() {
188        AnnotationMethodDecl tree = (AnnotationMethodDecl) copy();
189        if (children != null) {
190          for (int i = 0; i < children.length; ++i) {
191            ASTNode child = (ASTNode) children[i];
192            if (child != null) {
193              child = child.treeCopyNoTransform();
194              tree.setChild(child, i);
195            }
196          }
197        }
198        return tree;
199      }
200      /**
201       * Create a deep copy of the AST subtree at this node.
202       * The subtree of this node is traversed to trigger rewrites before copy.
203       * The copy is dangling, i.e. has no parent.
204       * @return dangling copy of the subtree at this node
205       * @apilevel low-level
206       * @declaredat ASTNode:125
207       */
208      public AnnotationMethodDecl treeCopy() {
209        doFullTraversal();
210        return treeCopyNoTransform();
211      }
212      /**
213       * @apilevel internal
214       * @declaredat ASTNode:132
215       */
216      protected boolean is$Equal(ASTNode node) {
217        return super.is$Equal(node) && (tokenString_ID == ((AnnotationMethodDecl)node).tokenString_ID);    
218      }
219      /**
220       * Replaces the Modifiers child.
221       * @param node The new node to replace the Modifiers child.
222       * @apilevel high-level
223       */
224      public void setModifiers(Modifiers node) {
225        setChild(node, 0);
226      }
227      /**
228       * Retrieves the Modifiers child.
229       * @return The current node used as the Modifiers child.
230       * @apilevel high-level
231       */
232      @ASTNodeAnnotation.Child(name="Modifiers")
233      public Modifiers getModifiers() {
234        return (Modifiers) getChild(0);
235      }
236      /**
237       * Retrieves the Modifiers child.
238       * <p><em>This method does not invoke AST transformations.</em></p>
239       * @return The current node used as the Modifiers child.
240       * @apilevel low-level
241       */
242      public Modifiers getModifiersNoTransform() {
243        return (Modifiers) getChildNoTransform(0);
244      }
245      /**
246       * Replaces the TypeAccess child.
247       * @param node The new node to replace the TypeAccess child.
248       * @apilevel high-level
249       */
250      public void setTypeAccess(Access node) {
251        setChild(node, 1);
252      }
253      /**
254       * Retrieves the TypeAccess child.
255       * @return The current node used as the TypeAccess child.
256       * @apilevel high-level
257       */
258      @ASTNodeAnnotation.Child(name="TypeAccess")
259      public Access getTypeAccess() {
260        return (Access) getChild(1);
261      }
262      /**
263       * Retrieves the TypeAccess child.
264       * <p><em>This method does not invoke AST transformations.</em></p>
265       * @return The current node used as the TypeAccess child.
266       * @apilevel low-level
267       */
268      public Access getTypeAccessNoTransform() {
269        return (Access) getChildNoTransform(1);
270      }
271      /**
272       * Replaces the lexeme ID.
273       * @param value The new value for the lexeme ID.
274       * @apilevel high-level
275       */
276      public void setID(String value) {
277        tokenString_ID = value;
278      }
279      /**
280       * JastAdd-internal setter for lexeme ID using the Beaver parser.
281       * @param symbol Symbol containing the new value for the lexeme ID
282       * @apilevel internal
283       */
284      public void setID(beaver.Symbol symbol) {
285        if (symbol.value != null && !(symbol.value instanceof String))
286        throw new UnsupportedOperationException("setID is only valid for String lexemes");
287        tokenString_ID = (String)symbol.value;
288        IDstart = symbol.getStart();
289        IDend = symbol.getEnd();
290      }
291      /**
292       * Retrieves the value for the lexeme ID.
293       * @return The value for the lexeme ID.
294       * @apilevel high-level
295       */
296      @ASTNodeAnnotation.Token(name="ID")
297      public String getID() {
298        return tokenString_ID != null ? tokenString_ID : "";
299      }
300      /**
301       * Replaces the Parameter list.
302       * @param list The new list node to be used as the Parameter list.
303       * @apilevel high-level
304       */
305      public void setParameterList(List<ParameterDeclaration> list) {
306        setChild(list, 2);
307      }
308      /**
309       * Retrieves the number of children in the Parameter list.
310       * @return Number of children in the Parameter list.
311       * @apilevel high-level
312       */
313      public int getNumParameter() {
314        return getParameterList().getNumChild();
315      }
316      /**
317       * Retrieves the number of children in the Parameter list.
318       * Calling this method will not trigger rewrites.
319       * @return Number of children in the Parameter list.
320       * @apilevel low-level
321       */
322      public int getNumParameterNoTransform() {
323        return getParameterListNoTransform().getNumChildNoTransform();
324      }
325      /**
326       * Retrieves the element at index {@code i} in the Parameter list.
327       * @param i Index of the element to return.
328       * @return The element at position {@code i} in the Parameter list.
329       * @apilevel high-level
330       */
331      public ParameterDeclaration getParameter(int i) {
332        return (ParameterDeclaration) getParameterList().getChild(i);
333      }
334      /**
335       * Check whether the Parameter list has any children.
336       * @return {@code true} if it has at least one child, {@code false} otherwise.
337       * @apilevel high-level
338       */
339      public boolean hasParameter() {
340        return getParameterList().getNumChild() != 0;
341      }
342      /**
343       * Append an element to the Parameter list.
344       * @param node The element to append to the Parameter list.
345       * @apilevel high-level
346       */
347      public void addParameter(ParameterDeclaration node) {
348        List<ParameterDeclaration> list = (parent == null) ? getParameterListNoTransform() : getParameterList();
349        list.addChild(node);
350      }
351      /**
352       * @apilevel low-level
353       */
354      public void addParameterNoTransform(ParameterDeclaration node) {
355        List<ParameterDeclaration> list = getParameterListNoTransform();
356        list.addChild(node);
357      }
358      /**
359       * Replaces the Parameter list element at index {@code i} with the new node {@code node}.
360       * @param node The new node to replace the old list element.
361       * @param i The list index of the node to be replaced.
362       * @apilevel high-level
363       */
364      public void setParameter(ParameterDeclaration node, int i) {
365        List<ParameterDeclaration> list = getParameterList();
366        list.setChild(node, i);
367      }
368      /**
369       * Retrieves the Parameter list.
370       * @return The node representing the Parameter list.
371       * @apilevel high-level
372       */
373      @ASTNodeAnnotation.ListChild(name="Parameter")
374      public List<ParameterDeclaration> getParameterList() {
375        List<ParameterDeclaration> list = (List<ParameterDeclaration>) getChild(2);
376        return list;
377      }
378      /**
379       * Retrieves the Parameter list.
380       * <p><em>This method does not invoke AST transformations.</em></p>
381       * @return The node representing the Parameter list.
382       * @apilevel low-level
383       */
384      public List<ParameterDeclaration> getParameterListNoTransform() {
385        return (List<ParameterDeclaration>) getChildNoTransform(2);
386      }
387      /**
388       * Retrieves the Parameter list.
389       * @return The node representing the Parameter list.
390       * @apilevel high-level
391       */
392      public List<ParameterDeclaration> getParameters() {
393        return getParameterList();
394      }
395      /**
396       * Retrieves the Parameter list.
397       * <p><em>This method does not invoke AST transformations.</em></p>
398       * @return The node representing the Parameter list.
399       * @apilevel low-level
400       */
401      public List<ParameterDeclaration> getParametersNoTransform() {
402        return getParameterListNoTransform();
403      }
404      /**
405       * Replaces the Exception list.
406       * @param list The new list node to be used as the Exception list.
407       * @apilevel high-level
408       */
409      public void setExceptionList(List<Access> list) {
410        setChild(list, 3);
411      }
412      /**
413       * Retrieves the number of children in the Exception list.
414       * @return Number of children in the Exception list.
415       * @apilevel high-level
416       */
417      public int getNumException() {
418        return getExceptionList().getNumChild();
419      }
420      /**
421       * Retrieves the number of children in the Exception list.
422       * Calling this method will not trigger rewrites.
423       * @return Number of children in the Exception list.
424       * @apilevel low-level
425       */
426      public int getNumExceptionNoTransform() {
427        return getExceptionListNoTransform().getNumChildNoTransform();
428      }
429      /**
430       * Retrieves the element at index {@code i} in the Exception list.
431       * @param i Index of the element to return.
432       * @return The element at position {@code i} in the Exception list.
433       * @apilevel high-level
434       */
435      public Access getException(int i) {
436        return (Access) getExceptionList().getChild(i);
437      }
438      /**
439       * Check whether the Exception list has any children.
440       * @return {@code true} if it has at least one child, {@code false} otherwise.
441       * @apilevel high-level
442       */
443      public boolean hasException() {
444        return getExceptionList().getNumChild() != 0;
445      }
446      /**
447       * Append an element to the Exception list.
448       * @param node The element to append to the Exception list.
449       * @apilevel high-level
450       */
451      public void addException(Access node) {
452        List<Access> list = (parent == null) ? getExceptionListNoTransform() : getExceptionList();
453        list.addChild(node);
454      }
455      /**
456       * @apilevel low-level
457       */
458      public void addExceptionNoTransform(Access node) {
459        List<Access> list = getExceptionListNoTransform();
460        list.addChild(node);
461      }
462      /**
463       * Replaces the Exception list element at index {@code i} with the new node {@code node}.
464       * @param node The new node to replace the old list element.
465       * @param i The list index of the node to be replaced.
466       * @apilevel high-level
467       */
468      public void setException(Access node, int i) {
469        List<Access> list = getExceptionList();
470        list.setChild(node, i);
471      }
472      /**
473       * Retrieves the Exception list.
474       * @return The node representing the Exception list.
475       * @apilevel high-level
476       */
477      @ASTNodeAnnotation.ListChild(name="Exception")
478      public List<Access> getExceptionList() {
479        List<Access> list = (List<Access>) getChild(3);
480        return list;
481      }
482      /**
483       * Retrieves the Exception list.
484       * <p><em>This method does not invoke AST transformations.</em></p>
485       * @return The node representing the Exception list.
486       * @apilevel low-level
487       */
488      public List<Access> getExceptionListNoTransform() {
489        return (List<Access>) getChildNoTransform(3);
490      }
491      /**
492       * Retrieves the Exception list.
493       * @return The node representing the Exception list.
494       * @apilevel high-level
495       */
496      public List<Access> getExceptions() {
497        return getExceptionList();
498      }
499      /**
500       * Retrieves the Exception list.
501       * <p><em>This method does not invoke AST transformations.</em></p>
502       * @return The node representing the Exception list.
503       * @apilevel low-level
504       */
505      public List<Access> getExceptionsNoTransform() {
506        return getExceptionListNoTransform();
507      }
508      /**
509       * Replaces the optional node for the Block child. This is the <code>Opt</code>
510       * node containing the child Block, not the actual child!
511       * @param opt The new node to be used as the optional node for the Block child.
512       * @apilevel low-level
513       */
514      public void setBlockOpt(Opt<Block> opt) {
515        setChild(opt, 4);
516      }
517      /**
518       * Replaces the (optional) Block child.
519       * @param node The new node to be used as the Block child.
520       * @apilevel high-level
521       */
522      public void setBlock(Block node) {
523        getBlockOpt().setChild(node, 0);
524      }
525      /**
526       * Check whether the optional Block child exists.
527       * @return {@code true} if the optional Block child exists, {@code false} if it does not.
528       * @apilevel high-level
529       */
530      public boolean hasBlock() {
531        return getBlockOpt().getNumChild() != 0;
532      }
533      /**
534       * Retrieves the (optional) Block child.
535       * @return The Block child, if it exists. Returns {@code null} otherwise.
536       * @apilevel low-level
537       */
538      public Block getBlock() {
539        return (Block) getBlockOpt().getChild(0);
540      }
541      /**
542       * Retrieves the optional node for the Block child. This is the <code>Opt</code> node containing the child Block, not the actual child!
543       * @return The optional node for child the Block child.
544       * @apilevel low-level
545       */
546      @ASTNodeAnnotation.OptChild(name="Block")
547      public Opt<Block> getBlockOpt() {
548        return (Opt<Block>) getChild(4);
549      }
550      /**
551       * Retrieves the optional node for child Block. This is the <code>Opt</code> node containing the child Block, not the actual child!
552       * <p><em>This method does not invoke AST transformations.</em></p>
553       * @return The optional node for child Block.
554       * @apilevel low-level
555       */
556      public Opt<Block> getBlockOptNoTransform() {
557        return (Opt<Block>) getChildNoTransform(4);
558      }
559      /**
560       * Replaces the optional node for the DefaultValue child. This is the <code>Opt</code>
561       * node containing the child DefaultValue, not the actual child!
562       * @param opt The new node to be used as the optional node for the DefaultValue child.
563       * @apilevel low-level
564       */
565      public void setDefaultValueOpt(Opt<ElementValue> opt) {
566        setChild(opt, 5);
567      }
568      /**
569       * Replaces the (optional) DefaultValue child.
570       * @param node The new node to be used as the DefaultValue child.
571       * @apilevel high-level
572       */
573      public void setDefaultValue(ElementValue node) {
574        getDefaultValueOpt().setChild(node, 0);
575      }
576      /**
577       * Check whether the optional DefaultValue child exists.
578       * @return {@code true} if the optional DefaultValue child exists, {@code false} if it does not.
579       * @apilevel high-level
580       */
581      public boolean hasDefaultValue() {
582        return getDefaultValueOpt().getNumChild() != 0;
583      }
584      /**
585       * Retrieves the (optional) DefaultValue child.
586       * @return The DefaultValue child, if it exists. Returns {@code null} otherwise.
587       * @apilevel low-level
588       */
589      public ElementValue getDefaultValue() {
590        return (ElementValue) getDefaultValueOpt().getChild(0);
591      }
592      /**
593       * Retrieves the optional node for the DefaultValue child. This is the <code>Opt</code> node containing the child DefaultValue, not the actual child!
594       * @return The optional node for child the DefaultValue child.
595       * @apilevel low-level
596       */
597      @ASTNodeAnnotation.OptChild(name="DefaultValue")
598      public Opt<ElementValue> getDefaultValueOpt() {
599        return (Opt<ElementValue>) getChild(5);
600      }
601      /**
602       * Retrieves the optional node for child DefaultValue. This is the <code>Opt</code> node containing the child DefaultValue, not the actual child!
603       * <p><em>This method does not invoke AST transformations.</em></p>
604       * @return The optional node for child DefaultValue.
605       * @apilevel low-level
606       */
607      public Opt<ElementValue> getDefaultValueOptNoTransform() {
608        return (Opt<ElementValue>) getChildNoTransform(5);
609      }
610      /**
611       * @apilevel internal
612       */
613      protected boolean attributes_computed = false;
614      /**
615       * @apilevel internal
616       */
617      protected Collection attributes_value;
618      /**
619       * @apilevel internal
620       */
621      private void attributes_reset() {
622        attributes_computed = false;
623        attributes_value = null;
624      }
625      /**
626       * @attribute syn
627       * @aspect Attributes
628       * @declaredat /home/jesper/git/extendj/java4/backend/Attributes.jrag:212
629       */
630      @ASTNodeAnnotation.Attribute
631      public Collection attributes() {
632        ASTNode$State state = state();
633        if (attributes_computed) {
634          return attributes_value;
635        }
636        boolean intermediate = state.INTERMEDIATE_VALUE;
637        state.INTERMEDIATE_VALUE = false;
638        int num = state.boundariesCrossed;
639        boolean isFinal = this.is$Final();
640        attributes_value = attributes_compute();
641        if (isFinal && num == state().boundariesCrossed) {
642          attributes_computed = true;
643        } else {
644        }
645        state.INTERMEDIATE_VALUE |= intermediate;
646    
647        return attributes_value;
648      }
649      /**
650       * @apilevel internal
651       */
652      private Collection attributes_compute() {
653          Collection c = super.attributes();
654          // 4.8.19
655          if (hasDefaultValue()) {
656            Attribute attribute = new Attribute(hostType().constantPool(), "AnnotationDefault");
657            getDefaultValue().appendAsAttributeTo(attribute);
658            c.add(attribute);
659          }
660          return c;
661        }
662      /**
663       * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:601
664       * @apilevel internal
665       */
666      public TypeDecl Define_declType(ASTNode caller, ASTNode child) {
667        int childIndex = this.getIndexOfChild(caller);
668        return type();
669      }
670      protected boolean canDefine_declType(ASTNode caller, ASTNode child) {
671        return true;
672      }
673      /**
674       * @apilevel internal
675       */
676      public ASTNode rewriteTo() {
677        return super.rewriteTo();
678      }
679    }