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