|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ConditionalExpression.java | 25% | 48% | 60% | 44.7% |
|
||||||||||||||
| 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 binary expression nodes of the syntax tree | |
| 35 | * | |
| 36 | * @author Stephane Hillion | |
| 37 | * @version 1.0 - 1999/04/25 | |
| 38 | */ | |
| 39 | ||
| 40 | public class ConditionalExpression extends Expression { | |
| 41 | /** | |
| 42 | * The condition expression | |
| 43 | */ | |
| 44 | private Expression conditionExpression; | |
| 45 | ||
| 46 | /** | |
| 47 | * The if true expression | |
| 48 | */ | |
| 49 | private Expression ifTrueExpression; | |
| 50 | ||
| 51 | /** | |
| 52 | * The if false expression | |
| 53 | */ | |
| 54 | private Expression ifFalseExpression; | |
| 55 | ||
| 56 | /** | |
| 57 | * Initializes the expression | |
| 58 | * @param cexp the condition expression | |
| 59 | * @param texp the if true expression | |
| 60 | * @param fexp the if false expression | |
| 61 | * @exception IllegalArgumentException if cexp is null or texp is null or | |
| 62 | * fexp is null | |
| 63 | */ | |
| 64 | 1 | public ConditionalExpression(Expression cexp, Expression texp, Expression fexp) { |
| 65 | 1 | this(cexp, texp, fexp, SourceInfo.NONE); |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Initializes the expression | |
| 70 | * @param cexp the condition expression | |
| 71 | * @param texp the if true expression | |
| 72 | * @param fexp the if false expression | |
| 73 | * @exception IllegalArgumentException if cexp is null or texp is null or | |
| 74 | * fexp is null | |
| 75 | */ | |
| 76 | 2 | public ConditionalExpression(Expression cexp, Expression texp, Expression fexp, |
| 77 | SourceInfo si) { | |
| 78 | 2 | super(si); |
| 79 | ||
| 80 | 0 | if (cexp == null) throw new IllegalArgumentException("cexp == null"); |
| 81 | 0 | if (texp == null) throw new IllegalArgumentException("texp == null"); |
| 82 | 0 | if (fexp == null) throw new IllegalArgumentException("fexp == null"); |
| 83 | ||
| 84 | 2 | conditionExpression = cexp; |
| 85 | 2 | ifTrueExpression = texp; |
| 86 | 2 | ifFalseExpression = fexp; |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Returns the condition expression | |
| 91 | */ | |
| 92 | 2 | public Expression getConditionExpression() { |
| 93 | 2 | return conditionExpression; |
| 94 | } | |
| 95 | ||
| 96 | /** | |
| 97 | * Sets the condition expression | |
| 98 | * @exception IllegalArgumentException if e is null | |
| 99 | */ | |
| 100 | 0 | public void setConditionExpression(Expression e) { |
| 101 | 0 | if (e == null) throw new IllegalArgumentException("e == null"); |
| 102 | 0 | conditionExpression = e; |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Returns the if true expression | |
| 107 | */ | |
| 108 | 2 | public Expression getIfTrueExpression() { |
| 109 | 2 | return ifTrueExpression; |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * Sets the if true expression | |
| 114 | * @exception IllegalArgumentException if e is null | |
| 115 | */ | |
| 116 | 0 | public void setIfTrueExpression(Expression e) { |
| 117 | 0 | if (e == null) throw new IllegalArgumentException("e == null"); |
| 118 | 0 | ifTrueExpression = e; |
| 119 | } | |
| 120 | ||
| 121 | /** | |
| 122 | * Returns the if false expression | |
| 123 | */ | |
| 124 | 2 | public Expression getIfFalseExpression() { |
| 125 | 2 | return ifFalseExpression; |
| 126 | } | |
| 127 | ||
| 128 | /** | |
| 129 | * Sets the if false expression | |
| 130 | * @exception IllegalArgumentException if e is null | |
| 131 | */ | |
| 132 | 0 | public void setIfFalseExpression(Expression e) { |
| 133 | 0 | if (e == null) throw new IllegalArgumentException("e == null"); |
| 134 | 0 | ifFalseExpression = e; |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 138 | * Allows a visitor to traverse the tree | |
| 139 | * @param visitor the visitor to accept | |
| 140 | */ | |
| 141 | 0 | public <T> T acceptVisitor(Visitor<T> visitor) { |
| 142 | 0 | return visitor.visit(this); |
| 143 | } | |
| 144 | /** | |
| 145 | * Implementation of toString for use in unit testing | |
| 146 | */ | |
| 147 | 2 | public String toString() { |
| 148 | 2 | return "("+getClass().getName()+": "+getConditionExpression()+" "+getIfTrueExpression()+" "+getIfFalseExpression()+")"; |
| 149 | } | |
| 150 | } |
|
||||||||||