001    package edu.rice.cs.javalanglevels.tree;
002    
003    import edu.rice.cs.javalanglevels.SourceInfo;
004    
005    /**
006     * Class ForStatement, 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 ForStatement extends Statement {
011      private final ForInitI _init;
012      private final ForConditionI _condition;
013      private final UnparenthesizedExpressionList _update;
014      private final Statement _code;
015    
016      /**
017       * Constructs a ForStatement.
018       * @throws java.lang.IllegalArgumentException  If any parameter to the constructor is null.
019       */
020      public ForStatement(SourceInfo in_sourceInfo, ForInitI in_init, ForConditionI in_condition, UnparenthesizedExpressionList in_update, Statement in_code) {
021        super(in_sourceInfo);
022    
023        if (in_init == null) {
024          throw new java.lang.IllegalArgumentException("Parameter 'init' to the ForStatement constructor was null. This class may not have null field values.");
025        }
026        _init = in_init;
027    
028        if (in_condition == null) {
029          throw new java.lang.IllegalArgumentException("Parameter 'condition' to the ForStatement constructor was null. This class may not have null field values.");
030        }
031        _condition = in_condition;
032    
033        if (in_update == null) {
034          throw new java.lang.IllegalArgumentException("Parameter 'update' to the ForStatement constructor was null. This class may not have null field values.");
035        }
036        _update = in_update;
037    
038        if (in_code == null) {
039          throw new java.lang.IllegalArgumentException("Parameter 'code' to the ForStatement constructor was null. This class may not have null field values.");
040        }
041        _code = in_code;
042      }
043    
044      final public ForInitI getInit() { return _init; }
045      final public ForConditionI getCondition() { return _condition; }
046      final public UnparenthesizedExpressionList getUpdate() { return _update; }
047      final public Statement getCode() { return _code; }
048    
049      public <RetType> RetType visit(JExpressionIFVisitor<RetType> visitor) { return visitor.forForStatement(this); }
050      public void visit(JExpressionIFVisitor_void visitor) { visitor.forForStatement(this); }
051    
052      /**
053       * Implementation of toString that uses
054       * {@link #output} to generated nicely tabbed tree.
055       */
056      public java.lang.String toString() {
057        java.io.StringWriter w = new java.io.StringWriter();
058        output(w);
059        return w.toString();
060      }
061    
062      /**
063       * Prints this object out as a nicely tabbed tree.
064       */
065      public void output(java.io.Writer writer) {
066        outputHelp(new TabPrintWriter(writer, 2));
067      }
068    
069      public void outputHelp(TabPrintWriter writer) {
070        writer.print("ForStatement" + ":");
071        writer.indent();
072    
073        writer.startLine("");
074        writer.print("sourceInfo = ");
075        SourceInfo temp_sourceInfo = getSourceInfo();
076        if (temp_sourceInfo == null) {
077          writer.print("null");
078        } else {
079          writer.print(temp_sourceInfo);
080        }
081    
082        writer.startLine("");
083        writer.print("init = ");
084        ForInitI temp_init = getInit();
085        if (temp_init == null) {
086          writer.print("null");
087        } else {
088          temp_init.outputHelp(writer);
089        }
090    
091        writer.startLine("");
092        writer.print("condition = ");
093        ForConditionI temp_condition = getCondition();
094        if (temp_condition == null) {
095          writer.print("null");
096        } else {
097          temp_condition.outputHelp(writer);
098        }
099    
100        writer.startLine("");
101        writer.print("update = ");
102        UnparenthesizedExpressionList temp_update = getUpdate();
103        if (temp_update == null) {
104          writer.print("null");
105        } else {
106          temp_update.outputHelp(writer);
107        }
108    
109        writer.startLine("");
110        writer.print("code = ");
111        Statement temp_code = getCode();
112        if (temp_code == null) {
113          writer.print("null");
114        } else {
115          temp_code.outputHelp(writer);
116        }
117        writer.unindent();
118      }
119    
120      /**
121       * Implementation of equals that is based on the values
122       * of the fields of the object. Thus, two objects 
123       * created with identical parameters will be equal.
124       */
125      public boolean equals(java.lang.Object obj) {
126        if (obj == null) return false;
127        if ((obj.getClass() != this.getClass()) || (obj.hashCode() != this.hashCode())) {
128          return false;
129        } else {
130          ForStatement casted = (ForStatement) obj;
131          if (! (getInit().equals(casted.getInit()))) return false;
132          if (! (getCondition().equals(casted.getCondition()))) return false;
133          if (! (getUpdate().equals(casted.getUpdate()))) return false;
134          if (! (getCode().equals(casted.getCode()))) return false;
135          return true;
136        }
137      }
138    
139      /**
140       * Implementation of hashCode that is consistent with
141       * equals. The value of the hashCode is formed by
142       * XORing the hashcode of the class object with
143       * the hashcodes of all the fields of the object.
144       */
145      protected int generateHashCode() {
146        int code = getClass().hashCode();
147        code ^= 0;
148        code ^= getInit().hashCode();
149        code ^= getCondition().hashCode();
150        code ^= getUpdate().hashCode();
151        code ^= getCode().hashCode();
152        return code;
153      }
154    }