1 /* 2 * Copyright (C) 2007-2010 Jlio Vilmar Gesser. 3 * Copyright (C) 2011, 2013-2016 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.Range; 25 import com.github.javaparser.ast.expr.Expression; 26 import com.github.javaparser.ast.visitor.GenericVisitor; 27 import com.github.javaparser.ast.visitor.VoidVisitor; 28 29 import java.util.List; 30 31 import static com.github.javaparser.utils.Utils.*; 32 33 /** 34 * @author Julio Vilmar Gesser 35 */ 36 public final class SwitchStmt extends Statement { 37 38 private Expression selector; 39 40 private List<SwitchEntryStmt> entries; 41 42 public SwitchStmt() { 43 } 44 45 public SwitchStmt(final Expression selector, 46 final List<SwitchEntryStmt> entries) { 47 setSelector(selector); 48 setEntries(entries); 49 } 50 51 public SwitchStmt(Range range, final Expression selector, 52 final List<SwitchEntryStmt> entries) { 53 super(range); 54 setSelector(selector); 55 setEntries(entries); 56 } 57 58 @Override 59 public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { 60 return v.visit(this, arg); 61 } 62 63 @Override 64 public <A> void accept(final VoidVisitor<A> v, final A arg) { 65 v.visit(this, arg); 66 } 67 68 public List<SwitchEntryStmt> getEntries() { 69 entries = ensureNotNull(entries); 70 return entries; 71 } 72 73 public Expression getSelector() { 74 return selector; 75 } 76 77 public SwitchStmt setEntries(final List<SwitchEntryStmt> entries) { 78 this.entries = entries; 79 setAsParentNodeOf(this.entries); 80 return this; 81 } 82 83 public SwitchStmt setSelector(final Expression selector) { 84 this.selector = selector; 85 setAsParentNodeOf(this.selector); 86 return this; 87 } 88 } 89