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.expression.Literal;
019: import de.uka.ilkd.key.java.reference.ReferencePrefix;
020: import de.uka.ilkd.key.java.visitor.Visitor;
021: import de.uka.ilkd.key.util.ExtList;
022:
023: /**
024: * String literal.
025: * @author <TT>AutoDoc</TT>
026: */
027:
028: public class StringLiteral extends Literal implements ReferencePrefix {
029:
030: /**
031: * The value.
032: */
033:
034: protected final String value;
035:
036: /**
037: * String literal.
038: * @param value a string.
039: */
040:
041: public StringLiteral(String value) {
042: this .value = value;
043: }
044:
045: /**
046: * String literal.
047: * @param children an ExtList with children(here:comments)
048: * @param value a string.
049: */
050:
051: public StringLiteral(ExtList children, String value) {
052: super (children);
053: this .value = value;
054: }
055:
056: /** tests if equals
057: */
058: public boolean equalsModRenaming(SourceElement o,
059: NameAbstractionTable nat) {
060: if (!(o instanceof StringLiteral)) {
061: return false;
062: }
063: return ((StringLiteral) o).getValue().equals(getValue());
064: }
065:
066: public int hashCode() {
067: int result = 17;
068: result = 37 * result + getValue().hashCode();
069: return result;
070: }
071:
072: public boolean equals(Object o) {
073: return super .equals(o);
074: }
075:
076: /**
077: * Get value.
078: * @return the string.
079: */
080:
081: public String getValue() {
082: return value;
083: }
084:
085: /** calls the corresponding method of a visitor in order to
086: * perform some action/transformation on this element
087: * @param v the Visitor
088: */
089: public void visit(Visitor v) {
090: v.performActionOnStringLiteral(this );
091: }
092:
093: public void prettyPrint(PrettyPrinter p) throws java.io.IOException {
094: p.printStringLiteral(this );
095: }
096:
097: /**
098: * We do not have a prefix, so fake it!
099: * This way we implement ReferencePrefix
100: * @author VK
101: */
102: public ReferencePrefix getReferencePrefix() {
103: return null;
104: }
105:
106: public ReferencePrefix setReferencePrefix(ReferencePrefix r) {
107: return this ;
108: }
109:
110: public KeYJavaType getKeYJavaType(Services javaServ) {
111: return javaServ.getJavaInfo()
112: .getKeYJavaType("java.lang.String");
113: }
114:
115: }
|