1 /* valatrystatement.vala
3 * Copyright (C) 2007-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
27 * Represents a try statement in the source code.
29 public class Vala
.TryStatement
: CodeNode
, Statement
{
31 * Specifies the body of the try statement.
33 public Block body
{ get; set; }
36 * Specifies the body of the optional finally clause.
38 public Block? finally_body
{ get; set; }
40 private Gee
.List
<CatchClause
> catch_clauses
= new ArrayList
<CatchClause
> ();
43 * Creates a new try statement.
45 * @param body body of the try statement
46 * @param finally_body body of the optional finally clause
47 * @param source_reference reference to source code
48 * @return newly created try statement
50 public TryStatement (Block body
, Block? finally_body
, SourceReference? source_reference
= null) {
52 this
.finally_body
= finally_body
;
53 this
.source_reference
= source_reference
;
57 * Appends the specified clause to the list of catch clauses.
59 * @param clause a catch clause
61 public void add_catch_clause (CatchClause clause
) {
62 catch_clauses
.add (clause
);
66 * Returns a copy of the list of catch clauses.
68 * @return list of catch clauses
70 public Gee
.List
<CatchClause
> get_catch_clauses () {
71 return new ReadOnlyList
<CatchClause
> (catch_clauses
);
74 public override void accept (CodeVisitor visitor
) {
75 visitor
.visit_try_statement (this
);
78 public override void accept_children (CodeVisitor visitor
) {
79 body
.accept (visitor
);
81 foreach (CatchClause clause
in catch_clauses
) {
82 clause
.accept (visitor
);
85 if (finally_body
!= null) {
86 finally_body
.accept (visitor
);
90 public override bool check (SemanticAnalyzer analyzer
) {
97 body
.check (analyzer
);
99 foreach (CatchClause clause
in catch_clauses
) {
100 clause
.check (analyzer
);
103 if (finally_body
!= null) {
104 finally_body
.check (analyzer
);