|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AmbiguousName.java | 33.3% | 68.2% | 80% | 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 | import koala.dynamicjava.tree.visitor.*; | |
| 33 | ||
| 34 | /** | |
| 35 | * This class represents the qualified name nodes of the syntax tree | |
| 36 | * | |
| 37 | * @author Stephane Hillion | |
| 38 | * @version 1.0 - 1999/04/24 | |
| 39 | */ | |
| 40 | ||
| 41 | public class AmbiguousName extends PrimaryExpression implements LeftHandSide { | |
| 42 | ||
| 43 | /** | |
| 44 | * The identifiers (tokens) that compose this name | |
| 45 | */ | |
| 46 | private List<IdentifierToken> identifiers; | |
| 47 | ||
| 48 | /** | |
| 49 | * The representation of this object | |
| 50 | */ | |
| 51 | private String representation; | |
| 52 | ||
| 53 | /** | |
| 54 | * Creates a new qualified name | |
| 55 | * @param ids the identifiers (IdentifierTokens) that compose this name | |
| 56 | * @exception IllegalArgumentException if ids is null | |
| 57 | */ | |
| 58 | 2 | public AmbiguousName(List<IdentifierToken> ids) { |
| 59 | 2 | this(ids, SourceInfo.NONE); |
| 60 | } | |
| 61 | ||
| 62 | 0 | public AmbiguousName(IdentifierToken... ids) { |
| 63 | 0 | this(Arrays.asList(ids), SourceInfo.NONE); |
| 64 | } | |
| 65 | ||
| 66 | 38 | public AmbiguousName(String... ids) { |
| 67 | 38 | this(makeIdList(ids), SourceInfo.NONE); |
| 68 | } | |
| 69 | ||
| 70 | 38 | private static List<IdentifierToken> makeIdList(String... ids) { |
| 71 | 38 | List<IdentifierToken> result = new LinkedList<IdentifierToken>(); |
| 72 | 41 | for (String id : ids) { result.add(new Identifier(id)); } |
| 73 | 38 | return result; |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Creates a new qualified name | |
| 78 | * @param ids the identifiers (IdentifierTokens) that compose this name | |
| 79 | * @exception IllegalArgumentException if ids is null | |
| 80 | */ | |
| 81 | 1778 | public AmbiguousName(List<IdentifierToken> ids, SourceInfo si) { |
| 82 | 1778 | super(si); |
| 83 | ||
| 84 | 0 | if (ids == null) throw new IllegalArgumentException("ids == null"); |
| 85 | 0 | if (ids.size() == 0) throw new IllegalArgumentException("ids.size() == 0"); |
| 86 | ||
| 87 | 1778 | identifiers = ids; |
| 88 | 1778 | representation = TreeUtilities.listToName(ids); |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * Returns the representation of this object | |
| 93 | */ | |
| 94 | 315 | public String getRepresentation() { |
| 95 | 315 | return representation; |
| 96 | } | |
| 97 | ||
| 98 | /** | |
| 99 | * Returns the identifiers that compose this name | |
| 100 | */ | |
| 101 | 1931 | public List<IdentifierToken> getIdentifiers() { |
| 102 | 1931 | return identifiers; |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Sets the identifiers that compose this name. Update representation | |
| 107 | * @exception IllegalArgumentException if l is null | |
| 108 | */ | |
| 109 | 0 | public void setIdentifier(List<IdentifierToken> l) { |
| 110 | 0 | if (l == null) throw new IllegalArgumentException("l == null"); |
| 111 | 0 | identifiers = l; |
| 112 | 0 | representation = TreeUtilities.listToName(l); |
| 113 | } | |
| 114 | ||
| 115 | /** | |
| 116 | * Allows a visitor to traverse the tree | |
| 117 | * @param visitor the visitor to accept | |
| 118 | */ | |
| 119 | 1815 | public <T> T acceptVisitor(Visitor<T> visitor) { |
| 120 | 1815 | return visitor.visit(this); |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * Implementation of toString for use in unit testing | |
| 125 | */ | |
| 126 | 80 | public String toString() { |
| 127 | 80 | return "("+getClass().getName()+": "+getRepresentation()+")"; |
| 128 | } | |
| 129 | } |
|
||||||||||