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: * Boolean literal.
025: * @author <TT>AutoDoc</TT>
026: */
027: public class BooleanLiteral extends Literal {
028:
029: public final static BooleanLiteral TRUE = new BooleanLiteral(true);
030: public final static BooleanLiteral FALSE = new BooleanLiteral(false);
031:
032: protected final boolean value;
033:
034: /**
035: * get boolean literal for the given <code>value</code>. This supports
036: * use of single literals, but we do not force it.
037: * @param val a boolean specifying the literal to be returned
038: * @return the BooleanLiteral representing <tt>val</tt>
039: */
040: public static BooleanLiteral getBooleanLiteral(boolean val) {
041: return val ? TRUE : FALSE;
042: }
043:
044: /**
045: * Boolean literal.
046: * @param value a boolean value.
047: */
048:
049: private BooleanLiteral(boolean value) {
050: this .value = value;
051: }
052:
053: /**
054: * Boolean literal.
055: * @param children list with all children
056: * May contain: Comments
057: * @param value a boolean value.
058: */
059: public BooleanLiteral(ExtList children, boolean value) {
060: super (children);
061: this .value = value;
062: }
063:
064: /**
065: * Get value.
066: * @return the string.
067: */
068:
069: public boolean getValue() {
070: return value;
071: }
072:
073: /**
074: * Get value.
075: * @return the string.
076: */
077:
078: public String getName() {
079: return (value ? "true" : "false");
080: }
081:
082: /** tests if equals
083: */
084: public boolean equalsModRenaming(SourceElement o,
085: NameAbstractionTable nat) {
086: if (!(o instanceof BooleanLiteral)) {
087: return false;
088: }
089: return ((BooleanLiteral) o).getValue() == getValue();
090: }
091:
092: public int hashCode() {
093: int result = 17;
094: result = 37 * result + (getValue() ? 0 : 1);
095: return result;
096: }
097:
098: public boolean equals(Object o) {
099: return super .equals(o);
100: }
101:
102: /** calls the corresponding method of a visitor in order to
103: * perform some action/transformation on this element
104: * @param v the Visitor
105: */
106: public void visit(Visitor v) {
107: v.performActionOnBooleanLiteral(this );
108: }
109:
110: public void prettyPrint(PrettyPrinter p) throws java.io.IOException {
111: p.printBooleanLiteral(this );
112: }
113:
114: public KeYJavaType getKeYJavaType(Services javaServ) {
115: return javaServ.getJavaInfo().getKeYJavaType(
116: PrimitiveType.JAVA_BOOLEAN);
117: }
118:
119: }
|