001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: package de.uka.ilkd.key.java.expression.literal;
012:
013: import de.uka.ilkd.key.java.NameAbstractionTable;
014: import de.uka.ilkd.key.java.PrettyPrinter;
015: import de.uka.ilkd.key.java.Services;
016: import de.uka.ilkd.key.java.SourceElement;
017: import de.uka.ilkd.key.java.abstraction.KeYJavaType;
018: import de.uka.ilkd.key.java.abstraction.PrimitiveType;
019: import de.uka.ilkd.key.java.expression.Literal;
020: import de.uka.ilkd.key.java.visitor.Visitor;
021: import de.uka.ilkd.key.util.ExtList;
022:
023: /**
024: * Int literal.
025: * @author <TT>AutoDoc</TT>
026: */
027:
028: public class IntLiteral extends Literal {
029:
030: /**
031: * Textual representation of the value.
032: */
033: protected String value;
034:
035: /**
036: * Int literal.
037: */
038: public IntLiteral() {
039: this .value = "0".intern();
040: }
041:
042: /**
043: * Int literal.
044: * @param value an int value.
045: */
046: public IntLiteral(int value) {
047: this .value = ("" + value).intern();
048: }
049:
050: /**
051: * Int literal.
052: * @param value a string.
053: */
054: public IntLiteral(String value) {
055: this .value = value.intern();
056: }
057:
058: /**
059: * Constructor for the transformation of COMPOST ASTs to KeY.
060: * @param children the children of this AST element as KeY classes.
061: * May contain: Comments
062: */
063: public IntLiteral(ExtList children) {
064: super (children);
065: this .value = (String) children.get(String.class);
066: }
067:
068: /**
069: * Get value.
070: * @return the string.
071: */
072: public String getValue() {
073: return value;
074: }
075:
076: /** tests if equals
077: */
078: public boolean equalsModRenaming(SourceElement o,
079: NameAbstractionTable nat) {
080: if (!(o instanceof IntLiteral)) {
081: return false;
082: }
083: return ((IntLiteral) o).getValue().equals(getValue());
084: }
085:
086: public int hashCode() {
087: int result = 17;
088: result = 37 * result + getValue().hashCode();
089: return result;
090: }
091:
092: public boolean equals(Object o) {
093: return super .equals(o);
094: }
095:
096: /** calls the corresponding method of a visitor in order to
097: * perform some action/transformation on this element
098: * @param v the Visitor
099: */
100: public void visit(Visitor v) {
101: v.performActionOnIntLiteral(this );
102: }
103:
104: public void prettyPrint(PrettyPrinter p) throws java.io.IOException {
105: p.printIntLiteral(this );
106: }
107:
108: public KeYJavaType getKeYJavaType(Services javaServ) {
109: return javaServ.getJavaInfo().getKeYJavaType(
110: PrimitiveType.JAVA_INT);
111: }
112:
113: }
|