Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 387   Methods: 23
NCLOC: 315   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TextPrinter.java 38.9% 29.4% 43.5% 31.7%
coverage coverage
 1    /*
 2    * Copyright (c) 2001-2009, Jean Tessier
 3    * All rights reserved.
 4    *
 5    * Redistribution and use in source and binary forms, with or without
 6    * modification, are permitted provided that the following conditions
 7    * are met:
 8    *
 9    * * Redistributions of source code must retain the above copyright
 10    * notice, this list of conditions and the following disclaimer.
 11    *
 12    * * Redistributions in binary form must reproduce the above copyright
 13    * notice, this list of conditions and the following disclaimer in the
 14    * documentation and/or other materials provided with the distribution.
 15    *
 16    * * Neither the name of Jean Tessier nor the names of his contributors
 17    * may be used to endorse or promote products derived from this software
 18    * without specific prior written permission.
 19    *
 20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 24    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31    */
 32   
 33    package com.jeantessier.classreader;
 34   
 35    import java.io.*;
 36    import java.util.*;
 37   
 38    public class TextPrinter extends Printer {
 39    private boolean top = true;
 40   
 41  20 public TextPrinter(PrintWriter out) {
 42  20 super(out);
 43    }
 44   
 45  0 public void visitClassfile(Classfile classfile) {
 46  0 top = true;
 47  0 classfile.getConstantPool().accept(this);
 48  0 top = false;
 49   
 50  0 eol();
 51   
 52  0 append(classfile.getDeclaration()).append(" {").eol();
 53   
 54  0 for (Field_info field : classfile.getAllFields()) {
 55  0 field.accept(this);
 56    }
 57   
 58  0 for (Method_info method : classfile.getAllMethods()) {
 59  0 method.accept(this);
 60    }
 61   
 62  0 append("}").eol();
 63    }
 64   
 65  0 public void visitClass_info(Class_info entry) {
 66  0 if (top) {
 67  0 top = false;
 68  0 append(currentCount()).append(": ");
 69  0 append("Class ");
 70  0 append(entry);
 71  0 eol();
 72  0 top = true;
 73    } else {
 74  0 append(entry);
 75    }
 76    }
 77   
 78  0 public void visitFieldRef_info(FieldRef_info entry) {
 79  0 if (top) {
 80  0 top = false;
 81  0 append(currentCount()).append(": ");
 82  0 append("Field ");
 83  0 append(entry);
 84  0 eol();
 85  0 top = true;
 86    } else {
 87  0 append(entry);
 88    }
 89    }
 90   
 91  0 public void visitMethodRef_info(MethodRef_info entry) {
 92  0 if (top) {
 93  0 top = false;
 94  0 append(currentCount()).append(": ");
 95  0 append("Method ");
 96  0 append(entry);
 97  0 eol();
 98  0 top = true;
 99    } else {
 100  0 append(entry);
 101    }
 102    }
 103   
 104  0 public void visitInterfaceMethodRef_info(InterfaceMethodRef_info entry) {
 105  0 if (top) {
 106  0 top = false;
 107  0 append(currentCount()).append(": ");
 108  0 append("Interface Method ");
 109  0 append(entry);
 110  0 eol();
 111  0 top = true;
 112    } else {
 113  0 append(entry);
 114    }
 115    }
 116   
 117  0 public void visitString_info(String_info entry) {
 118  0 if (top) {
 119  0 top = false;
 120  0 append(currentCount()).append(": String \"");
 121  0 entry.getRawValue().accept(this);
 122  0 append("\"").eol();
 123  0 top = true;
 124    } else {
 125  0 entry.getRawValue().accept(this);
 126    }
 127    }
 128   
 129  0 public void visitInteger_info(Integer_info entry) {
 130  0 if (top) {
 131  0 append(currentCount()).append(": Integer ").append(entry.getValue()).eol();
 132    } else {
 133  0 append(entry.getValue());
 134    }
 135    }
 136   
 137  0 public void visitFloat_info(Float_info entry) {
 138  0 if (top) {
 139  0 append(currentCount()).append(": Float ").append(entry.getValue()).eol();
 140    } else {
 141  0 append(entry.getValue());
 142    }
 143    }
 144   
 145  0 public void visitLong_info(Long_info entry) {
 146  0 if (top) {
 147  0 append(currentCount()).append(": Long ").append(entry.getValue()).eol();
 148    } else {
 149  0 append(entry.getValue());
 150    }
 151    }
 152   
 153  0 public void visitDouble_info(Double_info entry) {
 154  0 if (top) {
 155  0 append(currentCount()).append(": Double ").append(entry.getValue()).eol();
 156    } else {
 157  0 append(entry.getValue());
 158    }
 159    }
 160   
 161  0 public void visitNameAndType_info(NameAndType_info entry) {
 162  0 if (top) {
 163  0 top = false;
 164  0 append(currentCount()).append(": Name and Type ");
 165  0 entry.getRawName().accept(this);
 166  0 append(" ");
 167  0 entry.getRawType().accept(this);
 168  0 eol();
 169  0 top = true;
 170    } else {
 171  0 entry.getRawName().accept(this);
 172  0 append(" ");
 173  0 entry.getRawType().accept(this);
 174    }
 175    }
 176   
 177  0 public void visitUTF8_info(UTF8_info entry) {
 178  0 if (top) {
 179  0 append(currentCount()).append(": \"").append(entry.getValue()).append("\"").eol();
 180    } else {
 181  0 append(entry.getValue());
 182    }
 183    }
 184   
 185  0 public void visitField_info(Field_info entry) {
 186  0 append(" ").append(entry.getDeclaration()).append(";").eol();
 187    }
 188   
 189  4 public void visitMethod_info(Method_info entry) {
 190  4 eol();
 191  4 append(" ");
 192  4 append(entry.getDeclaration());
 193  4 if (!entry.isStaticInitializer()) {
 194  3 append(";");
 195    }
 196  4 eol();
 197   
 198    // As per the Class File Format (paragraph 4.8.3):
 199    // - abstract and native methods must *not* have a Code attribute
 200    // - all other methods must have exactly one Code attribute.
 201  4 if (!entry.isAbstract() && !entry.isNative()) {
 202  2 entry.getCode().accept(this);
 203    }
 204    }
 205   
 206  2 public void visitCode_attribute(Code_attribute attribute) {
 207  2 append(" CODE").eol();
 208  2 visitInstructions(attribute);
 209   
 210  2 Collection<? extends ExceptionHandler> exceptionHandlers = attribute.getExceptionHandlers();
 211  2 if (!exceptionHandlers.isEmpty()) {
 212  1 append(" EXCEPTION HANDLING").eol();
 213  1 visitExceptionHandlers(exceptionHandlers);
 214    }
 215    }
 216   
 217  11 public void visitInstruction(Instruction helper) {
 218  11 append(" ").append(helper.getStart()).append(":\t").append(helper.getMnemonic());
 219  11 appendIndexedConstantPoolEntry(helper);
 220  11 appendIndexedLocalVariable(helper);
 221  11 appendOffset(helper);
 222  11 appendValue(helper);
 223  11 eol();
 224   
 225  11 super.visitInstruction(helper);
 226    }
 227   
 228  2 public void visitExceptionHandler(ExceptionHandler helper) {
 229  2 append(" ").append(helper.getStartPC()).append("-").append(helper.getEndPC()).append(": ").append(helper.getHandlerPC());
 230  2 if (helper.getCatchTypeIndex() != 0) {
 231  1 append(" (").append(helper.getCatchType()).append(")");
 232    }
 233  2 eol();
 234    }
 235   
 236  11 private void appendIndexedConstantPoolEntry(Instruction helper) {
 237  11 switch (helper.getOpcode()) {
 238  0 case 0x12: // ldc
 239  0 case 0x13: // ldc_w
 240  0 case 0x14: // ldc2_w
 241  0 case 0xb2: // getstatic
 242  0 case 0xb3: // putstatic
 243  1 case 0xb4: // getfield
 244  0 case 0xb5: // putfield
 245  0 case 0xb6: // invokevirtual
 246  0 case 0xb7: // invokespecial
 247  0 case 0xb8: // invokestatic
 248  0 case 0xb9: // invokeinterface
 249  0 case 0xbb: // new
 250  0 case 0xbd: // anewarray
 251  0 case 0xc0: // checkcast
 252  0 case 0xc1: // instanceof
 253  0 case 0xc5: // multianewarray
 254  1 append(" ");
 255  1 helper.getIndexedConstantPoolEntry().accept(this);
 256  1 break;
 257  10 default:
 258    // Do nothing
 259  10 break;
 260    }
 261    }
 262   
 263  11 private void appendIndexedLocalVariable(Instruction helper) {
 264  11 switch (helper.getOpcode()) {
 265  0 case 0x1a: // iload_0
 266  0 case 0x1e: // lload_0
 267  0 case 0x22: // fload_0
 268  0 case 0x26: // dload_0
 269  0 case 0x2a: // aload_0
 270  0 case 0x3b: // istore_0
 271  0 case 0x3f: // lstore_0
 272  0 case 0x43: // fstore_0
 273  0 case 0x47: // dstore_0
 274  0 case 0x4b: // astore_0
 275  2 case 0x1b: // iload_1
 276  0 case 0x1f: // lload_1
 277  0 case 0x23: // fload_1
 278  0 case 0x27: // dload_1
 279  0 case 0x2b: // aload_1
 280  0 case 0x3c: // istore_1
 281  0 case 0x40: // lstore_1
 282  0 case 0x44: // fstore_1
 283  0 case 0x48: // dstore_1
 284  0 case 0x4c: // astore_1
 285  0 case 0x1c: // iload_2
 286  0 case 0x20: // lload_2
 287  0 case 0x24: // fload_2
 288  0 case 0x28: // dload_2
 289  0 case 0x2c: // aload_2
 290  0 case 0x3d: // istore_2
 291  0 case 0x41: // lstore_2
 292  0 case 0x45: // fstore_2
 293  0 case 0x49: // dstore_2
 294  0 case 0x4d: // astore_2
 295  0 case 0x1d: // iload_3
 296  0 case 0x21: // lload_3
 297  0 case 0x25: // fload_3
 298  0 case 0x29: // dload_3
 299  0 case 0x2d: // aload_3
 300  0 case 0x3e: // istore_3
 301  0 case 0x42: // lstore_3
 302  0 case 0x46: // fstore_3
 303  0 case 0x4a: // dstore_3
 304  0 case 0x4e: // astore_3
 305  2 appendLocalVariable(helper.getIndexedLocalVariable());
 306  2 break;
 307  1 case 0x15: // iload
 308  0 case 0x16: // llload
 309  0 case 0x17: // fload
 310  0 case 0x18: // dload
 311  0 case 0x19: // aload
 312  0 case 0x36: // istore
 313  0 case 0x37: // lstore
 314  0 case 0x38: // fstore
 315  0 case 0x39: // dstore
 316  0 case 0x3a: // astore
 317  0 case 0xa9: // ret
 318  1 case 0x84: // iinc
 319  2 case 0xc4: // wide
 320  4 appendLocalVariable(helper.getIndexedLocalVariable());
 321  4 append(" (#").append(helper.getIndex()).append(")");
 322  4 break;
 323  5 default:
 324    // Do nothing
 325  5 break;
 326    }
 327    }
 328   
 329  6 private void appendLocalVariable(LocalVariable localVariable) {
 330  6 if (localVariable != null) {
 331  5 append(" ").append(DescriptorHelper.getType(localVariable.getDescriptor())).append(" ").append(localVariable.getName());
 332    }
 333    }
 334   
 335  11 private void appendOffset(Instruction helper) {
 336  11 switch (helper.getOpcode()) {
 337  0 case 0x99: // ifeq
 338  0 case 0x9a: // ifne
 339  0 case 0x9b: // iflt
 340  0 case 0x9c: // ifge
 341  0 case 0x9d: // ifgt
 342  0 case 0x9e: // ifle
 343  0 case 0x9f: // if_icmpeq
 344  0 case 0xa0: // if_icmpne
 345  0 case 0xa1: // if_icmplt
 346  0 case 0xa2: // if_icmpge
 347  0 case 0xa3: // if_icmpgt
 348  0 case 0xa4: // if_icmple
 349  0 case 0xa5: // if_acmpeq
 350  0 case 0xa6: // if_acmpne
 351  3 case 0xa7: // goto
 352  0 case 0xa8: // jsr
 353  0 case 0xc6: // ifnull
 354  0 case 0xc7: // ifnonnull
 355  0 case 0xc8: // goto_w
 356  0 case 0xc9: // jsr_w
 357  3 append(" ").append(helper.getStart() + helper.getOffset()).append(" (");
 358  3 if (helper.getOffset() >= 0) {
 359  2 append("+");
 360    }
 361  3 append(helper.getOffset());
 362  3 append(")");
 363  3 break;
 364  8 default:
 365    // Do nothing
 366  8 break;
 367    }
 368    }
 369   
 370  11 private void appendValue(Instruction helper) {
 371  11 switch (helper.getOpcode()) {
 372  0 case 0x10: // bipush
 373  0 case 0x11: // sipush
 374  1 case 0x84: // iinc
 375  1 append(" ").append(helper.getValue());
 376  1 break;
 377  2 case 0xc4: // wide
 378  2 if (helper.getByte(1) == 0x84 /* iinc */) {
 379  1 append(" ").append(helper.getValue());
 380    }
 381  2 break;
 382  8 default:
 383    // Do nothing
 384  8 break;
 385    }
 386    }
 387    }