|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| Literal.java | 25% | 62.5% | 66.7% | 58.6% |
|
||||||||||||||
| 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 literal nodes of the syntax tree | |
| 35 | * | |
| 36 | * @author Stephane Hillion | |
| 37 | * @version 1.0 - 1999/04/24 | |
| 38 | */ | |
| 39 | ||
| 40 | public abstract class Literal extends PrimaryExpression { | |
| 41 | /** | |
| 42 | * The representation of the literal | |
| 43 | */ | |
| 44 | private String representation; | |
| 45 | ||
| 46 | /** | |
| 47 | * The value of this literal | |
| 48 | */ | |
| 49 | private Object value; | |
| 50 | ||
| 51 | /** | |
| 52 | * The type of this literal | |
| 53 | */ | |
| 54 | private Class<?> type; | |
| 55 | ||
| 56 | /** | |
| 57 | * Initializes a literal | |
| 58 | * @param rep the representation of the literal | |
| 59 | * @param val the value of this literal | |
| 60 | * @param typ the type of this literal | |
| 61 | * @exception IllegalArgumentException if rep is null | |
| 62 | */ | |
| 63 | 1041 | protected Literal(String rep, Object val, Class<?> typ, SourceInfo si) { |
| 64 | 1041 | super(si); |
| 65 | ||
| 66 | 0 | if (rep == null) throw new IllegalArgumentException("rep == null"); |
| 67 | ||
| 68 | 1041 | representation = rep; |
| 69 | 1041 | value = val; |
| 70 | 1041 | type = typ; |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Returns the representation of this object | |
| 75 | */ | |
| 76 | 88 | public String getRepresentation() { |
| 77 | 88 | return representation; |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * Sets the representation of this object | |
| 82 | * @exception IllegalArgumentException if s is null | |
| 83 | */ | |
| 84 | 0 | public void setRepresentation(String s) { |
| 85 | 0 | if (s == null) throw new IllegalArgumentException("s == null"); |
| 86 | 0 | representation = s; |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Returns the value of this expression | |
| 91 | */ | |
| 92 | 1030 | public Object getValue() { |
| 93 | 1030 | return value; |
| 94 | } | |
| 95 | ||
| 96 | /** | |
| 97 | * Sets the value of this object | |
| 98 | * @exception IllegalArgumentException if o is null | |
| 99 | */ | |
| 100 | 0 | public void setValue(Object o) { |
| 101 | 0 | value = o; |
| 102 | } | |
| 103 | ||
| 104 | /** | |
| 105 | * Returns the type of this expression. | |
| 106 | * NOTE: the 'null' literal has a null type | |
| 107 | */ | |
| 108 | 619 | public Class<?> getType() { |
| 109 | 619 | return type; |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * Sets the type of this object | |
| 114 | */ | |
| 115 | 0 | public void setType(Class<?> c) { |
| 116 | 0 | type = c; |
| 117 | } | |
| 118 | ||
| 119 | /** | |
| 120 | * Allows a visitor to traverse the tree | |
| 121 | * @param visitor the visitor to accept | |
| 122 | */ | |
| 123 | 921 | public <T> T acceptVisitor(Visitor<T> visitor) { |
| 124 | 921 | return visitor.visit(this); |
| 125 | } | |
| 126 | /** | |
| 127 | * Implementation of toString for use in unit testing | |
| 128 | */ | |
| 129 | 88 | public String toString() { |
| 130 | 88 | return "("+getClass().getName()+": "+getRepresentation()+" "+getValue()+" "+getType()+")"; |
| 131 | } | |
| 132 | } |
|
||||||||||