001    package edu.rice.cs.javalanglevels.tree;
002    
003    import edu.rice.cs.javalanglevels.SourceInfo;
004    
005    /**
006     * Class BracedBody, 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 BracedBody extends Body {
011    
012      /**
013       * Constructs a BracedBody.
014       * @throws java.lang.IllegalArgumentException  If any parameter to the constructor is null.
015       */
016      public BracedBody(SourceInfo in_sourceInfo, BodyItemI[] in_statements) {
017        super(in_sourceInfo, in_statements);
018      }
019    
020    
021      public <RetType> RetType visit(JExpressionIFVisitor<RetType> visitor) { return visitor.forBracedBody(this); }
022      public void visit(JExpressionIFVisitor_void visitor) { visitor.forBracedBody(this); }
023    
024      /**
025       * Implementation of toString that uses
026       * {@link #output} to generated nicely tabbed tree.
027       */
028      public java.lang.String toString() {
029        java.io.StringWriter w = new java.io.StringWriter();
030        output(w);
031        return w.toString();
032      }
033    
034      /**
035       * Prints this object out as a nicely tabbed tree.
036       */
037      public void output(java.io.Writer writer) {
038        outputHelp(new TabPrintWriter(writer, 2));
039      }
040    
041      public void outputHelp(TabPrintWriter writer) {
042        writer.print("BracedBody" + ":");
043        writer.indent();
044    
045        writer.startLine("");
046        writer.print("sourceInfo = ");
047        SourceInfo temp_sourceInfo = getSourceInfo();
048        if (temp_sourceInfo == null) {
049          writer.print("null");
050        } else {
051          writer.print(temp_sourceInfo);
052        }
053    
054        writer.startLine("");
055        writer.print("statements = ");
056        writer.print("{");
057        writer.indent();
058        for (int i = 0; i < getStatements().length; i++) {
059          BodyItemI temp_statements = getStatements()[i];
060          writer.startLine("#" + i + ": ");
061          if (temp_statements == null) {
062            writer.print("null");
063          } else {
064            temp_statements.outputHelp(writer);
065          }
066        }
067        writer.unindent();
068        if (getStatements().length > 0) {
069          writer.startLine("");
070        }
071        writer.print("}");
072        writer.unindent();
073      }
074    
075      /**
076       * Implementation of equals that is based on the values
077       * of the fields of the object. Thus, two objects 
078       * created with identical parameters will be equal.
079       */
080      public boolean equals(java.lang.Object obj) {
081        if (obj == null) return false;
082        if ((obj.getClass() != this.getClass()) || (obj.hashCode() != this.hashCode())) {
083          return false;
084        } else {
085          BracedBody casted = (BracedBody) obj;
086          if (this.getStatements().length != casted.getStatements().length) return false;
087          for (int i = 0; i < getStatements().length; i++) if (! getStatements()[i].equals(casted.getStatements()[i])) return false;
088          return true;
089        }
090      }
091    
092      /**
093       * Implementation of hashCode that is consistent with
094       * equals. The value of the hashCode is formed by
095       * XORing the hashcode of the class object with
096       * the hashcodes of all the fields of the object.
097       */
098      protected int generateHashCode() {
099        int code = getClass().hashCode();
100        code ^= 0;
101        for (int i = 0; i < getStatements().length; i++) code ^= getStatements()[i].hashCode();
102        return code;
103      }
104    }