    001    /* Copyright 2000, 2001, Compaq Computer Corporation */
    002
    003    /* IF THIS IS A JAVA FILE, DO NOT EDIT IT!
    004
    005       Most Java files in this directory which are part of the Javafe AST
    006       are automatically generated using the astgen comment (see
    007       ESCTools/Javafe/astgen) from the input file 'hierarchy.h'.  If you
    008       wish to modify AST classes or introduce new ones, modify
    009       'hierarchy.j.'
    010     */
    011
    012    package javafe.ast;
    013
    014    import javafe.util.Assert;
    015    import javafe.util.Location;
    016    import javafe.util.ErrorSet;
    017
    018    // Convention: unless otherwise noted, integer fields named "loc" refer
    019    // to the location of the first character of the syntactic unit
    020
    021
    022    public class ClassDecl extends TypeDecl
    023    {
    024      public TypeName superClass;
    025
    026
    027
    028      /** Set the parent pointer of the <code>TypeDeclElem</code>s
    029        inside the <code>this</code>. */
    030      private void postMake() {
    031        for(int i = 0; i < elems.size(); i++)
    032          elems.elementAt(i).setParent(this);
    033      }
    034
    035
    036    // Generated boilerplate constructors:
    037
    038      /**
    039       * Construct a raw ClassDecl whose class invariant(s) have not
    040       * yet been established.  It is the caller's job to
    041       * initialize the returned node's fields so that any
    042       * class invariants hold.
    043       */
    044      //@ requires I_will_establish_invariants_afterwards;
    045      protected ClassDecl() {}    //@ nowarn Invariant,NonNullInit;
    046
    047
    048    // Generated boilerplate methods:
    049
    050      public final int childCount() {
    051         int sz = 0;
    052         if (this.pmodifiers != null) sz += this.pmodifiers.size();
    053         if (this.superInterfaces != null) sz += this.superInterfaces.size();
    054         if (this.tmodifiers != null) sz += this.tmodifiers.size();
    055         if (this.elems != null) sz += this.elems.size();
    056         return sz + 2;
    057      }
    058
    059      public final Object childAt(int index) {
    060              /*throws IndexOutOfBoundsException*/
    061         if (index < 0)
    062            throw new IndexOutOfBoundsException("AST child index " + index);
    063         int indexPre = index;
    064
    065         int sz;
    066
    067         sz = (this.pmodifiers == null ? 0 : this.pmodifiers.size());
    068         if (0 <= index && index < sz)
    069            return this.pmodifiers.elementAt(index);
    070         else index -= sz;
    071
    072         if (index == 0) return this.id;
    073         else index--;
    074
    075         sz = (this.superInterfaces == null ? 0 : this.superInterfaces.size());
    076         if (0 <= index && index < sz)
    077            return this.superInterfaces.elementAt(index);
    078         else index -= sz;
    079
    080         sz = (this.tmodifiers == null ? 0 : this.tmodifiers.size());
    081         if (0 <= index && index < sz)
    082            return this.tmodifiers.elementAt(index);
    083         else index -= sz;
    084
    085         sz = (this.elems == null ? 0 : this.elems.size());
    086         if (0 <= index && index < sz)
    087            return this.elems.elementAt(index);
    088         else index -= sz;
    089
    090         if (index == 0) return this.superClass;
    091         else index--;
    092
    093         throw new IndexOutOfBoundsException("AST child index " + indexPre);
    094      }   //@ nowarn Exception;
    095
    096      public final String toString() {
    097         return "[ClassDecl"
    098            + " modifiers = " + this.modifiers
    099            + " pmodifiers = " + this.pmodifiers
    100            + " id = " + this.id
    101            + " superInterfaces = " + this.superInterfaces
    102            + " tmodifiers = " + this.tmodifiers
    103            + " elems = " + this.elems
    104            + " loc = " + this.loc
    105            + " locId = " + this.locId
    106            + " locOpenBrace = " + this.locOpenBrace
    107            + " locCloseBrace = " + this.locCloseBrace
    108            + " superClass = " + this.superClass
    109            + "]";
    110      }
    111
    112      public final int getTag() {
    113         return TagConstants.CLASSDECL;
    114      }
    115
    116      public final void accept(Visitor v) { v.visitClassDecl(this); }
    117
    118      public final Object accept(VisitorArgResult v, Object o) {return v.visitClassDecl(this, o); }
    119
    120      public void check() {
    121         super.check();
    122         if (this.pmodifiers != null)
    123            for(int i = 0; i < this.pmodifiers.size(); i++)
    124               this.pmodifiers.elementAt(i).check();
    125         if (this.id == null) throw new RuntimeException();
    126         for(int i = 0; i < this.superInterfaces.size(); i++)
    127            this.superInterfaces.elementAt(i).check();
    128         if (this.tmodifiers != null)
    129            for(int i = 0; i < this.tmodifiers.size(); i++)
    130               this.tmodifiers.elementAt(i).check();
    131         if (this.elems == null) throw new RuntimeException();
    132         if (this.superClass != null)
    133            this.superClass.check();
    134      }
    135
    136      //@ requires loc != javafe.util.Location.NULL;
    137      //@ requires locId != javafe.util.Location.NULL;
    138      //@ requires locOpenBrace != javafe.util.Location.NULL;
    139      //@ requires locCloseBrace != javafe.util.Location.NULL;
    140      //@ ensures \result != null;
    141      public static ClassDecl make(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ TypeNameVec superInterfaces, TypeModifierPragmaVec tmodifiers, /*@ non_null @*/ TypeDeclElemVec elems, int loc, int locId, int locOpenBrace, int locCloseBrace, TypeName superClass) {
    142         //@ set I_will_establish_invariants_afterwards = true;
    143         ClassDecl result = new ClassDecl();
    144         result.modifiers = modifiers;
    145         result.pmodifiers = pmodifiers;
    146         result.id = id;
    147         result.superInterfaces = superInterfaces;
    148         result.tmodifiers = tmodifiers;
    149         result.elems = elems;
    150         result.loc = loc;
    151         result.locId = locId;
    152         result.locOpenBrace = locOpenBrace;
    153         result.locCloseBrace = locCloseBrace;
    154         result.superClass = superClass;
    155         result.postMake();
    156         return result;
    157      }
    158    }