View Javadoc
Minimize
Table

1   /*
2    * Copyright 2003-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.groovy.ast.stmt;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.codehaus.groovy.ast.GroovyCodeVisitor;
22  
23  /**
24   * Represents a try { ... } catch () finally {} statement in Groovy
25   * 
26   * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
27   * @version $Revision: 15807 $
28   */
29  public class TryCatchStatement extends Statement {
30  
31      private Statement tryStatement;
32      private List<CatchStatement> catchStatements = new ArrayList<CatchStatement>();
33      private Statement finallyStatement;
34      
35  
36      public TryCatchStatement(Statement tryStatement, Statement finallyStatement) {
37          this.tryStatement = tryStatement;
38          this.finallyStatement = finallyStatement;
39      }
40      
41      public void visit(GroovyCodeVisitor visitor) {
42          visitor.visitTryCatchFinally(this);
43      }
44      
45      public List<CatchStatement> getCatchStatements() {
46          return catchStatements;
47      }
48  
49      public Statement getFinallyStatement() {
50          return finallyStatement;
51      }
52  
53      public Statement getTryStatement() {
54          return tryStatement;
55      }
56  
57      public void addCatch(CatchStatement catchStatement) {
58          catchStatements.add(catchStatement);
59      }
60  
61      /**
62       * @return the catch statement of the given index or null
63       */
64      public CatchStatement getCatchStatement(int idx) {
65          if (idx >= 0 && idx < catchStatements.size()) {
66              return catchStatements.get(idx);
67          }
68          return null;
69      }
70  
71      public void setTryStatement(Statement tryStatement) {
72          this.tryStatement = tryStatement;
73      }
74  
75      public void setCatchStatement(int idx, CatchStatement catchStatement) {
76          catchStatements.set(idx, catchStatement);
77      }
78  
79      public void setFinallyStatement(Statement finallyStatement) {
80          this.finallyStatement = finallyStatement;
81      }
82  }