001 package edu.rice.cs.javalanglevels.tree;
002
003 import edu.rice.cs.javalanglevels.SourceInfo;
004
005 /**
006 * Class ClassDef, 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 May 27 23:01:27 CDT 2012
009 */
010 public class ClassDef extends TypeDefBase {
011 private final ReferenceType _superclass;
012
013 /**
014 * Constructs a ClassDef.
015 * @throws java.lang.IllegalArgumentException If any parameter to the constructor is null.
016 */
017 public ClassDef(SourceInfo in_sourceInfo, ModifiersAndVisibility in_mav, Word in_name, TypeParameter[] in_typeParameters, ReferenceType in_superclass, ReferenceType[] in_interfaces, BracedBody in_body) {
018 super(in_sourceInfo, in_mav, in_name, in_typeParameters, in_interfaces, in_body);
019
020 if (in_superclass == null) {
021 throw new java.lang.IllegalArgumentException("Parameter 'superclass' to the ClassDef constructor was null. This class may not have null field values.");
022 }
023 _superclass = in_superclass;
024 }
025
026 final public ReferenceType getSuperclass() { return _superclass; }
027
028 public <RetType> RetType visit(JExpressionIFVisitor<RetType> visitor) { return visitor.forClassDef(this); }
029 public void visit(JExpressionIFVisitor_void visitor) { visitor.forClassDef(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("ClassDef" + ":");
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("mav = ");
063 ModifiersAndVisibility temp_mav = getMav();
064 if (temp_mav == null) {
065 writer.print("null");
066 } else {
067 temp_mav.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("typeParameters = ");
081 writer.print("{");
082 writer.indent();
083 for (int i = 0; i < getTypeParameters().length; i++) {
084 TypeParameter temp_typeParameters = getTypeParameters()[i];
085 writer.startLine("#" + i + ": ");
086 if (temp_typeParameters == null) {
087 writer.print("null");
088 } else {
089 temp_typeParameters.outputHelp(writer);
090 }
091 }
092 writer.unindent();
093 if (getTypeParameters().length > 0) {
094 writer.startLine("");
095 }
096 writer.print("}");
097
098 writer.startLine("");
099 writer.print("superclass = ");
100 ReferenceType temp_superclass = getSuperclass();
101 if (temp_superclass == null) {
102 writer.print("null");
103 } else {
104 temp_superclass.outputHelp(writer);
105 }
106
107 writer.startLine("");
108 writer.print("interfaces = ");
109 writer.print("{");
110 writer.indent();
111 for (int i = 0; i < getInterfaces().length; i++) {
112 ReferenceType temp_interfaces = getInterfaces()[i];
113 writer.startLine("#" + i + ": ");
114 if (temp_interfaces == null) {
115 writer.print("null");
116 } else {
117 temp_interfaces.outputHelp(writer);
118 }
119 }
120 writer.unindent();
121 if (getInterfaces().length > 0) {
122 writer.startLine("");
123 }
124 writer.print("}");
125
126 writer.startLine("");
127 writer.print("body = ");
128 BracedBody temp_body = getBody();
129 if (temp_body == null) {
130 writer.print("null");
131 } else {
132 temp_body.outputHelp(writer);
133 }
134 writer.unindent();
135 }
136
137 /**
138 * Implementation of equals that is based on the values
139 * of the fields of the object. Thus, two objects
140 * created with identical parameters will be equal.
141 */
142 public boolean equals(java.lang.Object obj) {
143 if (obj == null) return false;
144 if ((obj.getClass() != this.getClass()) || (obj.hashCode() != this.hashCode())) {
145 return false;
146 } else {
147 ClassDef casted = (ClassDef) obj;
148 if (! (getMav().equals(casted.getMav()))) return false;
149 if (! (getName().equals(casted.getName()))) return false;
150 if (this.getTypeParameters().length != casted.getTypeParameters().length) return false;
151 for (int i = 0; i < getTypeParameters().length; i++) if (! getTypeParameters()[i].equals(casted.getTypeParameters()[i])) return false;
152 if (! (getSuperclass().equals(casted.getSuperclass()))) return false;
153 if (this.getInterfaces().length != casted.getInterfaces().length) return false;
154 for (int i = 0; i < getInterfaces().length; i++) if (! getInterfaces()[i].equals(casted.getInterfaces()[i])) return false;
155 if (! (getBody().equals(casted.getBody()))) return false;
156 return true;
157 }
158 }
159
160 /**
161 * Implementation of hashCode that is consistent with
162 * equals. The value of the hashCode is formed by
163 * XORing the hashcode of the class object with
164 * the hashcodes of all the fields of the object.
165 */
166 protected int generateHashCode() {
167 int code = getClass().hashCode();
168 code ^= 0;
169 code ^= getMav().hashCode();
170 code ^= getName().hashCode();
171 for (int i = 0; i < getTypeParameters().length; i++) code ^= getTypeParameters()[i].hashCode();
172 code ^= getSuperclass().hashCode();
173 for (int i = 0; i < getInterfaces().length; i++) code ^= getInterfaces()[i].hashCode();
174 code ^= getBody().hashCode();
175 return code;
176 }
177 }