|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ReferenceTypeName.java | 40% | 69.2% | 91.7% | 68.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 reference type nodes of the syntax tree | |
| 37 | * | |
| 38 | * @author Stephane Hillion | |
| 39 | * @version 1.0 - 1999/04/24 | |
| 40 | */ | |
| 41 | ||
| 42 | public class ReferenceTypeName extends TypeName { | |
| 43 | ||
| 44 | // TODO: Develop a better representation with more structure (resolving package/class ambiguities). | |
| 45 | ||
| 46 | /** | |
| 47 | * The representation of this type | |
| 48 | */ | |
| 49 | private String representation; | |
| 50 | ||
| 51 | /** | |
| 52 | * The representation of this type | |
| 53 | */ | |
| 54 | private List<? extends IdentifierToken> identifiers; | |
| 55 | ||
| 56 | ||
| 57 | /** | |
| 58 | * Initializes the type | |
| 59 | * @param ids the list of the tokens that compose the type name | |
| 60 | * @exception IllegalArgumentException if ids is null or empty | |
| 61 | */ | |
| 62 | 115 | public ReferenceTypeName(List<? extends IdentifierToken> ids) { |
| 63 | 115 | this(ids, SourceInfo.NONE); |
| 64 | } | |
| 65 | ||
| 66 | 115 | public ReferenceTypeName(IdentifierToken... ids) { |
| 67 | 115 | this(Arrays.asList(ids)); |
| 68 | } | |
| 69 | ||
| 70 | 115 | public ReferenceTypeName(String... names) { |
| 71 | 115 | this(stringsToIdentifiers(names)); |
| 72 | } | |
| 73 | ||
| 74 | 51 | public ReferenceTypeName(String[] names, SourceInfo si) { |
| 75 | 51 | this(Arrays.asList(stringsToIdentifiers(names)), si); |
| 76 | } | |
| 77 | ||
| 78 | 166 | private static IdentifierToken[] stringsToIdentifiers(String[] names) { |
| 79 | 166 | IdentifierToken[] ids = new IdentifierToken[names.length]; |
| 80 | 166 | for (int i = 0; i < names.length; i++) { |
| 81 | 206 | ids[i] = new Identifier(names[i]); |
| 82 | } | |
| 83 | 166 | return ids; |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Initializes the type | |
| 88 | * @param ids the list of the tokens that compose the type name | |
| 89 | * @exception IllegalArgumentException if ids is null or empty | |
| 90 | */ | |
| 91 | 2025 | public ReferenceTypeName(List<? extends IdentifierToken> ids, SourceInfo si) { |
| 92 | 2025 | super(si); |
| 93 | ||
| 94 | 0 | if (ids == null) throw new IllegalArgumentException("ids == null"); |
| 95 | 0 | if (ids.size() == 0) throw new IllegalArgumentException("ids.size() == 0"); |
| 96 | 2025 | identifiers = ids; |
| 97 | 2025 | representation = TreeUtilities.listToName(ids); |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * Returns the representation of this type | |
| 102 | */ | |
| 103 | 203 | public String getRepresentation() { |
| 104 | 203 | return representation; |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * Returns the list of identifiers that make up this type | |
| 109 | */ | |
| 110 | 1847 | public List<? extends IdentifierToken> getIdentifiers() { |
| 111 | 1847 | return identifiers; |
| 112 | } | |
| 113 | ||
| 114 | /** | |
| 115 | * Sets the identifiers of this type | |
| 116 | * @exception IllegalArgumentException if ids is null or empty | |
| 117 | */ | |
| 118 | 0 | public void setIdentifiers(List<? extends IdentifierToken> ids) { |
| 119 | 0 | if (ids == null) throw new IllegalArgumentException("ids == null"); |
| 120 | 0 | if (ids.size() == 0) throw new IllegalArgumentException("ids.size() == 0"); |
| 121 | 0 | identifiers = ids; |
| 122 | 0 | representation = TreeUtilities.listToName(ids); |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * Allows a visitor to traverse the tree | |
| 127 | * @param visitor the visitor to accept | |
| 128 | */ | |
| 129 | 1340 | public <T> T acceptVisitor(Visitor<T> visitor) { |
| 130 | 1340 | return visitor.visit(this); |
| 131 | } | |
| 132 | /** | |
| 133 | * Implementation of toString for use in unit testing | |
| 134 | */ | |
| 135 | 52 | public String toString() { |
| 136 | 52 | return "("+getClass().getName()+": "+toStringHelper()+")"; |
| 137 | } | |
| 138 | ||
| 139 | 52 | protected String toStringHelper() { |
| 140 | 52 | return getRepresentation(); |
| 141 | } | |
| 142 | } |
|
||||||||||