|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| SwitchStatement.java | 25% | 47.1% | 57.1% | 43.8% |
|
||||||||||||||
| 1 | /* | |
| 2 | * DynamicJava - Copyright (C) 1999-2001 | |
| 3 | * | |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
| 5 | * copy of this software and associated documentation files | |
| 6 | * (the "Software"), to deal in the Software without restriction, including | |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, | |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to permit | |
| 9 | * persons to whom the Software is furnished to do so, subject to the | |
| 10 | * following conditions: | |
| 11 | * The above copyright notice and this permission notice shall be included | |
| 12 | * in all copies or substantial portions of the Software. | |
| 13 | * | |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
| 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
| 17 | * IN NO EVENT SHALL DYADE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
| 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
| 20 | * DEALINGS IN THE SOFTWARE. | |
| 21 | * | |
| 22 | * Except as contained in this notice, the name of Dyade shall not be | |
| 23 | * used in advertising or otherwise to promote the sale, use or other | |
| 24 | * dealings in this Software without prior written authorization from | |
| 25 | * Dyade. | |
| 26 | * | |
| 27 | */ | |
| 28 | ||
| 29 | package koala.dynamicjava.tree; | |
| 30 | ||
| 31 | import java.util.*; | |
| 32 | ||
| 33 | import koala.dynamicjava.tree.visitor.*; | |
| 34 | ||
| 35 | /** | |
| 36 | * This class represents the switch statement nodes of the syntax tree | |
| 37 | * | |
| 38 | * @author Stephane Hillion | |
| 39 | * @version 1.0 - 1999/05/25 | |
| 40 | */ | |
| 41 | ||
| 42 | public class SwitchStatement extends Statement { | |
| 43 | /** | |
| 44 | * The selector | |
| 45 | */ | |
| 46 | private Expression selector; | |
| 47 | ||
| 48 | /** | |
| 49 | * The list of case bindings | |
| 50 | */ | |
| 51 | private List<SwitchBlock> bindings; | |
| 52 | ||
| 53 | /** | |
| 54 | * Creates a new switch statement | |
| 55 | * @param sel the selector | |
| 56 | * @param cases the case bindings (SwitchBlocks) | |
| 57 | * @exception IllegalArgumentException if sel is null or cases is null | |
| 58 | */ | |
| 59 | 2 | public SwitchStatement(Expression sel, List<SwitchBlock> cases, |
| 60 | SourceInfo si) { | |
| 61 | 2 | super(si); |
| 62 | ||
| 63 | 0 | if (sel == null) throw new IllegalArgumentException("sel == null"); |
| 64 | 0 | if (cases == null) throw new IllegalArgumentException("cases == null"); |
| 65 | ||
| 66 | 2 | selector = sel; |
| 67 | 2 | bindings = cases; |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * Gets the selector | |
| 72 | */ | |
| 73 | 2 | public Expression getSelector() { |
| 74 | 2 | return selector; |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * Sets the selector | |
| 79 | * @exception IllegalArgumentException if e is null | |
| 80 | */ | |
| 81 | 0 | public void setSelector(Expression e) { |
| 82 | 0 | if (e == null) throw new IllegalArgumentException("e == null"); |
| 83 | 0 | selector = e; |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Returns the 'case' bindings | |
| 88 | */ | |
| 89 | 2 | public List<SwitchBlock> getBindings() { |
| 90 | 2 | return bindings; |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * Sets the bindings | |
| 95 | * @exception IllegalArgumentException if e is null | |
| 96 | */ | |
| 97 | 0 | public void setBindings(List<SwitchBlock> l) { |
| 98 | 0 | if (l == null) throw new IllegalArgumentException("l == null"); |
| 99 | 0 | bindings = l; |
| 100 | } | |
| 101 | ||
| 102 | /** | |
| 103 | * Allows a visitor to traverse the tree | |
| 104 | * @param visitor the visitor to accept | |
| 105 | */ | |
| 106 | 0 | public <T> T acceptVisitor(Visitor<T> visitor) { |
| 107 | 0 | return visitor.visit(this); |
| 108 | } | |
| 109 | /** | |
| 110 | * Implementation of toString for use in unit testing | |
| 111 | */ | |
| 112 | 2 | public String toString() { |
| 113 | 2 | return "("+getClass().getName()+": "+getSelector()+" "+getBindings()+")"; |
| 114 | } | |
| 115 | } |
|
||||||||||