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: * Char literal.
025: * @author <TT>AutoDoc</TT>
026: */
027:
028: public class CharLiteral extends Literal {
029:
030: protected final String value;
031: private char charVal;
032:
033: /**
034: * Char literal.
035: * @param value a char value.
036: */
037:
038: public CharLiteral(char value) {
039: this .value = "'" + value + "'";
040: this .charVal = value;
041: }
042:
043: /**
044: * Char literal.
045: * @param children an ExtList with all children(comments)
046: * May contain: Comments
047: * @param value a string.
048: */
049:
050: public CharLiteral(ExtList children, String value) {
051: super (children);
052: this .value = value;
053: this .charVal = value.charAt(1);
054: }
055:
056: /**
057: * Char literal.
058: * @param value a string.
059: */
060:
061: public CharLiteral(String value) {
062: this .value = value;
063: this .charVal = value.charAt(1);
064: }
065:
066: /** tests if equals
067: */
068: public boolean equalsModRenaming(SourceElement o,
069: NameAbstractionTable nat) {
070: if (!(o instanceof CharLiteral)) {
071: return false;
072: }
073: return ((CharLiteral) o).getValue().equals(getValue());
074: }
075:
076: public int hashCode() {
077: int result = 17;
078: result = 37 * result + getValue().hashCode();
079: return result;
080: }
081:
082: public boolean equals(Object o) {
083: return super .equals(o);
084: }
085:
086: /**
087: * Get value.
088: * @return the string.
089: */
090:
091: public String getValue() {
092: return value;
093: }
094:
095: public char getCharValue() {
096: return charVal;
097: }
098:
099: /** calls the corresponding method of a visitor in order to
100: * perform some action/transformation on this element
101: * @param v the Visitor
102: */
103: public void visit(Visitor v) {
104: v.performActionOnCharLiteral(this );
105: }
106:
107: public void prettyPrint(PrettyPrinter p) throws java.io.IOException {
108: p.printCharLiteral(this );
109: }
110:
111: public KeYJavaType getKeYJavaType(Services javaServ) {
112: return javaServ.getJavaInfo().getKeYJavaType(
113: PrimitiveType.JAVA_CHAR);
114: }
115:
116: }
|