|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| IfThenElseStatement.java | 25% | 63.6% | 83.3% | 61.9% |
|
||||||||||||||
| 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 koala.dynamicjava.tree.visitor.*; | |
| 32 | ||
| 33 | /** | |
| 34 | * This class represents the if-then-else statement nodes of the syntax tree | |
| 35 | * | |
| 36 | * @author Stephane Hillion | |
| 37 | * @version 1.0 - 1999/05/16 | |
| 38 | */ | |
| 39 | ||
| 40 | public class IfThenElseStatement extends IfThenStatement { | |
| 41 | /** | |
| 42 | * The 'else' statement | |
| 43 | */ | |
| 44 | private Node elseStatement; | |
| 45 | ||
| 46 | /** | |
| 47 | * Creates a new while statement | |
| 48 | * @param cond the condition | |
| 49 | * @param tstmt the then statement | |
| 50 | * @param estmt the else statement | |
| 51 | * @exception IllegalArgumentException if cond is null or tstmt is null or | |
| 52 | * estmt is null | |
| 53 | */ | |
| 54 | 3 | public IfThenElseStatement(Expression cond, Node tstmt, Node estmt) { |
| 55 | 3 | this(cond, tstmt, estmt, SourceInfo.NONE); |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Creates a new while statement | |
| 60 | * @param cond the condition | |
| 61 | * @param tstmt the then statement | |
| 62 | * @param estmt the else statement | |
| 63 | * @exception IllegalArgumentException if cond is null or tstmt is null or | |
| 64 | * estmt is null | |
| 65 | */ | |
| 66 | 12 | public IfThenElseStatement(Expression cond, Node tstmt, Node estmt, |
| 67 | SourceInfo si) { | |
| 68 | 12 | super(cond, tstmt, si); |
| 69 | ||
| 70 | 0 | if (estmt == null) throw new IllegalArgumentException("estmt == null"); |
| 71 | ||
| 72 | 12 | elseStatement = estmt; |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Returns the else statement of this statement | |
| 77 | */ | |
| 78 | 15 | public Node getElseStatement() { |
| 79 | 15 | return elseStatement; |
| 80 | } | |
| 81 | ||
| 82 | /** | |
| 83 | * Sets the else statement of this statement | |
| 84 | * @exception IllegalArgumentException if node is null | |
| 85 | */ | |
| 86 | 0 | public void setElseStatement(Node node) { |
| 87 | 0 | if (node == null) throw new IllegalArgumentException("node == null"); |
| 88 | 0 | elseStatement = node; |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * Allows a visitor to traverse the tree | |
| 93 | * @param visitor the visitor to accept | |
| 94 | */ | |
| 95 | 12 | public <T> T acceptVisitor(Visitor<T> visitor) { |
| 96 | 12 | return visitor.visit(this); |
| 97 | } | |
| 98 | /** | |
| 99 | * Implementation of toString for use in unit testing | |
| 100 | */ | |
| 101 | 6 | public String toString() { |
| 102 | 6 | return "("+getClass().getName()+": "+getCondition()+" "+getThenStatement()+" "+getElseStatement()+")"; |
| 103 | } | |
| 104 | } |
|
||||||||||