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.Expression;
014: import de.uka.ilkd.key.java.ExpressionContainer;
015: import de.uka.ilkd.key.java.ProgramElement;
016: import de.uka.ilkd.key.util.ExtList;
017:
018: /**
019: * Expression jump statement.
020: * @author <TT>AutoDoc</TT>
021: */
022:
023: public abstract class ExpressionJumpStatement extends JumpStatement
024: implements ExpressionContainer {
025:
026: /**
027: * Expression.
028: */
029:
030: protected final Expression expression;
031:
032: /**
033: * Expression jump statement.
034: * May contain: an Expression (as expression of the
035: * ExpressionJumpStatement),
036: * Comments
037: */
038: public ExpressionJumpStatement(ExtList children) {
039: super (children);
040: expression = (Expression) children.get(Expression.class);
041: }
042:
043: /**
044: * Expression jump statement.
045: */
046: public ExpressionJumpStatement() {
047: expression = null;
048: }
049:
050: /**
051: * Expression jump statement.
052: * @param expr an Expression used to jump
053: */
054: public ExpressionJumpStatement(Expression expr) {
055: expression = expr;
056: }
057:
058: /**
059: * Get the number of expressions in this container.
060: * @return the number of expressions.
061: */
062: public int getExpressionCount() {
063: return (expression != null) ? 1 : 0;
064: }
065:
066: /**
067: Return the expression at the specified index in this node's
068: "virtual" expression array.
069: @param index an index for an expression.
070: @return the expression with the given index.
071: @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out
072: of bounds.
073: */
074: public Expression getExpressionAt(int index) {
075: if (expression != null && index == 0) {
076: return expression;
077: }
078: throw new ArrayIndexOutOfBoundsException();
079: }
080:
081: /**
082: * Get expression.
083: * @return the expression.
084: */
085: public Expression getExpression() {
086: return expression;
087: }
088:
089: /**
090: * Returns the number of children of this node.
091: * @return an int giving the number of children of this node
092: */
093: public int getChildCount() {
094: return (expression != null) ? 1 : 0;
095: }
096:
097: /**
098: * Returns the child at the specified index in this node's "virtual"
099: * child array
100: * @param index an index into this node's "virtual" child array
101: * @return the program element at the given position
102: * @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out
103: * of bounds
104: */
105: public ProgramElement getChildAt(int index) {
106: if (expression != null) {
107: if (index == 0)
108: return expression;
109: }
110: throw new ArrayIndexOutOfBoundsException();
111: }
112: }
|