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 GLBType : {@link ReferenceType} ::= <span class="component">{@link Modifiers}</span> <span class="component">&lt;ID:String&gt;</span> <span class="component">{@link BodyDecl}*</span> <span class="component">TypeBound:{@link Access}*</span>;
015     * @ast node
016     * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.ast:47
017     */
018    public class GLBType extends ReferenceType 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 GLBType clone() throws CloneNotSupportedException {
034        GLBType node = (GLBType)super.clone();
035        node.subtype_TypeDecl_values = null;
036        node.in$Circle(false);
037        node.is$Final(false);
038        return node;
039      }
040    /**
041     * @apilevel internal
042     */
043      @SuppressWarnings({"unchecked", "cast"})
044    public GLBType copy() {
045      
046      try {
047        GLBType node = (GLBType) clone();
048        node.parent = null;
049        if(children != null)
050          node.children = (ASTNode[]) children.clone();
051        
052        return node;
053      } catch (CloneNotSupportedException e) {
054        throw new Error("Error: clone not supported for " + getClass().getName());
055      }
056      
057    }/**
058     * Create a deep copy of the AST subtree at this node.
059     * The copy is dangling, i.e. has no parent.
060     * @return dangling copy of the subtree at this node
061     * @apilevel low-level
062     */
063      @SuppressWarnings({"unchecked", "cast"})
064    public GLBType fullCopy() {
065      
066      GLBType tree = (GLBType) copy();
067      if (children != null) {
068        for (int i = 0; i < children.length; ++i) {
069          
070          ASTNode child = (ASTNode) children[i];
071          if(child != null) {
072            child = child.fullCopy();
073            tree.setChild(child, i);
074          }
075        }
076      }
077      return tree;
078      
079    }  /**
080       * @ast method 
081       * @aspect LookupParTypeDecl
082       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.jrag:1482
083       */
084      public HashSet implementedInterfaces(){
085        HashSet ret = new HashSet();
086        for (int i = 0; i < getNumTypeBound(); i++) {
087          ret.addAll(getTypeBound(i).type().implementedInterfaces());
088        }
089        return ret;
090      }
091      /**
092       * @ast method 
093       * 
094       */
095      public GLBType() {
096        super();
097    
098    
099      }
100      /**
101       * Initializes the child array to the correct size.
102       * Initializes List and Opt nta children.
103       * @apilevel internal
104       * @ast method
105       * @ast method 
106       * 
107       */
108      public void init$Children() {
109        children = new ASTNode[3];
110        setChild(new List(), 1);
111        setChild(new List(), 2);
112      }
113      /**
114       * @ast method 
115       * 
116       */
117      public GLBType(Modifiers p0, String p1, List<BodyDecl> p2, List<Access> p3) {
118        setChild(p0, 0);
119        setID(p1);
120        setChild(p2, 1);
121        setChild(p3, 2);
122      }
123      /**
124       * @ast method 
125       * 
126       */
127      public GLBType(Modifiers p0, beaver.Symbol p1, List<BodyDecl> p2, List<Access> p3) {
128        setChild(p0, 0);
129        setID(p1);
130        setChild(p2, 1);
131        setChild(p3, 2);
132      }
133      /**
134       * @apilevel low-level
135       * @ast method 
136       * 
137       */
138      protected int numChildren() {
139        return 3;
140      }
141      /**
142       * @apilevel internal
143       * @ast method 
144       * 
145       */
146      public boolean mayHaveRewrite() {
147        return false;
148      }
149      /**
150       * Replaces the Modifiers child.
151       * @param node The new node to replace the Modifiers child.
152       * @apilevel high-level
153       * @ast method 
154       * 
155       */
156      public void setModifiers(Modifiers node) {
157        setChild(node, 0);
158      }
159      /**
160       * Retrieves the Modifiers child.
161       * @return The current node used as the Modifiers child.
162       * @apilevel high-level
163       * @ast method 
164       * 
165       */
166      public Modifiers getModifiers() {
167        return (Modifiers)getChild(0);
168      }
169      /**
170       * Retrieves the Modifiers child.
171       * <p><em>This method does not invoke AST transformations.</em></p>
172       * @return The current node used as the Modifiers child.
173       * @apilevel low-level
174       * @ast method 
175       * 
176       */
177      public Modifiers getModifiersNoTransform() {
178        return (Modifiers)getChildNoTransform(0);
179      }
180      /**
181       * Replaces the lexeme ID.
182       * @param value The new value for the lexeme ID.
183       * @apilevel high-level
184       * @ast method 
185       * 
186       */
187      public void setID(String value) {
188        tokenString_ID = value;
189      }
190      /**
191       * JastAdd-internal setter for lexeme ID using the Beaver parser.
192       * @apilevel internal
193       * @ast method 
194       * 
195       */
196      public void setID(beaver.Symbol symbol) {
197        if(symbol.value != null && !(symbol.value instanceof String))
198          throw new UnsupportedOperationException("setID is only valid for String lexemes");
199        tokenString_ID = (String)symbol.value;
200        IDstart = symbol.getStart();
201        IDend = symbol.getEnd();
202      }
203      /**
204       * Retrieves the value for the lexeme ID.
205       * @return The value for the lexeme ID.
206       * @apilevel high-level
207       * @ast method 
208       * 
209       */
210      public String getID() {
211        return tokenString_ID != null ? tokenString_ID : "";
212      }
213      /**
214       * Replaces the BodyDecl list.
215       * @param list The new list node to be used as the BodyDecl list.
216       * @apilevel high-level
217       * @ast method 
218       * 
219       */
220      public void setBodyDeclList(List<BodyDecl> list) {
221        setChild(list, 1);
222      }
223      /**
224       * Retrieves the number of children in the BodyDecl list.
225       * @return Number of children in the BodyDecl list.
226       * @apilevel high-level
227       * @ast method 
228       * 
229       */
230      public int getNumBodyDecl() {
231        return getBodyDeclList().getNumChild();
232      }
233      /**
234       * Retrieves the number of children in the BodyDecl list.
235       * Calling this method will not trigger rewrites..
236       * @return Number of children in the BodyDecl list.
237       * @apilevel low-level
238       * @ast method 
239       * 
240       */
241      public int getNumBodyDeclNoTransform() {
242        return getBodyDeclListNoTransform().getNumChildNoTransform();
243      }
244      /**
245       * Retrieves the element at index {@code i} in the BodyDecl list..
246       * @param i Index of the element to return.
247       * @return The element at position {@code i} in the BodyDecl list.
248       * @apilevel high-level
249       * @ast method 
250       * 
251       */
252      @SuppressWarnings({"unchecked", "cast"})
253      public BodyDecl getBodyDecl(int i) {
254        return (BodyDecl)getBodyDeclList().getChild(i);
255      }
256      /**
257       * Append an element to the BodyDecl list.
258       * @param node The element to append to the BodyDecl list.
259       * @apilevel high-level
260       * @ast method 
261       * 
262       */
263      public void addBodyDecl(BodyDecl node) {
264        List<BodyDecl> list = (parent == null || state == null) ? getBodyDeclListNoTransform() : getBodyDeclList();
265        list.addChild(node);
266      }
267      /**
268       * @apilevel low-level
269       * @ast method 
270       * 
271       */
272      public void addBodyDeclNoTransform(BodyDecl node) {
273        List<BodyDecl> list = getBodyDeclListNoTransform();
274        list.addChild(node);
275      }
276      /**
277       * Replaces the BodyDecl list element at index {@code i} with the new node {@code node}.
278       * @param node The new node to replace the old list element.
279       * @param i The list index of the node to be replaced.
280       * @apilevel high-level
281       * @ast method 
282       * 
283       */
284      public void setBodyDecl(BodyDecl node, int i) {
285        List<BodyDecl> list = getBodyDeclList();
286        list.setChild(node, i);
287      }
288      /**
289       * Retrieves the BodyDecl list.
290       * @return The node representing the BodyDecl list.
291       * @apilevel high-level
292       * @ast method 
293       * 
294       */
295      public List<BodyDecl> getBodyDecls() {
296        return getBodyDeclList();
297      }
298      /**
299       * Retrieves the BodyDecl list.
300       * <p><em>This method does not invoke AST transformations.</em></p>
301       * @return The node representing the BodyDecl list.
302       * @apilevel low-level
303       * @ast method 
304       * 
305       */
306      public List<BodyDecl> getBodyDeclsNoTransform() {
307        return getBodyDeclListNoTransform();
308      }
309      /**
310       * Retrieves the BodyDecl list.
311       * @return The node representing the BodyDecl list.
312       * @apilevel high-level
313       * @ast method 
314       * 
315       */
316      @SuppressWarnings({"unchecked", "cast"})
317      public List<BodyDecl> getBodyDeclList() {
318        List<BodyDecl> list = (List<BodyDecl>)getChild(1);
319        list.getNumChild();
320        return list;
321      }
322      /**
323       * Retrieves the BodyDecl list.
324       * <p><em>This method does not invoke AST transformations.</em></p>
325       * @return The node representing the BodyDecl list.
326       * @apilevel low-level
327       * @ast method 
328       * 
329       */
330      @SuppressWarnings({"unchecked", "cast"})
331      public List<BodyDecl> getBodyDeclListNoTransform() {
332        return (List<BodyDecl>)getChildNoTransform(1);
333      }
334      /**
335       * Replaces the TypeBound list.
336       * @param list The new list node to be used as the TypeBound list.
337       * @apilevel high-level
338       * @ast method 
339       * 
340       */
341      public void setTypeBoundList(List<Access> list) {
342        setChild(list, 2);
343      }
344      /**
345       * Retrieves the number of children in the TypeBound list.
346       * @return Number of children in the TypeBound list.
347       * @apilevel high-level
348       * @ast method 
349       * 
350       */
351      public int getNumTypeBound() {
352        return getTypeBoundList().getNumChild();
353      }
354      /**
355       * Retrieves the number of children in the TypeBound list.
356       * Calling this method will not trigger rewrites..
357       * @return Number of children in the TypeBound list.
358       * @apilevel low-level
359       * @ast method 
360       * 
361       */
362      public int getNumTypeBoundNoTransform() {
363        return getTypeBoundListNoTransform().getNumChildNoTransform();
364      }
365      /**
366       * Retrieves the element at index {@code i} in the TypeBound list..
367       * @param i Index of the element to return.
368       * @return The element at position {@code i} in the TypeBound list.
369       * @apilevel high-level
370       * @ast method 
371       * 
372       */
373      @SuppressWarnings({"unchecked", "cast"})
374      public Access getTypeBound(int i) {
375        return (Access)getTypeBoundList().getChild(i);
376      }
377      /**
378       * Append an element to the TypeBound list.
379       * @param node The element to append to the TypeBound list.
380       * @apilevel high-level
381       * @ast method 
382       * 
383       */
384      public void addTypeBound(Access node) {
385        List<Access> list = (parent == null || state == null) ? getTypeBoundListNoTransform() : getTypeBoundList();
386        list.addChild(node);
387      }
388      /**
389       * @apilevel low-level
390       * @ast method 
391       * 
392       */
393      public void addTypeBoundNoTransform(Access node) {
394        List<Access> list = getTypeBoundListNoTransform();
395        list.addChild(node);
396      }
397      /**
398       * Replaces the TypeBound list element at index {@code i} with the new node {@code node}.
399       * @param node The new node to replace the old list element.
400       * @param i The list index of the node to be replaced.
401       * @apilevel high-level
402       * @ast method 
403       * 
404       */
405      public void setTypeBound(Access node, int i) {
406        List<Access> list = getTypeBoundList();
407        list.setChild(node, i);
408      }
409      /**
410       * Retrieves the TypeBound list.
411       * @return The node representing the TypeBound list.
412       * @apilevel high-level
413       * @ast method 
414       * 
415       */
416      public List<Access> getTypeBounds() {
417        return getTypeBoundList();
418      }
419      /**
420       * Retrieves the TypeBound list.
421       * <p><em>This method does not invoke AST transformations.</em></p>
422       * @return The node representing the TypeBound list.
423       * @apilevel low-level
424       * @ast method 
425       * 
426       */
427      public List<Access> getTypeBoundsNoTransform() {
428        return getTypeBoundListNoTransform();
429      }
430      /**
431       * Retrieves the TypeBound list.
432       * @return The node representing the TypeBound list.
433       * @apilevel high-level
434       * @ast method 
435       * 
436       */
437      @SuppressWarnings({"unchecked", "cast"})
438      public List<Access> getTypeBoundList() {
439        List<Access> list = (List<Access>)getChild(2);
440        list.getNumChild();
441        return list;
442      }
443      /**
444       * Retrieves the TypeBound list.
445       * <p><em>This method does not invoke AST transformations.</em></p>
446       * @return The node representing the TypeBound list.
447       * @apilevel low-level
448       * @ast method 
449       * 
450       */
451      @SuppressWarnings({"unchecked", "cast"})
452      public List<Access> getTypeBoundListNoTransform() {
453        return (List<Access>)getChildNoTransform(2);
454      }
455      /**
456       * @attribute syn
457       * @aspect LookupParTypeDecl
458       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Generics.jrag:1472
459       */
460      public String typeName() {
461        ASTNode$State state = state();
462        try {
463        if(getNumTypeBound() == 0)
464          return "<NOTYPE>";
465        StringBuffer s = new StringBuffer();
466        s.append(getTypeBound(0).type().typeName());
467        for(int i = 1; i < getNumTypeBound(); i++)
468          s.append(" & " + getTypeBound(i).type().typeName());
469        return s.toString();
470      }
471        finally {
472        }
473      }
474      /**
475       * @attribute syn
476       * @aspect GenericsSubtype
477       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/GenericsSubtype.jrag:347
478       */
479      public boolean supertypeLUBType(LUBType type) {
480        ASTNode$State state = state();
481        try {
482        ArrayList bounds = new ArrayList(getNumTypeBound());
483        for (int i = 0; i < getNumTypeBound(); i++) {
484          bounds.add(getTypeBound(i));
485        }
486        return type == lookupLUBType(bounds);
487      }
488        finally {
489        }
490      }
491      protected java.util.Map subtype_TypeDecl_values;
492      /**
493       * @attribute syn
494       * @aspect GenericsSubtype
495       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/GenericsSubtype.jrag:365
496       */
497      @SuppressWarnings({"unchecked", "cast"})
498      public boolean subtype(TypeDecl type) {
499        Object _parameters = type;
500        if(subtype_TypeDecl_values == null) subtype_TypeDecl_values = new java.util.HashMap(4);
501        ASTNode$State.CircularValue _value;
502        if(subtype_TypeDecl_values.containsKey(_parameters)) {
503          Object _o = subtype_TypeDecl_values.get(_parameters);
504          if(!(_o instanceof ASTNode$State.CircularValue)) {
505            return ((Boolean)_o).booleanValue();
506          }
507          else
508            _value = (ASTNode$State.CircularValue)_o;
509        }
510        else {
511          _value = new ASTNode$State.CircularValue();
512          subtype_TypeDecl_values.put(_parameters, _value);
513          _value.value = Boolean.valueOf(true);
514        }
515        ASTNode$State state = state();
516        if (!state.IN_CIRCLE) {
517          state.IN_CIRCLE = true;
518          int num = state.boundariesCrossed;
519          boolean isFinal = this.is$Final();
520          boolean new_subtype_TypeDecl_value;
521          do {
522            _value.visited = new Integer(state.CIRCLE_INDEX);
523            state.CHANGE = false;
524            new_subtype_TypeDecl_value = subtype_compute(type);
525            if (new_subtype_TypeDecl_value!=((Boolean)_value.value).booleanValue()) {
526              state.CHANGE = true;
527              _value.value = Boolean.valueOf(new_subtype_TypeDecl_value);
528            }
529            state.CIRCLE_INDEX++;
530          } while (state.CHANGE);
531            if(isFinal && num == state().boundariesCrossed) {
532            subtype_TypeDecl_values.put(_parameters, new_subtype_TypeDecl_value);
533          }
534          else {
535            subtype_TypeDecl_values.remove(_parameters);
536          state.RESET_CYCLE = true;
537          subtype_compute(type);
538          state.RESET_CYCLE = false;
539          }
540          state.IN_CIRCLE = false; 
541          return new_subtype_TypeDecl_value;
542        }
543        if(!new Integer(state.CIRCLE_INDEX).equals(_value.visited)) {
544          _value.visited = new Integer(state.CIRCLE_INDEX);
545          boolean new_subtype_TypeDecl_value = subtype_compute(type);
546          if (state.RESET_CYCLE) {
547            subtype_TypeDecl_values.remove(_parameters);
548          }
549          else if (new_subtype_TypeDecl_value!=((Boolean)_value.value).booleanValue()) {
550            state.CHANGE = true;
551            _value.value = new_subtype_TypeDecl_value;
552          }
553          return new_subtype_TypeDecl_value;
554        }
555        return ((Boolean)_value.value).booleanValue();
556      }
557      /**
558       * @apilevel internal
559       */
560      private boolean subtype_compute(TypeDecl type) {  return type.supertypeGLBType(this);  }
561      /**
562       * @attribute syn
563       * @aspect GenericsSubtype
564       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/GenericsSubtype.jrag:366
565       */
566      public boolean supertypeGLBType(GLBType type) {
567        ASTNode$State state = state();
568        try {  return this == type;  }
569        finally {
570        }
571      }
572      /**
573       * @apilevel internal
574       */
575      public ASTNode rewriteTo() {
576        return super.rewriteTo();
577      }
578    }