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.statement;
012:
013: import de.uka.ilkd.key.java.ArrayOfStatement;
014: import de.uka.ilkd.key.java.PrettyPrinter;
015: import de.uka.ilkd.key.java.ProgramElement;
016: import de.uka.ilkd.key.java.Statement;
017: import de.uka.ilkd.key.java.visitor.Visitor;
018: import de.uka.ilkd.key.util.ExtList;
019:
020: /**
021: * Default.
022: *
023: */
024: public class Default extends BranchImp {
025:
026: /**
027: * Body.
028: */
029: protected final ArrayOfStatement body;
030:
031: /**
032: * Default.
033: */
034: public Default() {
035: this .body = null;
036: }
037:
038: /**
039: * Default.
040: * @param body a statement array.
041: */
042:
043: public Default(Statement[] body) {
044: this .body = new ArrayOfStatement(body);
045: }
046:
047: /**
048: * Constructor for the transformation of COMPOST ASTs to KeY.
049: * @param children the children of this AST element as KeY classes.
050: * May contain: Comments,
051: * several of Statement (as the statements for Default)
052: */
053: public Default(ExtList children) {
054: super (children);
055: this .body = new ArrayOfStatement((Statement[]) children
056: .collect(Statement.class));
057: }
058:
059: /**
060: * Returns the number of children of this node.
061: * @return an int giving the number of children of this node
062: */
063: public int getChildCount() {
064: int result = 0;
065: if (body != null)
066: result += body.size();
067: return result;
068: }
069:
070: /**
071: * Returns the child at the specified index in this node's "virtual"
072: * child array
073: * @param index an index into this node's "virtual" child array
074: * @return the program element at the given position
075: * @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out
076: * of bounds
077: */
078: public ProgramElement getChildAt(int index) {
079: int len;
080: if (body != null) {
081: len = body.size();
082: if (len > index) {
083: return body.getStatement(index);
084: }
085: index -= len;
086: }
087: throw new ArrayIndexOutOfBoundsException();
088: }
089:
090: /**
091: * Get the number of statements in this container.
092: * @return the number of statements.
093: */
094: public int getStatementCount() {
095: return (body != null) ? body.size() : 0;
096: }
097:
098: /*
099: Return the statement at the specified index in this node's
100: "virtual" statement array.
101: @param index an index for a statement.
102: @return the statement with the given index.
103: @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out
104: of bounds.
105: */
106: public Statement getStatementAt(int index) {
107: if (body != null) {
108: return body.getStatement(index);
109: }
110: throw new ArrayIndexOutOfBoundsException();
111: }
112:
113: /**
114: * The body may be empty (null), to define a fall-through.
115: * Attaching an {@link EmptyStatement} would create a single ";".
116: */
117: public ArrayOfStatement getBody() {
118: return body;
119: }
120:
121: /** calls the corresponding method of a visitor in order to
122: * perform some action/transformation on this element
123: * @param v the Visitor
124: */
125: public void visit(Visitor v) {
126: v.performActionOnDefault(this );
127: }
128:
129: public void prettyPrint(PrettyPrinter p) throws java.io.IOException {
130: p.printDefault(this);
131: }
132: }
|