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