Clover coverage report - DynamicJava Test Coverage (dynamicjava-20130622-r5436)
Coverage timestamp: Sat Jun 22 2013 03:01:29 CDT
file stats: LOC: 155   Methods: 10
NCLOC: 50   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
VariableDeclaration.java 40% 63.6% 80% 61.9%
coverage coverage
 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 variable declarations in an AST
 35    *
 36    * @author Stephane Hillion
 37    * @version 1.0 - 1999/05/11
 38    */
 39   
 40    public class VariableDeclaration extends Declaration {
 41    /**
 42    * The type of this variable
 43    */
 44    private TypeName type;
 45   
 46    /**
 47    * The name of this variable
 48    */
 49    private String name;
 50   
 51    /**
 52    * The initializer
 53    */
 54    private Expression initializer;
 55   
 56    /**
 57    * Creates a new variable declaration
 58    * @param mods the modifiers
 59    * @param type the type of this variable
 60    * @param name the name of this variable
 61    * @param init the initializer
 62    * @exception IllegalArgumentException if name is null or type is null
 63    */
 64  11 public VariableDeclaration(ModifierSet mods, TypeName type, String name, Expression init) {
 65  11 this(mods, type, name, init, SourceInfo.NONE);
 66    }
 67   
 68    /**
 69    * Creates a new variable declaration
 70    * @param mods the modifiers
 71    * @param type the type of this variable
 72    * @param name the name of this variable
 73    * @param init the initializer
 74    * @exception IllegalArgumentException if name is null or type is null
 75    */
 76  682 public VariableDeclaration(ModifierSet mods, TypeName type, String name, Expression init,
 77    SourceInfo si) {
 78  682 super(mods, si);
 79   
 80    // TODO: restore this check? -- we're allowing an inferred type for now
 81    //if (type == null) throw new IllegalArgumentException("type == null");
 82  0 if (name == null) throw new IllegalArgumentException("name == null");
 83   
 84  682 this.type = type;
 85  682 this.name = name;
 86  682 initializer = init;
 87   
 88  682 if (type instanceof ArrayTypeName) {
 89  2 if (initializer instanceof ArrayInitializer) {
 90  0 ((ArrayInitializer)initializer).setElementType
 91    (((ArrayTypeName)type).getElementType());
 92    }
 93    }
 94    }
 95   
 96    /**
 97    * Gets the declared type for this variable
 98    */
 99  1342 public TypeName getType() {
 100  1342 return type;
 101    }
 102   
 103    /**
 104    * Sets the type of this field
 105    * @exception IllegalArgumentException if t is null
 106    */
 107  0 public void setType(TypeName t) {
 108  0 if (t == null) throw new IllegalArgumentException("t == null");
 109  0 type = t;
 110    }
 111   
 112    /**
 113    * Returns the name of this variable
 114    */
 115  679 public String getName() {
 116  679 return name;
 117    }
 118   
 119    /**
 120    * Sets the variable's name
 121    * @exception IllegalArgumentException if s is null
 122    */
 123  0 public void setName(String s) {
 124  0 if (s == null) throw new IllegalArgumentException("s == null");
 125  0 name = s;
 126    }
 127   
 128    /**
 129    * Returns the initializer for this variable
 130    */
 131  2591 public Expression getInitializer() {
 132  2591 return initializer;
 133    }
 134   
 135    /**
 136    * Sets the initializer
 137    */
 138  612 public void setInitializer(Expression e) {
 139  612 initializer = e;
 140    }
 141   
 142    /**
 143    * Allows a visitor to traverse the tree
 144    * @param visitor the visitor to accept
 145    */
 146  986 public <T> T acceptVisitor(Visitor<T> visitor) {
 147  986 return visitor.visit(this);
 148    }
 149    /**
 150    * Implementation of toString for use in unit testing
 151    */
 152  22 public String toString() {
 153  22 return "("+getClass().getName()+": "+getModifiers()+" "+getType()+" "+getName()+" "+getInitializer()+")";
 154    }
 155    }