|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ArrayInitializer.java | 40% | 65% | 100% | 65.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 array initializer nodes of the syntax tree | |
| 37 | * | |
| 38 | * @author Stephane Hillion | |
| 39 | * @version 1.0 - 1999/04/25 | |
| 40 | */ | |
| 41 | ||
| 42 | public class ArrayInitializer extends Expression { | |
| 43 | /** | |
| 44 | * The list of initialized cells | |
| 45 | */ | |
| 46 | private List<Expression> cells; | |
| 47 | ||
| 48 | /** | |
| 49 | * The element type | |
| 50 | */ | |
| 51 | private TypeName elementType; | |
| 52 | ||
| 53 | /** | |
| 54 | * Initializes the expression | |
| 55 | * @param cells the list of initialized cells | |
| 56 | * @exception IllegalArgumentException if cells is null | |
| 57 | */ | |
| 58 | 24 | public ArrayInitializer(List<? extends Expression> cells) { |
| 59 | 24 | this(cells, SourceInfo.NONE); |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * Initializes the expression | |
| 64 | * @param cells the list of initialized cells | |
| 65 | * @exception IllegalArgumentException if cells is null | |
| 66 | */ | |
| 67 | 40 | public ArrayInitializer(List<? extends Expression> cells, |
| 68 | SourceInfo si) { | |
| 69 | 40 | super(si); |
| 70 | ||
| 71 | 0 | if (cells == null) throw new IllegalArgumentException("cells == null"); |
| 72 | ||
| 73 | 40 | this.cells = new ArrayList<Expression>(cells); |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Returns the list of cell initialization expressions | |
| 78 | */ | |
| 79 | 110 | public List<Expression> getCells() { |
| 80 | 110 | return cells; |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Sets the list of cell initialization expressions | |
| 85 | * @exception IllegalArgumentException if l is null | |
| 86 | */ | |
| 87 | 12 | public void setCells(List<? extends Expression> l) { |
| 88 | 0 | if (l == null) throw new IllegalArgumentException("l == null"); |
| 89 | 12 | cells = new ArrayList<Expression>(l); |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * Returns the element type, or {@code null} if it's not set | |
| 94 | */ | |
| 95 | 18 | public TypeName getElementType() { |
| 96 | 18 | return elementType; |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * Sets the element type. Also recursively sets the element type of any | |
| 101 | * cells that are ArrayInitializers. | |
| 102 | * @exception IllegalArgumentException if t is null | |
| 103 | */ | |
| 104 | 34 | public void setElementType(TypeName t) { |
| 105 | 0 | if (t == null) throw new IllegalArgumentException("t == null"); |
| 106 | 34 | elementType = t; |
| 107 | 34 | if (t instanceof ArrayTypeName) { |
| 108 | 0 | ArrayTypeName at = (ArrayTypeName)t; |
| 109 | 0 | for (Expression init : cells) { |
| 110 | 0 | if (init instanceof ArrayInitializer) { |
| 111 | 0 | ((ArrayInitializer)init).setElementType(at.getElementType()); |
| 112 | } | |
| 113 | } | |
| 114 | } | |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Allows a visitor to traverse the tree | |
| 119 | * @param visitor the visitor to accept | |
| 120 | */ | |
| 121 | 46 | public <T> T acceptVisitor(Visitor<T> visitor) { |
| 122 | 46 | return visitor.visit(this); |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * Implementation of toString for use in unit testing | |
| 127 | */ | |
| 128 | 6 | public String toString() { |
| 129 | 6 | return "("+getClass().getName()+": "+getCells()+" "+getElementType()+")"; |
| 130 | } | |
| 131 | } |
|
||||||||||