Clover coverage report - DynamicJava Test Coverage (dynamicjava-20110903-r5436)
Coverage timestamp: Sat Sep 3 2011 03:02:20 CDT
file stats: LOC: 185   Methods: 15
NCLOC: 65   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ArrayAllocation.java 50% 75% 80% 70.5%
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 java.util.*;
 32   
 33    import koala.dynamicjava.tree.visitor.*;
 34   
 35    /** This class represents the array allocation nodes of the syntax tree
 36    * @author Stephane Hillion
 37    * @version 1.0 - 1999/04/25
 38    */
 39   
 40    public class ArrayAllocation extends PrimaryExpression {
 41    /** The creationType */
 42    private TypeName elementType;
 43   
 44    /** The type descriptor */
 45    private TypeDescriptor typeDescriptor;
 46   
 47    /** Initializes the expression
 48    * @param tp the type prefix
 49    * @param td the type descriptor
 50    * @exception IllegalArgumentException if tp is null or td is null
 51    */
 52  22 public ArrayAllocation(TypeName tp, TypeDescriptor td) { this(tp, td, SourceInfo.NONE); }
 53   
 54    /**
 55    * Initializes the expression
 56    * @param tp the type prefix
 57    * @param td the type descriptor. The element type of the enclosed initializer will
 58    * be automatically and recursively set.
 59    * @exception IllegalArgumentException if tp is null or td is null
 60    */
 61  36 public ArrayAllocation(TypeName tp, TypeDescriptor td,
 62    SourceInfo si) {
 63  36 super(si);
 64   
 65  0 if (tp == null) throw new IllegalArgumentException("tp == null");
 66  0 if (td == null) throw new IllegalArgumentException("td == null");
 67  36 elementType = tp;
 68  36 typeDescriptor = td;
 69  36 td.initialize(tp);
 70    }
 71   
 72    /**
 73    * Returns the creation type
 74    */
 75  16 public TypeName getElementType() {
 76  16 return elementType;
 77    }
 78   
 79    /**
 80    * Sets the creation type
 81    * @exception IllegalArgumentException if t is null
 82    */
 83  0 public void setElementType(TypeName t) {
 84  0 if (t == null) throw new IllegalArgumentException("t == null");
 85  0 elementType = t;
 86    }
 87   
 88    /**
 89    * Returns the dimension of the array
 90    */
 91  28 public int getDimension() { return typeDescriptor.dimension; }
 92   
 93    /**
 94    * Note: This method <em>doesn't</em> follow the usual convention of
 95    * firing a property change. If that functionality is needed, the code should
 96    * be fixed.
 97    */
 98  0 public void setDimension(int dim) { typeDescriptor.dimension = dim; }
 99   
 100    /** Returns the size expressions */
 101  40 public List<Expression> getSizes() {
 102  40 return typeDescriptor.sizes;
 103    }
 104   
 105    /**
 106    * Note: This method <em>doesn't</em> follow the usual convention of
 107    * firing a property change. If that functionality is needed, the code should
 108    * be fixed.
 109    */
 110  12 public void setSizes(List<? extends Expression> sz) {
 111  12 typeDescriptor.sizes = (sz == null) ? null : new ArrayList<Expression>(sz);
 112    }
 113   
 114    /**
 115    * Returns the initialization expression
 116    */
 117  92 public ArrayInitializer getInitialization() {
 118  92 return typeDescriptor.initialization;
 119    }
 120   
 121    /**
 122    * Note: This method <em>doesn't</em> follow the usual convention of
 123    * firing a property change. If that functionality is needed, the code should
 124    * be fixed.
 125    *
 126    * @param init An initializer, assumed to already be set up with a valid element type.
 127    * (The ArrayInitializer constructor will set up the element type automatically,
 128    * but this method does not.)
 129    */
 130  0 public void setInitialization(ArrayInitializer init) { typeDescriptor.initialization = init; }
 131   
 132    /**
 133    * Allows a visitor to traverse the tree
 134    * @param visitor the visitor to accept
 135    */
 136  46 public <T> T acceptVisitor(Visitor<T> visitor) {
 137  46 return visitor.visit(this);
 138    }
 139   
 140    /**
 141    * Implementation of toString for use in unit testing
 142    */
 143  4 public String toString() {
 144  4 return "(" + getClass().getName() + ": " + getElementType() + " " + getDimension() + " " + getSizes() + ")";
 145    }
 146   
 147    /**
 148    * This class contains informations about the array to create
 149    */
 150    public static class TypeDescriptor implements SourceInfo.Wrapper {
 151    /** The array dimension sizes */
 152    List<Expression> sizes;
 153   
 154    /** The array dimension */
 155    int dimension;
 156   
 157    /** The initialization expression */
 158    ArrayInitializer initialization;
 159   
 160    SourceInfo sourceInfo;
 161   
 162    /** Creates a new type descriptor */
 163  36 public TypeDescriptor(List<? extends Expression> sizes, int dim, ArrayInitializer init, SourceInfo si) {
 164  36 this.sizes = (sizes == null) ? null : new ArrayList<Expression>(sizes);
 165  36 dimension = dim;
 166  36 initialization = init;
 167  36 sourceInfo = si;
 168    }
 169   
 170  14 public SourceInfo getSourceInfo() { return sourceInfo; }
 171   
 172    /** Initializes the type descriptor */
 173  36 void initialize(TypeName t) {
 174  36 if (initialization != null) {
 175  34 TypeName et;
 176  34 if (dimension > 1)
 177  0 et = new ArrayTypeName(t, dimension-1, false, SourceInfo.span(t, this));
 178    else
 179  34 et = t;
 180   
 181  34 initialization.setElementType(et);
 182    }
 183    }
 184    }
 185    }