Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 183   Methods: 7
NCLOC: 85   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClassFile.java 78.6% 87.8% 85.7% 85.7%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-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.sitraka.bytecode;
 55   
 
 56   
 import java.io.DataInputStream;
 57   
 import java.io.IOException;
 58   
 import java.io.InputStream;
 59   
 import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ClassCPInfo;
 60   
 import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool;
 61   
 import org.apache.tools.ant.taskdefs.optional.depend.constantpool.Utf8CPInfo;
 62   
 import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.attributes.AttributeInfo;
 63   
 
 64   
 
 65   
 /**
 66   
  * Object representing a class.
 67   
  *
 68   
  * Information are kept to the strict minimum for JProbe reports so
 69   
  * that not too many objects are created for a class, otherwise the
 70   
  * JVM can quickly run out of memory when analyzing a great deal of
 71   
  * classes and keeping them in memory for global analysis.
 72   
  *
 73   
  * @author <a href="sbailliez@imediation.com">Stephane Bailliez</a>
 74   
  */
 75   
 public final class ClassFile {
 76   
 
 77   
     private MethodInfo[] methods;
 78   
 
 79   
     private String sourceFile;
 80   
 
 81   
     private String fullname;
 82   
 
 83   
     private int access_flags;
 84   
 
 85  17387
     public ClassFile(InputStream is) throws IOException {
 86  17387
         DataInputStream dis = new DataInputStream(is);
 87  17387
         ConstantPool constantPool = new ConstantPool();
 88   
 
 89  17387
         /* int magic = */ dis.readInt(); // 0xCAFEBABE
 90  17387
         /* int minor = */ dis.readShort();
 91  17387
         /* int major = */ dis.readShort();
 92   
 
 93  17387
         constantPool.read(dis);
 94  17387
         constantPool.resolve();
 95   
 
 96   
         // class information
 97  17387
         access_flags = dis.readShort();
 98  17387
         int this_class = dis.readShort();
 99  17387
         fullname = ((ClassCPInfo) constantPool.getEntry(this_class)).getClassName().replace('/', '.');
 100  17387
         /* int super_class = */ dis.readShort();
 101   
 
 102   
         // skip interfaces...
 103  17387
         int count = dis.readShort();
 104  17387
         dis.skipBytes(count * 2); // short
 105   
 
 106   
         // skip fields...
 107  17387
         int numFields = dis.readShort();
 108  17387
         for (int i = 0; i < numFields; i++) {
 109   
             // 3 short: access flags, name index, descriptor index
 110  73630
             dis.skip(2 * 3);
 111   
             // attribute list...
 112  73630
             int attributes_count = dis.readUnsignedShort();
 113  73630
             for (int j = 0; j < attributes_count; j++) {
 114  31420
                 dis.skipBytes(2); // skip attr_id (short)
 115  31420
                 int len = dis.readInt();
 116  31420
                 dis.skipBytes(len);
 117   
             }
 118   
         }
 119   
 
 120   
         // read methods
 121  17387
         int method_count = dis.readShort();
 122  17387
         methods = new MethodInfo[method_count];
 123  17387
         for (int i = 0; i < method_count; i++) {
 124  155833
             methods[i] = new MethodInfo();
 125  155833
             methods[i].read(constantPool, dis);
 126   
         }
 127   
 
 128   
         // get interesting attributes.
 129  17387
         int attributes_count = dis.readUnsignedShort();
 130  17387
         for (int j = 0; j < attributes_count; j++) {
 131  25049
             int attr_id = dis.readShort();
 132  25049
             int len = dis.readInt();
 133  25049
             String attr_name = Utils.getUTF8Value(constantPool, attr_id);
 134  25049
             if (AttributeInfo.SOURCE_FILE.equals(attr_name)) {
 135  17367
                 int name_index = dis.readShort();
 136  17367
                 sourceFile = ((Utf8CPInfo) constantPool.getEntry(name_index)).getValue();
 137   
             } else {
 138  7682
                 dis.skipBytes(len);
 139   
             }
 140   
         }
 141   
     }
 142   
 
 143  8692
     public int getAccess() {
 144  8692
         return access_flags;
 145   
     }
 146   
 
 147  1
     public String getSourceFile() {
 148  1
         return sourceFile;
 149   
     }
 150   
 
 151  7675
     public MethodInfo[] getMethods() {
 152  7675
         return methods;
 153   
     }
 154   
 
 155  98311
     public String getFullName() {
 156  98311
         return fullname;
 157   
     }
 158   
 
 159  1
     public String getName() {
 160  1
         String name = getFullName();
 161  1
         int pos = name.lastIndexOf('.');
 162  1
         if (pos == -1) {
 163  0
             return "";
 164   
         }
 165  1
         return name.substring(pos + 1);
 166   
     }
 167   
 
 168  0
     public String getPackage() {
 169  0
         String name = getFullName();
 170  0
         int pos = name.lastIndexOf('.');
 171  0
         if (pos == -1) {
 172  0
             return "";
 173   
         }
 174  0
         return name.substring(0, pos);
 175   
     }
 176   
 
 177   
 }
 178   
 
 179   
 
 180   
 
 181   
 
 182   
 
 183