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     * @production EnumConstant : {@link FieldDeclaration} ::= <span class="component">{@link Modifiers}</span> <span class="component">&lt;ID:String&gt;</span> <span class="component">Arg:{@link Expr}*</span> <span class="component">[Init:{@link Expr}]</span> <span class="component">TypeAccess:{@link Access}</span>;
015     * @ast node
016     * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.ast:3
017     */
018    public class EnumConstant extends FieldDeclaration implements Cloneable {
019      /**
020       * @apilevel low-level
021       */
022      public void flushCache() {
023      }
024      /**
025       * @apilevel internal
026       */
027      public void flushCollectionCache() {
028      }
029      /**
030       * @apilevel internal
031       */
032      @SuppressWarnings({"unchecked", "cast"})
033      public EnumConstant clone() throws CloneNotSupportedException {
034        EnumConstant node = (EnumConstant)super.clone();
035        node.getTypeAccess_computed = false;
036        node.getTypeAccess_value = null;
037        node.localMethodsSignatureMap_computed = false;
038        node.localMethodsSignatureMap_value = 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 EnumConstant copy() {
049      
050      try {
051        EnumConstant node = (EnumConstant) 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 EnumConstant fullCopy() {
069      
070      EnumConstant tree = (EnumConstant) copy();
071      if (children != null) {
072        for (int i = 0; i < children.length; ++i) {
073                    switch (i) {
074                    case 4:
075                      tree.children[i] = null;
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 Enums
090       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:197
091       */
092      public EnumConstant(Modifiers mods, String name, List<Expr> args, List<BodyDecl> bds) {
093        this(mods, name, args, new Opt<Expr>(new EnumInstanceExpr(createOptAnonymousDecl(bds))));
094      }
095      /**
096       * @ast method 
097       * @aspect Enums
098       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:236
099       */
100      private static Opt<TypeDecl> createOptAnonymousDecl(List<BodyDecl> bds) {
101        if(bds.getNumChildNoTransform() == 0)
102          return new Opt<TypeDecl>();
103        return new Opt<TypeDecl>(
104          new AnonymousDecl(
105            new Modifiers(),
106            "Anonymous",
107            bds
108          )
109        );
110      }
111      /**
112       * @ast method 
113       * @aspect Enums
114       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:249
115       */
116      public int getNumBodyDecl() {
117        int cnt = 0;
118        ClassInstanceExpr init = (ClassInstanceExpr)getInit();
119        if(!init.hasTypeDecl())
120          return 0;
121        for(BodyDecl bd : init.getTypeDecl().getBodyDecls())
122          if(!(bd instanceof ConstructorDecl))
123            ++cnt;
124        return cnt;
125      }
126      /**
127       * @ast method 
128       * @aspect Enums
129       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:260
130       */
131      public BodyDecl getBodyDecl(int i) {
132        ClassInstanceExpr init = (ClassInstanceExpr)getInit();
133        if(init.hasTypeDecl())
134          for(BodyDecl bd : init.getTypeDecl().getBodyDecls())
135            if(!(bd instanceof ConstructorDecl))
136              if(i-- == 0)
137                return bd;
138        throw new ArrayIndexOutOfBoundsException(i);
139      }
140      /**
141       * @ast method 
142       * @aspect Enums
143       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:592
144       */
145      public void toString(StringBuffer s) {
146        s.append(indent());
147        getModifiers().toString(s);
148        s.append(getID());
149        s.append("(");
150        if(getNumArg() > 0) {
151          getArg(0).toString(s);
152          for(int i = 1; i < getNumArg(); i++) {
153            s.append(", ");
154            getArg(i).toString(s);
155          }
156        }
157        s.append(")");
158        if(getNumBodyDecl() > 0) {
159          s.append(" {");
160          for(int i=0; i < getNumBodyDecl(); i++) {
161            BodyDecl d = getBodyDecl(i);
162            d.toString(s);
163          }
164          s.append(indent() + "}");
165        }
166        s.append(",\n");
167      }
168      /**
169       * @ast method 
170       * 
171       */
172      public EnumConstant() {
173        super();
174    
175    
176      }
177      /**
178       * Initializes the child array to the correct size.
179       * Initializes List and Opt nta children.
180       * @apilevel internal
181       * @ast method
182       * @ast method 
183       * 
184       */
185      public void init$Children() {
186        children = new ASTNode[4];
187        setChild(new List(), 1);
188        setChild(new Opt(), 2);
189      }
190      /**
191       * @ast method 
192       * 
193       */
194      public EnumConstant(Modifiers p0, String p1, List<Expr> p2, Opt<Expr> p3) {
195        setChild(p0, 0);
196        setID(p1);
197        setChild(p2, 1);
198        setChild(p3, 2);
199      }
200      /**
201       * @ast method 
202       * 
203       */
204      public EnumConstant(Modifiers p0, beaver.Symbol p1, List<Expr> p2, Opt<Expr> p3) {
205        setChild(p0, 0);
206        setID(p1);
207        setChild(p2, 1);
208        setChild(p3, 2);
209      }
210      /**
211       * @apilevel low-level
212       * @ast method 
213       * 
214       */
215      protected int numChildren() {
216        return 3;
217      }
218      /**
219       * @apilevel internal
220       * @ast method 
221       * 
222       */
223      public boolean mayHaveRewrite() {
224        return false;
225      }
226      /**
227       * Replaces the Modifiers child.
228       * @param node The new node to replace the Modifiers child.
229       * @apilevel high-level
230       * @ast method 
231       * 
232       */
233      public void setModifiers(Modifiers node) {
234        setChild(node, 0);
235      }
236      /**
237       * Retrieves the Modifiers child.
238       * @return The current node used as the Modifiers child.
239       * @apilevel high-level
240       * @ast method 
241       * 
242       */
243      public Modifiers getModifiers() {
244        return (Modifiers)getChild(0);
245      }
246      /**
247       * Retrieves the Modifiers child.
248       * <p><em>This method does not invoke AST transformations.</em></p>
249       * @return The current node used as the Modifiers child.
250       * @apilevel low-level
251       * @ast method 
252       * 
253       */
254      public Modifiers getModifiersNoTransform() {
255        return (Modifiers)getChildNoTransform(0);
256      }
257      /**
258       * Replaces the lexeme ID.
259       * @param value The new value for the lexeme ID.
260       * @apilevel high-level
261       * @ast method 
262       * 
263       */
264      public void setID(String value) {
265        tokenString_ID = value;
266      }
267      /**
268       * JastAdd-internal setter for lexeme ID using the Beaver parser.
269       * @apilevel internal
270       * @ast method 
271       * 
272       */
273      public void setID(beaver.Symbol symbol) {
274        if(symbol.value != null && !(symbol.value instanceof String))
275          throw new UnsupportedOperationException("setID is only valid for String lexemes");
276        tokenString_ID = (String)symbol.value;
277        IDstart = symbol.getStart();
278        IDend = symbol.getEnd();
279      }
280      /**
281       * Retrieves the value for the lexeme ID.
282       * @return The value for the lexeme ID.
283       * @apilevel high-level
284       * @ast method 
285       * 
286       */
287      public String getID() {
288        return tokenString_ID != null ? tokenString_ID : "";
289      }
290      /**
291       * Replaces the Arg list.
292       * @param list The new list node to be used as the Arg list.
293       * @apilevel high-level
294       * @ast method 
295       * 
296       */
297      public void setArgList(List<Expr> list) {
298        setChild(list, 1);
299      }
300      /**
301       * Retrieves the number of children in the Arg list.
302       * @return Number of children in the Arg list.
303       * @apilevel high-level
304       * @ast method 
305       * 
306       */
307      public int getNumArg() {
308        return getArgList().getNumChild();
309      }
310      /**
311       * Retrieves the number of children in the Arg list.
312       * Calling this method will not trigger rewrites..
313       * @return Number of children in the Arg list.
314       * @apilevel low-level
315       * @ast method 
316       * 
317       */
318      public int getNumArgNoTransform() {
319        return getArgListNoTransform().getNumChildNoTransform();
320      }
321      /**
322       * Retrieves the element at index {@code i} in the Arg list..
323       * @param i Index of the element to return.
324       * @return The element at position {@code i} in the Arg list.
325       * @apilevel high-level
326       * @ast method 
327       * 
328       */
329      @SuppressWarnings({"unchecked", "cast"})
330      public Expr getArg(int i) {
331        return (Expr)getArgList().getChild(i);
332      }
333      /**
334       * Append an element to the Arg list.
335       * @param node The element to append to the Arg list.
336       * @apilevel high-level
337       * @ast method 
338       * 
339       */
340      public void addArg(Expr node) {
341        List<Expr> list = (parent == null || state == null) ? getArgListNoTransform() : getArgList();
342        list.addChild(node);
343      }
344      /**
345       * @apilevel low-level
346       * @ast method 
347       * 
348       */
349      public void addArgNoTransform(Expr node) {
350        List<Expr> list = getArgListNoTransform();
351        list.addChild(node);
352      }
353      /**
354       * Replaces the Arg list element at index {@code i} with the new node {@code node}.
355       * @param node The new node to replace the old list element.
356       * @param i The list index of the node to be replaced.
357       * @apilevel high-level
358       * @ast method 
359       * 
360       */
361      public void setArg(Expr node, int i) {
362        List<Expr> list = getArgList();
363        list.setChild(node, i);
364      }
365      /**
366       * Retrieves the Arg list.
367       * @return The node representing the Arg list.
368       * @apilevel high-level
369       * @ast method 
370       * 
371       */
372      public List<Expr> getArgs() {
373        return getArgList();
374      }
375      /**
376       * Retrieves the Arg list.
377       * <p><em>This method does not invoke AST transformations.</em></p>
378       * @return The node representing the Arg list.
379       * @apilevel low-level
380       * @ast method 
381       * 
382       */
383      public List<Expr> getArgsNoTransform() {
384        return getArgListNoTransform();
385      }
386      /**
387       * Retrieves the Arg list.
388       * @return The node representing the Arg list.
389       * @apilevel high-level
390       * @ast method 
391       * 
392       */
393      @SuppressWarnings({"unchecked", "cast"})
394      public List<Expr> getArgList() {
395        List<Expr> list = (List<Expr>)getChild(1);
396        list.getNumChild();
397        return list;
398      }
399      /**
400       * Retrieves the Arg list.
401       * <p><em>This method does not invoke AST transformations.</em></p>
402       * @return The node representing the Arg list.
403       * @apilevel low-level
404       * @ast method 
405       * 
406       */
407      @SuppressWarnings({"unchecked", "cast"})
408      public List<Expr> getArgListNoTransform() {
409        return (List<Expr>)getChildNoTransform(1);
410      }
411      /**
412       * Replaces the optional node for the Init child. This is the {@code Opt} node containing the child Init, not the actual child!
413       * @param opt The new node to be used as the optional node for the Init child.
414       * @apilevel low-level
415       * @ast method 
416       * 
417       */
418      public void setInitOpt(Opt<Expr> opt) {
419        setChild(opt, 2);
420      }
421      /**
422       * Check whether the optional Init child exists.
423       * @return {@code true} if the optional Init child exists, {@code false} if it does not.
424       * @apilevel high-level
425       * @ast method 
426       * 
427       */
428      public boolean hasInit() {
429        return getInitOpt().getNumChild() != 0;
430      }
431      /**
432       * Retrieves the (optional) Init child.
433       * @return The Init child, if it exists. Returns {@code null} otherwise.
434       * @apilevel low-level
435       * @ast method 
436       * 
437       */
438      @SuppressWarnings({"unchecked", "cast"})
439      public Expr getInit() {
440        return (Expr)getInitOpt().getChild(0);
441      }
442      /**
443       * Replaces the (optional) Init child.
444       * @param node The new node to be used as the Init child.
445       * @apilevel high-level
446       * @ast method 
447       * 
448       */
449      public void setInit(Expr node) {
450        getInitOpt().setChild(node, 0);
451      }
452      /**
453       * @apilevel low-level
454       * @ast method 
455       * 
456       */
457      @SuppressWarnings({"unchecked", "cast"})
458      public Opt<Expr> getInitOpt() {
459        return (Opt<Expr>)getChild(2);
460      }
461      /**
462       * Retrieves the optional node for child Init. This is the {@code Opt} node containing the child Init, not the actual child!
463       * <p><em>This method does not invoke AST transformations.</em></p>
464       * @return The optional node for child Init.
465       * @apilevel low-level
466       * @ast method 
467       * 
468       */
469      @SuppressWarnings({"unchecked", "cast"})
470      public Opt<Expr> getInitOptNoTransform() {
471        return (Opt<Expr>)getChildNoTransform(2);
472      }
473      /**
474       * Replaces the TypeAccess child.
475       * @param node The new node to replace the TypeAccess child.
476       * @apilevel high-level
477       * @ast method 
478       * 
479       */
480      public void setTypeAccess(Access node) {
481        setChild(node, 3);
482      }
483      /**
484       * Retrieves the TypeAccess child.
485       * <p><em>This method does not invoke AST transformations.</em></p>
486       * @return The current node used as the TypeAccess child.
487       * @apilevel low-level
488       * @ast method 
489       * 
490       */
491      public Access getTypeAccessNoTransform() {
492        return (Access)getChildNoTransform(3);
493      }
494      /**
495       * Retrieves the child position of the optional child TypeAccess.
496       * @return The the child position of the optional child TypeAccess.
497       * @apilevel low-level
498       * @ast method 
499       * 
500       */
501      protected int getTypeAccessChildPosition() {
502        return 3;
503      }
504      /**
505       * @attribute syn
506       * @aspect Enums
507       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:26
508       */
509      public boolean isEnumConstant() {
510        ASTNode$State state = state();
511        try {  return true;  }
512        finally {
513        }
514      }
515      /**
516       * @attribute syn
517       * @aspect Modifiers
518       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/Modifiers.jrag:239
519       */
520      public boolean isPublic() {
521        ASTNode$State state = state();
522        try {  return true;  }
523        finally {
524        }
525      }
526      /**
527       * @attribute syn
528       * @aspect Modifiers
529       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/Modifiers.jrag:242
530       */
531      public boolean isStatic() {
532        ASTNode$State state = state();
533        try {  return true;  }
534        finally {
535        }
536      }
537      /**
538       * @attribute syn
539       * @aspect Modifiers
540       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/Modifiers.jrag:244
541       */
542      public boolean isFinal() {
543        ASTNode$State state = state();
544        try {  return true;  }
545        finally {
546        }
547      }
548      /**
549       * @apilevel internal
550       */
551      protected boolean getTypeAccess_computed = false;
552      /**
553       * @apilevel internal
554       */
555      protected Access getTypeAccess_value;
556      /**
557       * @attribute syn nta
558       * @aspect Enums
559       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:193
560       */
561      @SuppressWarnings({"unchecked", "cast"})
562      public Access getTypeAccess() {
563        if(getTypeAccess_computed) {
564          return (Access) getChild(getTypeAccessChildPosition());
565        }
566          ASTNode$State state = state();
567      int num = state.boundariesCrossed;
568      boolean isFinal = this.is$Final();
569        getTypeAccess_value = getTypeAccess_compute();
570          setTypeAccess(getTypeAccess_value);
571      if(isFinal && num == state().boundariesCrossed){ getTypeAccess_computed = true; }
572        Access node = (Access) this.getChild(getTypeAccessChildPosition());
573        return node;
574      }
575      /**
576       * @apilevel internal
577       */
578      private Access getTypeAccess_compute() {
579        return hostType().createQualifiedAccess();
580      }
581      /**
582       * @attribute syn
583       * @aspect Enums
584       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:689
585       */
586      public SimpleSet localMethodsSignature(String signature) {
587        ASTNode$State state = state();
588        try {
589        SimpleSet set = (SimpleSet)localMethodsSignatureMap().get(signature);
590        if(set != null) return set;
591        return SimpleSet.emptySet;
592      }
593        finally {
594        }
595      }
596      /**
597       * @apilevel internal
598       */
599      protected boolean localMethodsSignatureMap_computed = false;
600      /**
601       * @apilevel internal
602       */
603      protected HashMap localMethodsSignatureMap_value;
604      /**
605       * @attribute syn
606       * @aspect Enums
607       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:696
608       */
609      @SuppressWarnings({"unchecked", "cast"})
610      public HashMap localMethodsSignatureMap() {
611        if(localMethodsSignatureMap_computed) {
612          return localMethodsSignatureMap_value;
613        }
614          ASTNode$State state = state();
615      int num = state.boundariesCrossed;
616      boolean isFinal = this.is$Final();
617        localMethodsSignatureMap_value = localMethodsSignatureMap_compute();
618      if(isFinal && num == state().boundariesCrossed){ localMethodsSignatureMap_computed = true; }
619            return localMethodsSignatureMap_value;
620      }
621      /**
622       * @apilevel internal
623       */
624      private HashMap localMethodsSignatureMap_compute() {
625        HashMap map = new HashMap(getNumBodyDecl());
626        for(int i = 0; i < getNumBodyDecl(); i++) {
627          if(getBodyDecl(i) instanceof MethodDecl) {
628            MethodDecl decl = (MethodDecl)getBodyDecl(i);
629            map.put(decl.signature(), decl);
630          }
631        }
632        return map;
633      }
634      /**
635       * @attribute syn
636       * @aspect Enums
637       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:707
638       */
639      public boolean implementsMethod(MethodDecl method) {
640        ASTNode$State state = state();
641        try {
642        SimpleSet set = (SimpleSet)localMethodsSignature(method.signature());
643        if (set.size() == 1) {
644          MethodDecl n = (MethodDecl)set.iterator().next();
645          if (!n.isAbstract())
646      return true;
647        }
648        return false;
649      }
650        finally {
651        }
652      }
653      /**
654       * @apilevel internal
655       */
656      protected boolean flags_computed = false;
657      /**
658       * @apilevel internal
659       */
660      protected int flags_value;
661      /**
662       * @attribute syn
663       * @aspect EnumsCodegen
664       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/EnumsCodegen.jrag:14
665       */
666      @SuppressWarnings({"unchecked", "cast"})
667      public int flags() {
668        if(flags_computed) {
669          return flags_value;
670        }
671          ASTNode$State state = state();
672      int num = state.boundariesCrossed;
673      boolean isFinal = this.is$Final();
674        flags_value = flags_compute();
675      if(isFinal && num == state().boundariesCrossed){ flags_computed = true; }
676            return flags_value;
677      }
678      /**
679       * @apilevel internal
680       */
681      private int flags_compute() {  return super.flags() | Modifiers.ACC_ENUM;  }
682      /**
683       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:489
684       * @apilevel internal
685       */
686      public NameType Define_NameType_nameType(ASTNode caller, ASTNode child) {
687        if(caller == getTypeAccessNoTransform()) {
688          return NameType.TYPE_NAME;
689        }
690        else {      return super.Define_NameType_nameType(caller, child);
691        }
692      }
693      /**
694       * @apilevel internal
695       */
696      public ASTNode rewriteTo() {
697        return super.rewriteTo();
698      }
699    }