summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/ptree/TryStatement.java
blob: b1b3d252c59bcc96c9ceae14b0d783b311e4de45 (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
122
123
124
125
126
127
128
129
/*
 * TryStatement.java 1.0
 *
 * Jun 20, 1997 mich
 * Sep 29, 1997 mich
 *
 * @see io.devnulllabs.openjava.ptree.ParseTree
 * @version 1.0 last updated:  Sep 29, 1997
 * @author  Michiaki Tatsubori
 */
package io.devnulllabs.openjava.ptree;

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

/**
 * The <code>TryStatement</code> class represents
 * a try 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.StatementList
 * @see io.devnulllabs.openjava.ptree.CatchList
 */
public class TryStatement extends NonLeaf implements Statement, ParseTree {

    /**
     * Allocates a new TryStatement object.
     *
     * @param  the statement list of the body of this try statement.
     * @param  the catch block list of this try statement.
     * @param  the statement list of the finally block.
     */
    public TryStatement(
        StatementList stmts,
        CatchList catchlist,
        StatementList finallee) {
        super();
        if (stmts == null)
            stmts = new StatementList();
        if (catchlist == null)
            catchlist = new CatchList();
        if (finallee == null)
            finallee = new StatementList();
        set(stmts, catchlist, finallee);
    }

    /**
     * Allocates a new TryStatement object.
     *
     * @param  the statement list of the body of this try statement.
     * @param  the catch block list of this try statement.
     */
    public TryStatement(StatementList stmts, CatchList catchlist) {
        this(stmts, catchlist, new StatementList());
    }

    /**
     * Allocates a new TryStatement object.
     *
     * @param  the statement list of the body of this try statement.
     * @param  the statement list of the finally block.
     */
    public TryStatement(StatementList stmts, StatementList finallee) {
        this(stmts, new CatchList(), finallee);
    }

    TryStatement() {
    }

    /**
     * Gets the body of this try statement.
     *
     * @return  the statement list of the body.
     */
    public StatementList getBody() {
        return (StatementList) elementAt(0);
    }

    /**
     * Sets the body of this try statement.
     *
     * @param  stmts  the statement list of the body to set.
     */
    public void setBody(StatementList stmts) {
        setElementAt(stmts, 0);
    }

    /**
     * Gets the catch block list.
     *
     * @return  the catch block list.
     */
    public CatchList getCatchList() {
        return (CatchList) elementAt(1);
    }

    /**
     * Sets the catch block list.
     *
     * @param  catchlist  the catch block list.
     */
    public void setCatchList(CatchList catchlist) {
        setElementAt(catchlist, 1);
    }

    /**
     * Gets the finally body.
     *
     * @return  the statement list of finally body.
     */
    public StatementList getFinallyBody() {
        return (StatementList) elementAt(2);
    }

    /**
     * Sets the finally body.
     *
     * @param  finallee  the statement list of finally body.
     */
    public void setFinallyBody(StatementList finallee) {
        setElementAt(finallee, 2);
    }

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

}