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