summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/ptree/IfStatement.java
blob: ac20264de49cf1821a37bb95a661d28b872a6c54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * IfStatement.java 1.0
 *
 * Jun 20, 1997 mich
 * Sep 29, 1997 bv
 * Oct 11, 1997 mich
 *
 * @see io.devnulllabs.openjava.ptree.ParseTree
 * @version 1.0 last updated:  Oct 11, 1997
 * @author  Michiaki Tatsubori
 */
package io.devnulllabs.openjava.ptree;

import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;

/**
 * The <code>IfStatement</code> class represents a if statement node
 * of parse tree
 *
 * @see io.devnulllabs.openjava.ptree.ParseTree
 * @see io.devnulllabs.openjava.ptree.NonLeaf
 * @see io.devnulllabs.openjava.ptree.Statement
 * @see io.devnulllabs.openjava.ptree.Expression
 * @see io.devnulllabs.openjava.ptree.StatementList
 */
public class IfStatement extends NonLeaf implements Statement, ParseTree {

    /**
     * Constructs new IfStatement from prototype object
     *
     * @param  expr  the condition of this if statement.
     * @param  stmts  the statement that is executed when expr is ture
     * @param  elsestmts the statement that is executed when expr is false.
     *                   If there is no else part then statement list is
     *                   empty.
     */
    public IfStatement(
        Expression expr,
        StatementList stmts,
        StatementList elsestmts) {
        super();
        if (stmts == null)
            stmts = new StatementList();
        if (elsestmts == null)
            elsestmts = new StatementList();
        set(expr, stmts, elsestmts);
    }

    /**
     * Constructs new IfStatement from prototype object
     *
     * @param  expr  the condition of this if statement.
     * @param  stmts  the statement that is executed when expr is ture
     */
    public IfStatement(Expression expr, StatementList stmts) {
        this(expr, stmts, null);
    }

    IfStatement() {
        super();
    }

    /**
     * Gets the condition of this if statement.
     *
     * @return  the expression of the condition.
     */
    public Expression getExpression() {
        return (Expression) elementAt(0);
    }

    /**
     * Sets the condition of this if statement.
     *
     * @param  expr  the expression of the condition.
     */
    public void setExpression(Expression expr) {
        setElementAt(expr, 0);
    }

    /**
     * Gets the then part of this if statement.
     *
     * @return  the statement list of the then part.
     */
    public StatementList getStatements() {
        return (StatementList) elementAt(1);
    }

    /**
     * Sets the then part of this if statement.
     *
     * @param  thenstmts  the statement list of the then part.
     */
    public void setStatements(StatementList thenstmts) {
        setElementAt(thenstmts, 1);
    }

    /**
     * Gets the else part of this if statement.
     *
     * @return  the statement list of the else part.
     */
    public StatementList getElseStatements() {
        return (StatementList) elementAt(2);
    }

    /**
     * Sets the else part of this if statement.
     *
     * @param  elsestmts  the statement list of the else part.
     */
    public void setElseStatements(StatementList elsestmts) {
        setElementAt(elsestmts, 2);
    }

    public void accept(ParseTreeVisitor v) throws ParseTreeException {
        v.visit(this);
    }

}