1 /* 2 * Copyright (C) 2007-2010 Jlio Vilmar Gesser. 3 * Copyright (C) 2011, 2013-2015 The JavaParser Team. 4 * 5 * This file is part of JavaParser. 6 * 7 * JavaParser can be used either under the terms of 8 * a) the GNU Lesser General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * b) the terms of the Apache License 12 * 13 * You should have received a copy of both licenses in LICENCE.LGPL and 14 * LICENCE.APACHE. Please refer to those files for details. 15 * 16 * JavaParser is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License for more details. 20 */ 21 22 package com.github.javaparser.ast.stmt; 23 24 import com.github.javaparser.ast.Node; 25 import com.github.javaparser.ast.body.MultiTypeParameter; 26 import com.github.javaparser.ast.body.VariableDeclaratorId; 27 import com.github.javaparser.ast.expr.AnnotationExpr; 28 import com.github.javaparser.ast.type.Type; 29 import com.github.javaparser.ast.visitor.GenericVisitor; 30 import com.github.javaparser.ast.visitor.VoidVisitor; 31 32 import java.util.List; 33 34 /** 35 * @author Julio Vilmar Gesser 36 */ 37 public final class CatchClause extends Node { 38 39 private MultiTypeParameter except; 40 41 private BlockStmt catchBlock; 42 43 public CatchClause() { 44 } 45 46 public CatchClause(final MultiTypeParameter except, final BlockStmt catchBlock) { 47 setExcept(except); 48 setCatchBlock(catchBlock); 49 } 50 51 public CatchClause(int exceptModifier, List<AnnotationExpr> exceptAnnotations, List<Type> exceptTypes, VariableDeclaratorId exceptId, BlockStmt catchBlock) { 52 this(new MultiTypeParameter(exceptModifier, exceptAnnotations, exceptTypes, exceptId), catchBlock); 53 } 54 55 public CatchClause(final int beginLine, final int beginColumn, final int endLine, final int endColumn, 56 final int exceptModifier, final List<AnnotationExpr> exceptAnnotations, final List<Type> exceptTypes, 57 final VariableDeclaratorId exceptId, final BlockStmt catchBlock) { 58 super(beginLine, beginColumn, endLine, endColumn); 59 setExcept(new MultiTypeParameter(beginLine, beginColumn, endLine, endColumn, exceptModifier, exceptAnnotations, exceptTypes, exceptId)); 60 setCatchBlock(catchBlock); 61 } 62 63 @Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { 64 return v.visit(this, arg); 65 } 66 67 @Override public <A> void accept(final VoidVisitor<A> v, final A arg) { 68 v.visit(this, arg); 69 } 70 71 public BlockStmt getCatchBlock() { 72 return catchBlock; 73 } 74 75 public MultiTypeParameter getExcept() { 76 return except; 77 } 78 79 public void setCatchBlock(final BlockStmt catchBlock) { 80 this.catchBlock = catchBlock; 81 setAsParentNodeOf(this.catchBlock); 82 } 83 84 public void setExcept(final MultiTypeParameter except) { 85 this.except = except; 86 setAsParentNodeOf(this.except); 87 } 88 } 89