001    package edu.rice.cs.javalanglevels.tree;
002    
003    import edu.rice.cs.javalanglevels.SourceInfo;
004    
005    /**
006     * Class ConstructorDef, a component of the JExpressionIF composite hierarchy.
007     * Note: null is not allowed as a value for any field.
008     * @version  Generated automatically by ASTGen at Sun Mar 04 23:01:27 CST 2012
009     */
010    public class ConstructorDef extends JExpression implements BodyItemI {
011      private final Word _name;
012      private final ModifiersAndVisibility _mav;
013      private final FormalParameter[] _parameters;
014      private final ReferenceType[] _throws;
015      private final BracedBody _statements;
016    
017      /**
018       * Constructs a ConstructorDef.
019       * @throws java.lang.IllegalArgumentException  If any parameter to the constructor is null.
020       */
021      public ConstructorDef(SourceInfo in_sourceInfo, Word in_name, ModifiersAndVisibility in_mav, FormalParameter[] in_parameters, ReferenceType[] in_throws, BracedBody in_statements) {
022        super(in_sourceInfo);
023    
024        if (in_name == null) {
025          throw new java.lang.IllegalArgumentException("Parameter 'name' to the ConstructorDef constructor was null. This class may not have null field values.");
026        }
027        _name = in_name;
028    
029        if (in_mav == null) {
030          throw new java.lang.IllegalArgumentException("Parameter 'mav' to the ConstructorDef constructor was null. This class may not have null field values.");
031        }
032        _mav = in_mav;
033    
034        if (in_parameters == null) {
035          throw new java.lang.IllegalArgumentException("Parameter 'parameters' to the ConstructorDef constructor was null. This class may not have null field values.");
036        }
037        _parameters = in_parameters;
038    
039        if (in_throws == null) {
040          throw new java.lang.IllegalArgumentException("Parameter 'throws' to the ConstructorDef constructor was null. This class may not have null field values.");
041        }
042        _throws = in_throws;
043    
044        if (in_statements == null) {
045          throw new java.lang.IllegalArgumentException("Parameter 'statements' to the ConstructorDef constructor was null. This class may not have null field values.");
046        }
047        _statements = in_statements;
048      }
049    
050      final public Word getName() { return _name; }
051      final public ModifiersAndVisibility getMav() { return _mav; }
052      final public FormalParameter[] getParameters() { return _parameters; }
053      final public ReferenceType[] getThrows() { return _throws; }
054      final public BracedBody getStatements() { return _statements; }
055    
056      public <RetType> RetType visit(JExpressionIFVisitor<RetType> visitor) { return visitor.forConstructorDef(this); }
057      public void visit(JExpressionIFVisitor_void visitor) { visitor.forConstructorDef(this); }
058    
059      /**
060       * Implementation of toString that uses
061       * {@link #output} to generated nicely tabbed tree.
062       */
063      public java.lang.String toString() {
064        java.io.StringWriter w = new java.io.StringWriter();
065        output(w);
066        return w.toString();
067      }
068    
069      /**
070       * Prints this object out as a nicely tabbed tree.
071       */
072      public void output(java.io.Writer writer) {
073        outputHelp(new TabPrintWriter(writer, 2));
074      }
075    
076      public void outputHelp(TabPrintWriter writer) {
077        writer.print("ConstructorDef" + ":");
078        writer.indent();
079    
080        writer.startLine("");
081        writer.print("sourceInfo = ");
082        SourceInfo temp_sourceInfo = getSourceInfo();
083        if (temp_sourceInfo == null) {
084          writer.print("null");
085        } else {
086          writer.print(temp_sourceInfo);
087        }
088    
089        writer.startLine("");
090        writer.print("name = ");
091        Word temp_name = getName();
092        if (temp_name == null) {
093          writer.print("null");
094        } else {
095          temp_name.outputHelp(writer);
096        }
097    
098        writer.startLine("");
099        writer.print("mav = ");
100        ModifiersAndVisibility temp_mav = getMav();
101        if (temp_mav == null) {
102          writer.print("null");
103        } else {
104          temp_mav.outputHelp(writer);
105        }
106    
107        writer.startLine("");
108        writer.print("parameters = ");
109        writer.print("{");
110        writer.indent();
111        for (int i = 0; i < getParameters().length; i++) {
112          FormalParameter temp_parameters = getParameters()[i];
113          writer.startLine("#" + i + ": ");
114          if (temp_parameters == null) {
115            writer.print("null");
116          } else {
117            temp_parameters.outputHelp(writer);
118          }
119        }
120        writer.unindent();
121        if (getParameters().length > 0) {
122          writer.startLine("");
123        }
124        writer.print("}");
125    
126        writer.startLine("");
127        writer.print("throws = ");
128        writer.print("{");
129        writer.indent();
130        for (int i = 0; i < getThrows().length; i++) {
131          ReferenceType temp_throws = getThrows()[i];
132          writer.startLine("#" + i + ": ");
133          if (temp_throws == null) {
134            writer.print("null");
135          } else {
136            temp_throws.outputHelp(writer);
137          }
138        }
139        writer.unindent();
140        if (getThrows().length > 0) {
141          writer.startLine("");
142        }
143        writer.print("}");
144    
145        writer.startLine("");
146        writer.print("statements = ");
147        BracedBody temp_statements = getStatements();
148        if (temp_statements == null) {
149          writer.print("null");
150        } else {
151          temp_statements.outputHelp(writer);
152        }
153        writer.unindent();
154      }
155    
156      /**
157       * Implementation of equals that is based on the values
158       * of the fields of the object. Thus, two objects 
159       * created with identical parameters will be equal.
160       */
161      public boolean equals(java.lang.Object obj) {
162        if (obj == null) return false;
163        if ((obj.getClass() != this.getClass()) || (obj.hashCode() != this.hashCode())) {
164          return false;
165        } else {
166          ConstructorDef casted = (ConstructorDef) obj;
167          if (! (getName().equals(casted.getName()))) return false;
168          if (! (getMav().equals(casted.getMav()))) return false;
169          if (this.getParameters().length != casted.getParameters().length) return false;
170          for (int i = 0; i < getParameters().length; i++) if (! getParameters()[i].equals(casted.getParameters()[i])) return false;
171          if (this.getThrows().length != casted.getThrows().length) return false;
172          for (int i = 0; i < getThrows().length; i++) if (! getThrows()[i].equals(casted.getThrows()[i])) return false;
173          if (! (getStatements().equals(casted.getStatements()))) return false;
174          return true;
175        }
176      }
177    
178      /**
179       * Implementation of hashCode that is consistent with
180       * equals. The value of the hashCode is formed by
181       * XORing the hashcode of the class object with
182       * the hashcodes of all the fields of the object.
183       */
184      protected int generateHashCode() {
185        int code = getClass().hashCode();
186        code ^= 0;
187        code ^= getName().hashCode();
188        code ^= getMav().hashCode();
189        for (int i = 0; i < getParameters().length; i++) code ^= getParameters()[i].hashCode();
190        for (int i = 0; i < getThrows().length; i++) code ^= getThrows()[i].hashCode();
191        code ^= getStatements().hashCode();
192        return code;
193      }
194    }