|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DoStatement.java | 30% | 56.5% | 70% | 53.5% |
|
||||||||||||||
| 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 do statement nodes of the syntax tree | |
| 37 | * | |
| 38 | * @author Stephane Hillion | |
| 39 | * @version 1.0 - 1999/05/16 | |
| 40 | */ | |
| 41 | ||
| 42 | public class DoStatement extends Statement implements ContinueTarget { | |
| 43 | /** | |
| 44 | * The condition to evaluate at each loop | |
| 45 | */ | |
| 46 | private Expression condition; | |
| 47 | ||
| 48 | /** | |
| 49 | * The body of this statement | |
| 50 | */ | |
| 51 | private Node body; | |
| 52 | ||
| 53 | /** | |
| 54 | * The labels | |
| 55 | */ | |
| 56 | private List<String> labels; | |
| 57 | ||
| 58 | /** | |
| 59 | * Creates a new do statement | |
| 60 | * @param cond the condition to evaluate at each loop | |
| 61 | * @param body the body | |
| 62 | * @exception IllegalArgumentException if cond is null or body is null | |
| 63 | */ | |
| 64 | 1 | public DoStatement(Expression cond, Node body) { |
| 65 | 1 | this(cond, body, SourceInfo.NONE); |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Creates a new do statement | |
| 70 | * @param cond the condition to evaluate at each loop | |
| 71 | * @param body the body | |
| 72 | * @exception IllegalArgumentException if cond is null or body is null | |
| 73 | */ | |
| 74 | 5 | public DoStatement(Expression cond, Node body, |
| 75 | SourceInfo si) { | |
| 76 | 5 | super(si); |
| 77 | ||
| 78 | 0 | if (cond == null) throw new IllegalArgumentException("cond == null"); |
| 79 | 0 | if (body == null) throw new IllegalArgumentException("body == null"); |
| 80 | ||
| 81 | 5 | condition = cond; |
| 82 | 5 | this.body = body; |
| 83 | 5 | labels = new LinkedList<String>(); |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Gets the condition to evaluate at each loop | |
| 88 | */ | |
| 89 | 29 | public Expression getCondition() { |
| 90 | 29 | return condition; |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * Sets the condition to evaluate | |
| 95 | * @exception IllegalArgumentException if e is null | |
| 96 | */ | |
| 97 | 3 | public void setCondition(Expression e) { |
| 98 | 0 | if (e == null) throw new IllegalArgumentException("e == null"); |
| 99 | 3 | condition = e; |
| 100 | } | |
| 101 | ||
| 102 | /** | |
| 103 | * Returns the body of this statement | |
| 104 | */ | |
| 105 | 26 | public Node getBody() { |
| 106 | 26 | return body; |
| 107 | } | |
| 108 | ||
| 109 | /** | |
| 110 | * Sets the body of this statement | |
| 111 | * @exception IllegalArgumentException if node is null | |
| 112 | */ | |
| 113 | 0 | public void setBody(Node node) { |
| 114 | 0 | if (node == null) throw new IllegalArgumentException("node == null"); |
| 115 | 0 | body = node; |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * Adds a label to this statement | |
| 120 | * @param label the label to add | |
| 121 | * @exception IllegalArgumentException if label is null | |
| 122 | */ | |
| 123 | 0 | public void addLabel(String label) { |
| 124 | 0 | if (label == null) throw new IllegalArgumentException("label == null"); |
| 125 | 0 | labels.add(label); |
| 126 | } | |
| 127 | ||
| 128 | /** | |
| 129 | * Test whether this statement has the given label | |
| 130 | * @return true if this statement has the given label | |
| 131 | */ | |
| 132 | 0 | public boolean hasLabel(String label) { |
| 133 | 0 | return labels.contains(label); |
| 134 | } | |
| 135 | ||
| 136 | /** | |
| 137 | * Allows a visitor to traverse the tree | |
| 138 | * @param visitor the visitor to accept | |
| 139 | */ | |
| 140 | 6 | public <T> T acceptVisitor(Visitor<T> visitor) { |
| 141 | 6 | return visitor.visit(this); |
| 142 | } | |
| 143 | /** | |
| 144 | * Implementation of toString for use in unit testing | |
| 145 | */ | |
| 146 | 2 | public String toString() { |
| 147 | 2 | return "("+getClass().getName()+": "+getCondition()+" "+getBody()+")"; |
| 148 | } | |
| 149 | } |
|
||||||||||