Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 183   Methods: 13
NCLOC: 93   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MethodInfo.java 91.7% 87.5% 84.6% 87.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 org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool;
 59   
 import org.apache.tools.ant.taskdefs.optional.sitraka.bytecode.attributes.AttributeInfo;
 60   
 
 61   
 /**
 62   
  * Method info structure.
 63   
  * @todo give a more appropriate name to methods.
 64   
  *
 65   
  * @author <a href="sbailliez@imediation.com">Stephane Bailliez</a>
 66   
  */
 67   
 public final class MethodInfo {
 68   
     private int access_flags;
 69   
     private int loc = -1;
 70   
     private String name;
 71   
     private String descriptor;
 72   
 
 73  155833
     public MethodInfo() {
 74   
     }
 75   
 
 76  155833
     public void read(ConstantPool constantPool, DataInputStream dis) throws IOException {
 77  155833
         access_flags = dis.readShort();
 78   
 
 79  155833
         int name_index = dis.readShort();
 80  155833
         name = Utils.getUTF8Value(constantPool, name_index);
 81   
 
 82  155833
         int descriptor_index = dis.readShort();
 83  155833
         descriptor = Utils.getUTF8Value(constantPool, descriptor_index);
 84   
 
 85  155833
         int attributes_count = dis.readUnsignedShort();
 86  155833
         for (int i = 0; i < attributes_count; i++) {
 87  172387
             int attr_id = dis.readShort();
 88  172387
             String attr_name = Utils.getUTF8Value(constantPool, attr_id);
 89  172387
             int len = dis.readInt();
 90  172387
             if (AttributeInfo.CODE.equals(attr_name)) {
 91  137093
                 readCode(constantPool, dis);
 92   
             } else {
 93  35294
                 dis.skipBytes(len);
 94   
             }
 95   
         }
 96   
 
 97   
     }
 98   
 
 99  137093
     protected void readCode(ConstantPool constantPool, DataInputStream dis) throws IOException {
 100   
         // skip max_stack (short), max_local (short)
 101  137093
         dis.skipBytes(2 * 2);
 102   
 
 103   
         // skip bytecode...
 104  137093
         int bytecode_len = dis.readInt();
 105  137093
         dis.skip(bytecode_len);
 106   
 
 107   
         // skip exceptions... 1 exception = 4 short.
 108  137093
         int exception_count = dis.readShort();
 109  137093
         dis.skipBytes(exception_count * 4 * 2);
 110   
 
 111   
         // read attributes...
 112  137093
         int attributes_count = dis.readUnsignedShort();
 113  137093
         for (int i = 0; i < attributes_count; i++) {
 114  129880
             int attr_id = dis.readShort();
 115  129880
             String attr_name = Utils.getUTF8Value(constantPool, attr_id);
 116  129880
             int len = dis.readInt();
 117  129880
             if (AttributeInfo.LINE_NUMBER_TABLE.equals(attr_name)) {
 118   
                 // we're only interested in lines of code...
 119  129877
                 loc = dis.readShort();
 120   
                 // skip the table which is 2*loc*short
 121  129877
                 dis.skip(loc * 2 * 2);
 122   
             } else {
 123  3
                 dis.skipBytes(len);
 124   
             }
 125   
         }
 126   
     }
 127   
 
 128  3
     public int getAccessFlags() {
 129  3
         return access_flags;
 130   
     }
 131   
 
 132  72284
     public String getName() {
 133  72284
         return name;
 134   
     }
 135   
 
 136  59
     public String getDescriptor() {
 137  59
         return descriptor;
 138   
     }
 139   
 
 140  6
     public String getFullSignature() {
 141  6
         return getReturnType() + " " + getShortSignature();
 142   
     }
 143   
 
 144  6
     public String getShortSignature() {
 145  6
         StringBuffer buf = new StringBuffer(getName());
 146  6
         buf.append("(");
 147  6
         String[] params = getParametersType();
 148  6
         for (int i = 0; i < params.length; i++) {
 149  6
             buf.append(params[i]);
 150  6
             if (i != params.length - 1) {
 151  0
                 buf.append(", ");
 152   
             }
 153   
         }
 154  6
         buf.append(")");
 155  6
         return buf.toString();
 156   
     }
 157   
 
 158  6
     public String getReturnType() {
 159  6
         return Utils.getMethodReturnType(getDescriptor());
 160   
     }
 161   
 
 162  53
     public String[] getParametersType() {
 163  53
         return Utils.getMethodParams(getDescriptor());
 164   
     }
 165   
 
 166  3
     public int getNumberOfLines() {
 167  3
         return loc;
 168   
     }
 169   
 
 170  0
     public String getAccess() {
 171  0
         return Utils.getMethodAccess(access_flags);
 172   
     }
 173   
 
 174  0
     public String toString() {
 175  0
         StringBuffer sb = new StringBuffer();
 176  0
         sb.append("Method: ").append(getAccess()).append(" ");
 177  0
         sb.append(getFullSignature());
 178  0
         return sb.toString();
 179   
     }
 180   
 }
 181   
 
 182   
 
 183