001 package edu.rice.cs.javalanglevels.tree;
002
003 import edu.rice.cs.javalanglevels.SourceInfo;
004
005 /**
006 * Class SourceFile, 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 SourceFile extends JExpression {
011 private final PackageStatement[] _packageStatements;
012 private final ImportStatement[] _importStatements;
013 private final TypeDefBase[] _types;
014
015 /**
016 * Constructs a SourceFile.
017 * @throws java.lang.IllegalArgumentException If any parameter to the constructor is null.
018 */
019 public SourceFile(SourceInfo in_sourceInfo, PackageStatement[] in_packageStatements, ImportStatement[] in_importStatements, TypeDefBase[] in_types) {
020 super(in_sourceInfo);
021
022 if (in_packageStatements == null) {
023 throw new java.lang.IllegalArgumentException("Parameter 'packageStatements' to the SourceFile constructor was null. This class may not have null field values.");
024 }
025 _packageStatements = in_packageStatements;
026
027 if (in_importStatements == null) {
028 throw new java.lang.IllegalArgumentException("Parameter 'importStatements' to the SourceFile constructor was null. This class may not have null field values.");
029 }
030 _importStatements = in_importStatements;
031
032 if (in_types == null) {
033 throw new java.lang.IllegalArgumentException("Parameter 'types' to the SourceFile constructor was null. This class may not have null field values.");
034 }
035 _types = in_types;
036 }
037
038 final public PackageStatement[] getPackageStatements() { return _packageStatements; }
039 final public ImportStatement[] getImportStatements() { return _importStatements; }
040 final public TypeDefBase[] getTypes() { return _types; }
041
042 public <RetType> RetType visit(JExpressionIFVisitor<RetType> visitor) { return visitor.forSourceFile(this); }
043 public void visit(JExpressionIFVisitor_void visitor) { visitor.forSourceFile(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("SourceFile" + ":");
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("packageStatements = ");
077 writer.print("{");
078 writer.indent();
079 for (int i = 0; i < getPackageStatements().length; i++) {
080 PackageStatement temp_packageStatements = getPackageStatements()[i];
081 writer.startLine("#" + i + ": ");
082 if (temp_packageStatements == null) {
083 writer.print("null");
084 } else {
085 temp_packageStatements.outputHelp(writer);
086 }
087 }
088 writer.unindent();
089 if (getPackageStatements().length > 0) {
090 writer.startLine("");
091 }
092 writer.print("}");
093
094 writer.startLine("");
095 writer.print("importStatements = ");
096 writer.print("{");
097 writer.indent();
098 for (int i = 0; i < getImportStatements().length; i++) {
099 ImportStatement temp_importStatements = getImportStatements()[i];
100 writer.startLine("#" + i + ": ");
101 if (temp_importStatements == null) {
102 writer.print("null");
103 } else {
104 temp_importStatements.outputHelp(writer);
105 }
106 }
107 writer.unindent();
108 if (getImportStatements().length > 0) {
109 writer.startLine("");
110 }
111 writer.print("}");
112
113 writer.startLine("");
114 writer.print("types = ");
115 writer.print("{");
116 writer.indent();
117 for (int i = 0; i < getTypes().length; i++) {
118 TypeDefBase temp_types = getTypes()[i];
119 writer.startLine("#" + i + ": ");
120 if (temp_types == null) {
121 writer.print("null");
122 } else {
123 temp_types.outputHelp(writer);
124 }
125 }
126 writer.unindent();
127 if (getTypes().length > 0) {
128 writer.startLine("");
129 }
130 writer.print("}");
131 writer.unindent();
132 }
133
134 /**
135 * Implementation of equals that is based on the values
136 * of the fields of the object. Thus, two objects
137 * created with identical parameters will be equal.
138 */
139 public boolean equals(java.lang.Object obj) {
140 if (obj == null) return false;
141 if ((obj.getClass() != this.getClass()) || (obj.hashCode() != this.hashCode())) {
142 return false;
143 } else {
144 SourceFile casted = (SourceFile) obj;
145 if (this.getPackageStatements().length != casted.getPackageStatements().length) return false;
146 for (int i = 0; i < getPackageStatements().length; i++) if (! getPackageStatements()[i].equals(casted.getPackageStatements()[i])) return false;
147 if (this.getImportStatements().length != casted.getImportStatements().length) return false;
148 for (int i = 0; i < getImportStatements().length; i++) if (! getImportStatements()[i].equals(casted.getImportStatements()[i])) return false;
149 if (this.getTypes().length != casted.getTypes().length) return false;
150 for (int i = 0; i < getTypes().length; i++) if (! getTypes()[i].equals(casted.getTypes()[i])) return false;
151 return true;
152 }
153 }
154
155 /**
156 * Implementation of hashCode that is consistent with
157 * equals. The value of the hashCode is formed by
158 * XORing the hashcode of the class object with
159 * the hashcodes of all the fields of the object.
160 */
161 protected int generateHashCode() {
162 int code = getClass().hashCode();
163 code ^= 0;
164 for (int i = 0; i < getPackageStatements().length; i++) code ^= getPackageStatements()[i].hashCode();
165 for (int i = 0; i < getImportStatements().length; i++) code ^= getImportStatements()[i].hashCode();
166 for (int i = 0; i < getTypes().length; i++) code ^= getTypes()[i].hashCode();
167 return code;
168 }
169 }