|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ClassDeclaration.java | 50% | 58.3% | 66.7% | 60% |
|
||||||||||||||
| 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 edu.rice.cs.plt.tuple.Option; | |
| 34 | ||
| 35 | import koala.dynamicjava.tree.tiger.TypeParameter; | |
| 36 | import koala.dynamicjava.tree.visitor.*; | |
| 37 | ||
| 38 | /** | |
| 39 | * This class represents a class declaration | |
| 40 | * | |
| 41 | * @author Stephane Hillion | |
| 42 | * @version 1.0 - 1999/05/10 | |
| 43 | */ | |
| 44 | ||
| 45 | public class ClassDeclaration extends TypeDeclaration { | |
| 46 | /** Default supertype */ | |
| 47 | private static final ReferenceTypeName OBJECT = new ReferenceTypeName("java", "lang", "Object"); | |
| 48 | ||
| 49 | /** | |
| 50 | * The superclass of this class | |
| 51 | */ | |
| 52 | private ReferenceTypeName superclass; | |
| 53 | ||
| 54 | /** | |
| 55 | * Creates a new class declaration | |
| 56 | * @param mods the modifiers | |
| 57 | * @param name the name of the class to declare | |
| 58 | * @param ext the tokens that compose the name of the parent class. | |
| 59 | * The list can be null. The superclass property is then | |
| 60 | * set to "java.lang.Object". | |
| 61 | * @param impl the list of implemented interfaces (a list of list of | |
| 62 | * Token). Can be null. | |
| 63 | * @param body the list of members declarations | |
| 64 | */ | |
| 65 | 0 | public ClassDeclaration(ModifierSet mods, String name, ReferenceTypeName ext, List<? extends ReferenceTypeName> impl, List<Node> body) { |
| 66 | 0 | this(mods, name, Option.<List<TypeParameter>>none(), ext, impl, body, SourceInfo.NONE); |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * Creates a new class declaration | |
| 71 | * @param mods the modifiers | |
| 72 | * @param name the name of the class to declare | |
| 73 | * @param tparams the type parameters | |
| 74 | * @param ext the tokens that compose the name of the parent class. | |
| 75 | * The list can be null. The superclass property is then | |
| 76 | * set to "java.lang.Object". | |
| 77 | * @param impl the list of implemented interfaces (a list of list of | |
| 78 | * Token). Can be null. | |
| 79 | * @param body the list of members declarations | |
| 80 | */ | |
| 81 | 0 | public ClassDeclaration(ModifierSet mods, String name, Option<List<TypeParameter>> tparams, ReferenceTypeName ext, |
| 82 | List<? extends ReferenceTypeName> impl, List<Node> body) { | |
| 83 | 0 | this(mods, name, tparams, ext, impl, body, SourceInfo.NONE); |
| 84 | } | |
| 85 | ||
| 86 | /** | |
| 87 | * Creates a new class declaration | |
| 88 | * @param mods the modifiers | |
| 89 | * @param name the name of the class to declare | |
| 90 | * @param ext the tokens that compose the name of the parent class. | |
| 91 | * The list can be null. The superclass property is then | |
| 92 | * set to "java.lang.Object". | |
| 93 | * @param impl the list of implemented interfaces (a list of list of | |
| 94 | * Token). Can be null. | |
| 95 | * @param body the list of members declarations | |
| 96 | */ | |
| 97 | 1 | public ClassDeclaration(ModifierSet mods, String name, ReferenceTypeName ext, |
| 98 | List<? extends ReferenceTypeName> impl, List<Node> body, SourceInfo si) { | |
| 99 | 1 | this(mods, name, Option.<List<TypeParameter>>none(), ext, impl, body, si); |
| 100 | } | |
| 101 | ||
| 102 | /** | |
| 103 | * Creates a new class declaration | |
| 104 | * @param mods the modifiers | |
| 105 | * @param name the name of the class to declare | |
| 106 | * @param tparams the type parameters | |
| 107 | * @param ext the tokens that compose the name of the parent class. | |
| 108 | * The list can be null. The superclass property is then | |
| 109 | * set to "java.lang.Object". | |
| 110 | * @param impl the list of implemented interfaces (a list of list of | |
| 111 | * Token). Can be null. | |
| 112 | * @param body the list of members declarations | |
| 113 | */ | |
| 114 | 91 | public ClassDeclaration(ModifierSet mods, String name, Option<List<TypeParameter>> tparams, ReferenceTypeName ext, |
| 115 | List<? extends ReferenceTypeName> impl, List<Node> body, SourceInfo si) { | |
| 116 | 91 | super(mods, name, tparams, impl, body, si); |
| 117 | 91 | superclass = (ext == null) ? OBJECT : ext; |
| 118 | } | |
| 119 | ||
| 120 | ||
| 121 | /** | |
| 122 | * Returns the name of the superclass of this class | |
| 123 | */ | |
| 124 | 1610 | public ReferenceTypeName getSuperclass() { |
| 125 | 1610 | return superclass; |
| 126 | } | |
| 127 | ||
| 128 | /** | |
| 129 | * Sets the superclass name | |
| 130 | * @exception IllegalArgumentException if s is null | |
| 131 | */ | |
| 132 | 0 | public void setSuperclass(ReferenceTypeName s) { |
| 133 | 0 | if (s == null) throw new IllegalArgumentException("s == null"); |
| 134 | 0 | superclass = s; |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 138 | * Allows a visitor to traverse the tree | |
| 139 | * @param visitor the visitor to accept | |
| 140 | */ | |
| 141 | 141 | public <T> T acceptVisitor(Visitor<T> visitor) { |
| 142 | 141 | 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()+": "+toStringHelper()+")"; |
| 149 | } | |
| 150 | ||
| 151 | 2 | protected String toStringHelper() { |
| 152 | 2 | return getModifiers()+" "+getName()+" "+getTypeParams()+" "+getSuperclass()+" "+getInterfaces()+" "+getMembers(); |
| 153 | } | |
| 154 | } |
|
||||||||||