Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 259   Methods: 6
NCLOC: 82   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConstantPoolEntry.java - 97.1% 100% 97.6%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
 55   
 
 56   
 import java.io.DataInputStream;
 57   
 import java.io.IOException;
 58   
 
 59   
 /**
 60   
  * An entry in the constant pool. This class contains a represenation of the
 61   
  * constant pool entries. It is an abstract base class for all the different
 62   
  * forms of constant pool entry.
 63   
  *
 64   
  * @author Conor MacNeill
 65   
  * @see ConstantPool
 66   
  */
 67   
 public abstract class ConstantPoolEntry {
 68   
 
 69   
     /** Tag value for UTF8 entries. */
 70   
     public static final int CONSTANT_UTF8 = 1;
 71   
 
 72   
     /** Tag value for Integer entries. */
 73   
     public static final int CONSTANT_INTEGER = 3;
 74   
 
 75   
     /** Tag value for Float entries. */
 76   
     public static final int CONSTANT_FLOAT = 4;
 77   
 
 78   
     /** Tag value for Long entries. */
 79   
     public static final int CONSTANT_LONG = 5;
 80   
 
 81   
     /** Tag value for Double entries. */
 82   
     public static final int CONSTANT_DOUBLE = 6;
 83   
 
 84   
     /** Tag value for Class entries. */
 85   
     public static final int CONSTANT_CLASS = 7;
 86   
 
 87   
     /** Tag value for String entries. */
 88   
     public static final int CONSTANT_STRING = 8;
 89   
 
 90   
     /** Tag value for Field Reference entries. */
 91   
     public static final int CONSTANT_FIELDREF = 9;
 92   
 
 93   
     /** Tag value for Method Reference entries. */
 94   
     public static final int CONSTANT_METHODREF = 10;
 95   
 
 96   
     /** Tag value for Interface Method Reference entries. */
 97   
     public static final int CONSTANT_INTERFACEMETHODREF = 11;
 98   
 
 99   
     /** Tag value for Name and Type entries. */
 100   
     public static final int CONSTANT_NAMEANDTYPE = 12;
 101   
 
 102   
     /**
 103   
      * This entry's tag which identifies the type of this constant pool
 104   
      * entry.
 105   
      */
 106   
     private int tag;
 107   
 
 108   
     /**
 109   
      * The number of slots in the constant pool, occupied by this entry.
 110   
      */
 111   
     private int numEntries;
 112   
 
 113   
     /**
 114   
      * A flag which indiciates if this entry has been resolved or not.
 115   
      */
 116   
     private boolean resolved;
 117   
 
 118   
     /**
 119   
      * Initialse the constant pool entry.
 120   
      *
 121   
      * @param tagValue the tag value which identifies which type of constant
 122   
      *      pool entry this is.
 123   
      * @param entries the number of constant pool entry slots this entry
 124   
      *      occupies.
 125   
      */
 126  1936022
     public ConstantPoolEntry(int tagValue, int entries) {
 127  1936022
         tag = tagValue;
 128  1936022
         numEntries = entries;
 129  1936022
         resolved = false;
 130   
     }
 131   
 
 132   
     /**
 133   
      * Read a constant pool entry from a stream. This is a factory method
 134   
      * which reads a constant pool entry form a stream and returns the
 135   
      * appropriate subclass for the entry.
 136   
      *
 137   
      * @param cpStream the stream from which the constant pool entry is to
 138   
      *      be read.
 139   
      * @return the appropriate ConstantPoolEntry subclass representing the
 140   
      *      constant pool entry from the stream.
 141   
      * @exception IOException if the constant pool entry cannot be read 
 142   
      *      from the stream
 143   
      */
 144  1936022
     public static ConstantPoolEntry readEntry(DataInputStream cpStream)
 145   
          throws IOException {
 146  1936022
         ConstantPoolEntry cpInfo = null;
 147  1936022
         int cpTag = cpStream.readUnsignedByte();
 148   
 
 149  1936022
         switch (cpTag) {
 150   
 
 151   
             case CONSTANT_UTF8:
 152  978500
                 cpInfo = new Utf8CPInfo();
 153   
 
 154  978500
                 break;
 155   
             case CONSTANT_INTEGER:
 156  21074
                 cpInfo = new IntegerCPInfo();
 157   
 
 158  21074
                 break;
 159   
             case CONSTANT_FLOAT:
 160  770
                 cpInfo = new FloatCPInfo();
 161   
 
 162  770
                 break;
 163   
             case CONSTANT_LONG:
 164  2078
                 cpInfo = new LongCPInfo();
 165   
 
 166  2078
                 break;
 167   
             case CONSTANT_DOUBLE:
 168  576
                 cpInfo = new DoubleCPInfo();
 169   
 
 170  576
                 break;
 171   
             case CONSTANT_CLASS:
 172  157875
                 cpInfo = new ClassCPInfo();
 173   
 
 174  157875
                 break;
 175   
             case CONSTANT_STRING:
 176  106428
                 cpInfo = new StringCPInfo();
 177   
 
 178  106428
                 break;
 179   
             case CONSTANT_FIELDREF:
 180  88863
                 cpInfo = new FieldRefCPInfo();
 181   
 
 182  88863
                 break;
 183   
             case CONSTANT_METHODREF:
 184  261073
                 cpInfo = new MethodRefCPInfo();
 185   
 
 186  261073
                 break;
 187   
             case CONSTANT_INTERFACEMETHODREF:
 188  20270
                 cpInfo = new InterfaceMethodRefCPInfo();
 189   
 
 190  20270
                 break;
 191   
             case CONSTANT_NAMEANDTYPE:
 192  298515
                 cpInfo = new NameAndTypeCPInfo();
 193   
 
 194  298515
                 break;
 195   
             default:
 196  0
                 throw new ClassFormatError("Invalid Constant Pool entry Type "
 197   
                      + cpTag);
 198   
         }
 199   
 
 200  1936022
         cpInfo.read(cpStream);
 201   
 
 202  1936022
         return cpInfo;
 203   
     }
 204   
 
 205   
     /**
 206   
      * Indicates whether this entry has been resolved. In general a constant
 207   
      * pool entry can reference another constant pool entry by its index
 208   
      * value. Resolution involves replacing this index value with the
 209   
      * constant pool entry at that index.
 210   
      *
 211   
      * @return true if this entry has been resolved.
 212   
      */
 213  1936022
     public boolean isResolved() {
 214  1936022
         return resolved;
 215   
     }
 216   
 
 217   
     /**
 218   
      * Resolve this constant pool entry with respect to its dependents in
 219   
      * the constant pool.
 220   
      *
 221   
      * @param constantPool the constant pool of which this entry is a member
 222   
      *      and against which this entry is to be resolved.
 223   
      */
 224  2323549
     public void resolve(ConstantPool constantPool) {
 225  2323549
         resolved = true;
 226   
     }
 227   
 
 228   
     /**
 229   
      * read a constant pool entry from a class stream.
 230   
      *
 231   
      * @param cpStream the DataInputStream which contains the constant pool
 232   
      *      entry to be read.
 233   
      * @exception IOException if there is a problem reading the entry from
 234   
      *      the stream.
 235   
      */
 236   
     public abstract void read(DataInputStream cpStream) throws IOException;
 237   
 
 238   
     /**
 239   
      * Get the Entry's type tag.
 240   
      *
 241   
      * @return The Tag value of this entry
 242   
      */
 243  422
     public int getTag() {
 244  422
         return tag;
 245   
     }
 246   
 
 247   
     /**
 248   
      * Get the number of Constant Pool Entry slots within the constant pool
 249   
      * occupied by this entry.
 250   
      *
 251   
      * @return the number of slots used.
 252   
      */
 253  3872044
     public final int getNumEntries() {
 254  3872044
         return numEntries;
 255   
     }
 256   
 
 257   
 }
 258   
 
 259