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