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    /**
015     * @production AnnotationDecl : {@link InterfaceDecl} ::= <span class="component">SuperInterfaceId:{@link Access}*</span>;
016     * @ast node
017     * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.ast:2
018     */
019    public class AnnotationDecl extends InterfaceDecl implements Cloneable {
020      /**
021       * @apilevel low-level
022       */
023      public void flushCache() {
024      }
025      /**
026       * @apilevel internal
027       */
028      public void flushCollectionCache() {
029      }
030      /**
031       * @apilevel internal
032       */
033      @SuppressWarnings({"unchecked", "cast"})
034      public AnnotationDecl clone() throws CloneNotSupportedException {
035        AnnotationDecl node = (AnnotationDecl)super.clone();
036        node.getSuperInterfaceIdList_computed = false;
037        node.getSuperInterfaceIdList_value = null;
038        node.containsElementOf_TypeDecl_values = null;
039        node.flags_computed = false;
040        node.in$Circle(false);
041        node.is$Final(false);
042        return node;
043      }
044    /**
045     * @apilevel internal
046     */
047      @SuppressWarnings({"unchecked", "cast"})
048    public AnnotationDecl copy() {
049      
050      try {
051        AnnotationDecl node = (AnnotationDecl) clone();
052        node.parent = null;
053        if(children != null)
054          node.children = (ASTNode[]) children.clone();
055        
056        return node;
057      } catch (CloneNotSupportedException e) {
058        throw new Error("Error: clone not supported for " + getClass().getName());
059      }
060      
061    }/**
062     * Create a deep copy of the AST subtree at this node.
063     * The copy is dangling, i.e. has no parent.
064     * @return dangling copy of the subtree at this node
065     * @apilevel low-level
066     */
067      @SuppressWarnings({"unchecked", "cast"})
068    public AnnotationDecl fullCopy() {
069      
070      AnnotationDecl tree = (AnnotationDecl) copy();
071      if (children != null) {
072        for (int i = 0; i < children.length; ++i) {
073                    switch (i) {
074                    case 3:
075                      tree.children[i] = new List();
076                      continue;
077                    }
078          ASTNode child = (ASTNode) children[i];
079          if(child != null) {
080            child = child.fullCopy();
081            tree.setChild(child, i);
082          }
083        }
084      }
085      return tree;
086      
087    }  /**
088       * @ast method 
089       * @aspect Annotations
090       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:103
091       */
092      public void typeCheck() {
093        super.typeCheck();
094        for(int i = 0; i < getNumBodyDecl(); i++) {
095          if(getBodyDecl(i) instanceof MethodDecl) {
096            MethodDecl m = (MethodDecl)getBodyDecl(i);
097            if(!m.type().isValidAnnotationMethodReturnType())
098              m.error("invalid type for annotation member");
099            if(m.annotationMethodOverride())
100              m.error("annotation method overrides " + m.signature());
101          }
102        }
103        if(containsElementOf(this))
104          error("cyclic annotation element type");
105      }
106      /**
107       * @ast method 
108       * @aspect Annotations
109       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:562
110       */
111      public void toString(StringBuffer s) {
112        getModifiers().toString(s);
113        s.append("@interface " + name());
114        s.append(" {");
115        for(int i=0; i < getNumBodyDecl(); i++) {
116          getBodyDecl(i).toString(s);
117        }
118        s.append(indent() + "}");
119      }
120      /**
121       * @ast method 
122       * 
123       */
124      public AnnotationDecl() {
125        super();
126    
127    
128      }
129      /**
130       * Initializes the child array to the correct size.
131       * Initializes List and Opt nta children.
132       * @apilevel internal
133       * @ast method
134       * @ast method 
135       * 
136       */
137      public void init$Children() {
138        children = new ASTNode[3];
139        setChild(new List(), 1);
140        setChild(new List(), 2);
141      }
142      /**
143       * @ast method 
144       * 
145       */
146      public AnnotationDecl(Modifiers p0, String p1, List<BodyDecl> p2) {
147        setChild(p0, 0);
148        setID(p1);
149        setChild(p2, 1);
150      }
151      /**
152       * @ast method 
153       * 
154       */
155      public AnnotationDecl(Modifiers p0, beaver.Symbol p1, List<BodyDecl> p2) {
156        setChild(p0, 0);
157        setID(p1);
158        setChild(p2, 1);
159      }
160      /**
161       * @apilevel low-level
162       * @ast method 
163       * 
164       */
165      protected int numChildren() {
166        return 2;
167      }
168      /**
169       * @apilevel internal
170       * @ast method 
171       * 
172       */
173      public boolean mayHaveRewrite() {
174        return false;
175      }
176      /**
177       * Replaces the Modifiers child.
178       * @param node The new node to replace the Modifiers child.
179       * @apilevel high-level
180       * @ast method 
181       * 
182       */
183      public void setModifiers(Modifiers node) {
184        setChild(node, 0);
185      }
186      /**
187       * Retrieves the Modifiers child.
188       * @return The current node used as the Modifiers child.
189       * @apilevel high-level
190       * @ast method 
191       * 
192       */
193      public Modifiers getModifiers() {
194        return (Modifiers)getChild(0);
195      }
196      /**
197       * Retrieves the Modifiers child.
198       * <p><em>This method does not invoke AST transformations.</em></p>
199       * @return The current node used as the Modifiers child.
200       * @apilevel low-level
201       * @ast method 
202       * 
203       */
204      public Modifiers getModifiersNoTransform() {
205        return (Modifiers)getChildNoTransform(0);
206      }
207      /**
208       * Replaces the lexeme ID.
209       * @param value The new value for the lexeme ID.
210       * @apilevel high-level
211       * @ast method 
212       * 
213       */
214      public void setID(String value) {
215        tokenString_ID = value;
216      }
217      /**
218       * JastAdd-internal setter for lexeme ID using the Beaver parser.
219       * @apilevel internal
220       * @ast method 
221       * 
222       */
223      public void setID(beaver.Symbol symbol) {
224        if(symbol.value != null && !(symbol.value instanceof String))
225          throw new UnsupportedOperationException("setID is only valid for String lexemes");
226        tokenString_ID = (String)symbol.value;
227        IDstart = symbol.getStart();
228        IDend = symbol.getEnd();
229      }
230      /**
231       * Retrieves the value for the lexeme ID.
232       * @return The value for the lexeme ID.
233       * @apilevel high-level
234       * @ast method 
235       * 
236       */
237      public String getID() {
238        return tokenString_ID != null ? tokenString_ID : "";
239      }
240      /**
241       * Replaces the BodyDecl list.
242       * @param list The new list node to be used as the BodyDecl list.
243       * @apilevel high-level
244       * @ast method 
245       * 
246       */
247      public void setBodyDeclList(List<BodyDecl> list) {
248        setChild(list, 1);
249      }
250      /**
251       * Retrieves the number of children in the BodyDecl list.
252       * @return Number of children in the BodyDecl list.
253       * @apilevel high-level
254       * @ast method 
255       * 
256       */
257      public int getNumBodyDecl() {
258        return getBodyDeclList().getNumChild();
259      }
260      /**
261       * Retrieves the number of children in the BodyDecl list.
262       * Calling this method will not trigger rewrites..
263       * @return Number of children in the BodyDecl list.
264       * @apilevel low-level
265       * @ast method 
266       * 
267       */
268      public int getNumBodyDeclNoTransform() {
269        return getBodyDeclListNoTransform().getNumChildNoTransform();
270      }
271      /**
272       * Retrieves the element at index {@code i} in the BodyDecl list..
273       * @param i Index of the element to return.
274       * @return The element at position {@code i} in the BodyDecl list.
275       * @apilevel high-level
276       * @ast method 
277       * 
278       */
279      @SuppressWarnings({"unchecked", "cast"})
280      public BodyDecl getBodyDecl(int i) {
281        return (BodyDecl)getBodyDeclList().getChild(i);
282      }
283      /**
284       * Append an element to the BodyDecl list.
285       * @param node The element to append to the BodyDecl list.
286       * @apilevel high-level
287       * @ast method 
288       * 
289       */
290      public void addBodyDecl(BodyDecl node) {
291        List<BodyDecl> list = (parent == null || state == null) ? getBodyDeclListNoTransform() : getBodyDeclList();
292        list.addChild(node);
293      }
294      /**
295       * @apilevel low-level
296       * @ast method 
297       * 
298       */
299      public void addBodyDeclNoTransform(BodyDecl node) {
300        List<BodyDecl> list = getBodyDeclListNoTransform();
301        list.addChild(node);
302      }
303      /**
304       * Replaces the BodyDecl list element at index {@code i} with the new node {@code node}.
305       * @param node The new node to replace the old list element.
306       * @param i The list index of the node to be replaced.
307       * @apilevel high-level
308       * @ast method 
309       * 
310       */
311      public void setBodyDecl(BodyDecl node, int i) {
312        List<BodyDecl> list = getBodyDeclList();
313        list.setChild(node, i);
314      }
315      /**
316       * Retrieves the BodyDecl list.
317       * @return The node representing the BodyDecl list.
318       * @apilevel high-level
319       * @ast method 
320       * 
321       */
322      public List<BodyDecl> getBodyDecls() {
323        return getBodyDeclList();
324      }
325      /**
326       * Retrieves the BodyDecl list.
327       * <p><em>This method does not invoke AST transformations.</em></p>
328       * @return The node representing the BodyDecl list.
329       * @apilevel low-level
330       * @ast method 
331       * 
332       */
333      public List<BodyDecl> getBodyDeclsNoTransform() {
334        return getBodyDeclListNoTransform();
335      }
336      /**
337       * Retrieves the BodyDecl list.
338       * @return The node representing the BodyDecl list.
339       * @apilevel high-level
340       * @ast method 
341       * 
342       */
343      @SuppressWarnings({"unchecked", "cast"})
344      public List<BodyDecl> getBodyDeclList() {
345        List<BodyDecl> list = (List<BodyDecl>)getChild(1);
346        list.getNumChild();
347        return list;
348      }
349      /**
350       * Retrieves the BodyDecl list.
351       * <p><em>This method does not invoke AST transformations.</em></p>
352       * @return The node representing the BodyDecl list.
353       * @apilevel low-level
354       * @ast method 
355       * 
356       */
357      @SuppressWarnings({"unchecked", "cast"})
358      public List<BodyDecl> getBodyDeclListNoTransform() {
359        return (List<BodyDecl>)getChildNoTransform(1);
360      }
361      /**
362       * Replaces the SuperInterfaceId list.
363       * @param list The new list node to be used as the SuperInterfaceId list.
364       * @apilevel high-level
365       * @ast method 
366       * 
367       */
368      public void setSuperInterfaceIdList(List<Access> list) {
369        setChild(list, 2);
370      }
371      /**
372       * Retrieves the number of children in the SuperInterfaceId list.
373       * @return Number of children in the SuperInterfaceId list.
374       * @apilevel high-level
375       * @ast method 
376       * 
377       */
378      public int getNumSuperInterfaceId() {
379        return getSuperInterfaceIdList().getNumChild();
380      }
381      /**
382       * Retrieves the number of children in the SuperInterfaceId list.
383       * Calling this method will not trigger rewrites..
384       * @return Number of children in the SuperInterfaceId list.
385       * @apilevel low-level
386       * @ast method 
387       * 
388       */
389      public int getNumSuperInterfaceIdNoTransform() {
390        return getSuperInterfaceIdListNoTransform().getNumChildNoTransform();
391      }
392      /**
393       * Retrieves the element at index {@code i} in the SuperInterfaceId list..
394       * @param i Index of the element to return.
395       * @return The element at position {@code i} in the SuperInterfaceId list.
396       * @apilevel high-level
397       * @ast method 
398       * 
399       */
400      @SuppressWarnings({"unchecked", "cast"})
401      public Access getSuperInterfaceId(int i) {
402        return (Access)getSuperInterfaceIdList().getChild(i);
403      }
404      /**
405       * Append an element to the SuperInterfaceId list.
406       * @param node The element to append to the SuperInterfaceId list.
407       * @apilevel high-level
408       * @ast method 
409       * 
410       */
411      public void addSuperInterfaceId(Access node) {
412        List<Access> list = (parent == null || state == null) ? getSuperInterfaceIdListNoTransform() : getSuperInterfaceIdList();
413        list.addChild(node);
414      }
415      /**
416       * @apilevel low-level
417       * @ast method 
418       * 
419       */
420      public void addSuperInterfaceIdNoTransform(Access node) {
421        List<Access> list = getSuperInterfaceIdListNoTransform();
422        list.addChild(node);
423      }
424      /**
425       * Replaces the SuperInterfaceId list element at index {@code i} with the new node {@code node}.
426       * @param node The new node to replace the old list element.
427       * @param i The list index of the node to be replaced.
428       * @apilevel high-level
429       * @ast method 
430       * 
431       */
432      public void setSuperInterfaceId(Access node, int i) {
433        List<Access> list = getSuperInterfaceIdList();
434        list.setChild(node, i);
435      }
436      /**
437       * Retrieves the SuperInterfaceId list.
438       * @return The node representing the SuperInterfaceId list.
439       * @apilevel high-level
440       * @ast method 
441       * 
442       */
443      public List<Access> getSuperInterfaceIds() {
444        return getSuperInterfaceIdList();
445      }
446      /**
447       * Retrieves the SuperInterfaceId list.
448       * <p><em>This method does not invoke AST transformations.</em></p>
449       * @return The node representing the SuperInterfaceId list.
450       * @apilevel low-level
451       * @ast method 
452       * 
453       */
454      public List<Access> getSuperInterfaceIdsNoTransform() {
455        return getSuperInterfaceIdListNoTransform();
456      }
457      /**
458       * Retrieves the SuperInterfaceId list.
459       * <p><em>This method does not invoke AST transformations.</em></p>
460       * @return The node representing the SuperInterfaceId list.
461       * @apilevel low-level
462       * @ast method 
463       * 
464       */
465      public List<Access> getSuperInterfaceIdListNoTransform() {
466        return (List<Access>)getChildNoTransform(2);
467      }
468      /**
469       * Retrieves the child position of the SuperInterfaceId list.
470       * @return The the child position of the SuperInterfaceId list.
471       * @apilevel low-level
472       * @ast method 
473       * 
474       */
475      protected int getSuperInterfaceIdListChildPosition() {
476        return 2;
477      }
478      /**
479       * @apilevel internal
480       */
481      protected boolean getSuperInterfaceIdList_computed = false;
482      /**
483       * @apilevel internal
484       */
485      protected List getSuperInterfaceIdList_value;
486      /* The direct superinterface of an annotation type is always
487      annotation.Annotation.* @attribute syn nta
488       * @aspect Annotations
489       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:99
490       */
491      @SuppressWarnings({"unchecked", "cast"})
492      public List getSuperInterfaceIdList() {
493        if(getSuperInterfaceIdList_computed) {
494          return (List) getChild(getSuperInterfaceIdListChildPosition());
495        }
496          ASTNode$State state = state();
497      int num = state.boundariesCrossed;
498      boolean isFinal = this.is$Final();
499        getSuperInterfaceIdList_value = getSuperInterfaceIdList_compute();
500        setSuperInterfaceIdList(getSuperInterfaceIdList_value);
501      if(isFinal && num == state().boundariesCrossed){ getSuperInterfaceIdList_computed = true; }
502        List node = (List) this.getChild(getSuperInterfaceIdListChildPosition());
503        return node;
504      }
505      /**
506       * @apilevel internal
507       */
508      private List getSuperInterfaceIdList_compute() {
509        return new List().add(new TypeAccess("java.lang.annotation", "Annotation"));
510      }
511      /* It is a compile-time error if the return type of a method declared in an
512      annotation type is any type other than one of the following: one of the
513      primitive types, String, Class and any invocation of Class, an enum type
514      (\ufffd8.9), an annotation type, or an array (\ufffd10) of one of the preceding types.* @attribute syn
515       * @aspect Annotations
516       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:121
517       */
518      public boolean isValidAnnotationMethodReturnType() {
519        ASTNode$State state = state();
520        try {  return true;  }
521        finally {
522        }
523      }
524      protected java.util.Map containsElementOf_TypeDecl_values;
525      /* It is a compile-time error if an annotation type T contains an element of
526      type T, either directly or indirectly.* @attribute syn
527       * @aspect Annotations
528       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:144
529       */
530      @SuppressWarnings({"unchecked", "cast"})
531      public boolean containsElementOf(TypeDecl typeDecl) {
532        Object _parameters = typeDecl;
533        if(containsElementOf_TypeDecl_values == null) containsElementOf_TypeDecl_values = new java.util.HashMap(4);
534        ASTNode$State.CircularValue _value;
535        if(containsElementOf_TypeDecl_values.containsKey(_parameters)) {
536          Object _o = containsElementOf_TypeDecl_values.get(_parameters);
537          if(!(_o instanceof ASTNode$State.CircularValue)) {
538            return ((Boolean)_o).booleanValue();
539          }
540          else
541            _value = (ASTNode$State.CircularValue)_o;
542        }
543        else {
544          _value = new ASTNode$State.CircularValue();
545          containsElementOf_TypeDecl_values.put(_parameters, _value);
546          _value.value = Boolean.valueOf(false);
547        }
548        ASTNode$State state = state();
549        if (!state.IN_CIRCLE) {
550          state.IN_CIRCLE = true;
551          int num = state.boundariesCrossed;
552          boolean isFinal = this.is$Final();
553          boolean new_containsElementOf_TypeDecl_value;
554          do {
555            _value.visited = new Integer(state.CIRCLE_INDEX);
556            state.CHANGE = false;
557            new_containsElementOf_TypeDecl_value = containsElementOf_compute(typeDecl);
558            if (new_containsElementOf_TypeDecl_value!=((Boolean)_value.value).booleanValue()) {
559              state.CHANGE = true;
560              _value.value = Boolean.valueOf(new_containsElementOf_TypeDecl_value);
561            }
562            state.CIRCLE_INDEX++;
563          } while (state.CHANGE);
564            if(isFinal && num == state().boundariesCrossed) {
565            containsElementOf_TypeDecl_values.put(_parameters, new_containsElementOf_TypeDecl_value);
566          }
567          else {
568            containsElementOf_TypeDecl_values.remove(_parameters);
569          state.RESET_CYCLE = true;
570          containsElementOf_compute(typeDecl);
571          state.RESET_CYCLE = false;
572          }
573          state.IN_CIRCLE = false; 
574          return new_containsElementOf_TypeDecl_value;
575        }
576        if(!new Integer(state.CIRCLE_INDEX).equals(_value.visited)) {
577          _value.visited = new Integer(state.CIRCLE_INDEX);
578          boolean new_containsElementOf_TypeDecl_value = containsElementOf_compute(typeDecl);
579          if (state.RESET_CYCLE) {
580            containsElementOf_TypeDecl_values.remove(_parameters);
581          }
582          else if (new_containsElementOf_TypeDecl_value!=((Boolean)_value.value).booleanValue()) {
583            state.CHANGE = true;
584            _value.value = new_containsElementOf_TypeDecl_value;
585          }
586          return new_containsElementOf_TypeDecl_value;
587        }
588        return ((Boolean)_value.value).booleanValue();
589      }
590      /**
591       * @apilevel internal
592       */
593      private boolean containsElementOf_compute(TypeDecl typeDecl) {
594        for(int i = 0; i < getNumBodyDecl(); i++) {
595          if(getBodyDecl(i) instanceof MethodDecl) {
596            MethodDecl m = (MethodDecl)getBodyDecl(i);
597            if(m.type() == typeDecl)
598              return true;
599            if(m.type() instanceof AnnotationDecl && ((AnnotationDecl)m.type()).containsElementOf(typeDecl))
600              return true;
601          }
602        }
603        return false;
604      }
605      /**
606       * @attribute syn
607       * @aspect Annotations
608       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:545
609       */
610      public boolean isAnnotationDecl() {
611        ASTNode$State state = state();
612        try {  return true;  }
613        finally {
614        }
615      }
616      /**
617       * @apilevel internal
618       */
619      protected boolean flags_computed = false;
620      /**
621       * @apilevel internal
622       */
623      protected int flags_value;
624      /**
625       * @attribute syn
626       * @aspect AnnotationsCodegen
627       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/AnnotationsCodegen.jrag:141
628       */
629      @SuppressWarnings({"unchecked", "cast"})
630      public int flags() {
631        if(flags_computed) {
632          return flags_value;
633        }
634          ASTNode$State state = state();
635      int num = state.boundariesCrossed;
636      boolean isFinal = this.is$Final();
637        flags_value = flags_compute();
638      if(isFinal && num == state().boundariesCrossed){ flags_computed = true; }
639            return flags_value;
640      }
641      /**
642       * @apilevel internal
643       */
644      private int flags_compute() {  return super.flags() | Modifiers.ACC_ANNOTATION;  }
645      /**
646       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Annotations.jrag:77
647       * @apilevel internal
648       */
649      public boolean Define_boolean_mayUseAnnotationTarget(ASTNode caller, ASTNode child, String name) {
650        if(caller == getModifiersNoTransform()) {
651          return name.equals("ANNOTATION_TYPE") || name.equals("TYPE");
652        }
653        else {      return super.Define_boolean_mayUseAnnotationTarget(caller, child, name);
654        }
655      }
656      /**
657       * @apilevel internal
658       */
659      public ASTNode rewriteTo() {
660        return super.rewriteTo();
661      }
662    }