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