Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 483   Methods: 62
NCLOC: 356   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MetricsGatherer.java 0% 0% 0% 0%
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.util.*;
 36   
 37    import org.apache.log4j.*;
 38   
 39    public class MetricsGatherer extends VisitorBase {
 40    private Collection<Object> classes = new LinkedList<Object>();
 41    private Collection<Object> interfaces = new LinkedList<Object>();
 42    private Collection<Method_info> methods = new LinkedList<Method_info>();
 43    private Collection<Field_info> fields = new LinkedList<Field_info>();
 44    private Collection<Classfile> syntheticClasses = new LinkedList<Classfile>();
 45    private Collection<Field_info> syntheticFields = new LinkedList<Field_info>();
 46    private Collection<Method_info> syntheticMethods = new LinkedList<Method_info>();
 47    private Collection<Classfile> deprecatedClasses = new LinkedList<Classfile>();
 48    private Collection<Field_info> deprecatedFields = new LinkedList<Field_info>();
 49    private Collection<Method_info> deprecatedMethods = new LinkedList<Method_info>();
 50    private Collection<Classfile> publicClasses = new LinkedList<Classfile>();
 51    private Collection<Field_info> publicFields = new LinkedList<Field_info>();
 52    private Collection<Method_info> publicMethods = new LinkedList<Method_info>();
 53    private Collection<InnerClass> publicInnerClasses = new LinkedList<InnerClass>();
 54    private Collection<Field_info> protectedFields = new LinkedList<Field_info>();
 55    private Collection<Method_info> protectedMethods = new LinkedList<Method_info>();
 56    private Collection<InnerClass> protectedInnerClasses = new LinkedList<InnerClass>();
 57    private Collection<Field_info> privateFields = new LinkedList<Field_info>();
 58    private Collection<Method_info> privateMethods = new LinkedList<Method_info>();
 59    private Collection<InnerClass> privateInnerClasses = new LinkedList<InnerClass>();
 60    private Collection<Classfile> packageClasses = new LinkedList<Classfile>();
 61    private Collection<Field_info> packageFields = new LinkedList<Field_info>();
 62    private Collection<Method_info> packageMethods = new LinkedList<Method_info>();
 63    private Collection<InnerClass> packageInnerClasses = new LinkedList<InnerClass>();
 64    private Collection<Classfile> abstractClasses = new LinkedList<Classfile>();
 65    private Collection<Method_info> abstractMethods = new LinkedList<Method_info>();
 66    private Collection<InnerClass> abstractInnerClasses = new LinkedList<InnerClass>();
 67    private Collection<Field_info> staticFields = new LinkedList<Field_info>();
 68    private Collection<Method_info> staticMethods = new LinkedList<Method_info>();
 69    private Collection<InnerClass> staticInnerClasses = new LinkedList<InnerClass>();
 70    private Collection<Classfile> finalClasses = new LinkedList<Classfile>();
 71    private Collection<Field_info> finalFields = new LinkedList<Field_info>();
 72    private Collection<Method_info> finalMethods = new LinkedList<Method_info>();
 73    private Collection<InnerClass> finalInnerClasses = new LinkedList<InnerClass>();
 74    private Collection<Method_info> synchronizedMethods = new LinkedList<Method_info>();
 75    private Collection<Method_info> nativeMethods = new LinkedList<Method_info>();
 76    private Collection<Field_info> volatileFields = new LinkedList<Field_info>();
 77    private Collection<Field_info> transientFields = new LinkedList<Field_info>();
 78    private Map<String, Long> attributeCounts = new HashMap<String, Long>();
 79    private Collection<Custom_attribute> customAttributes = new LinkedList<Custom_attribute>();
 80    private long[] instructionCounts = new long[256];
 81   
 82  0 public MetricsGatherer() {
 83  0 for (AttributeType attributeType : AttributeType.values()) {
 84  0 attributeCounts.put(attributeType.getAttributeName(), 0L);
 85    }
 86  0 attributeCounts.put("custom", 0L);
 87    }
 88   
 89  0 public Collection<Object> getClasses() {
 90  0 return classes;
 91    }
 92   
 93  0 public Collection<Object> getInterfaces() {
 94  0 return interfaces;
 95    }
 96   
 97  0 public Collection<Method_info> getMethods() {
 98  0 return methods;
 99    }
 100   
 101  0 public Collection<Field_info> getFields() {
 102  0 return fields;
 103    }
 104   
 105  0 public Collection<Classfile> getSyntheticClasses() {
 106  0 return syntheticClasses;
 107    }
 108   
 109  0 public Collection<Field_info> getSyntheticFields() {
 110  0 return syntheticFields;
 111    }
 112   
 113  0 public Collection<Method_info> getSyntheticMethods() {
 114  0 return syntheticMethods;
 115    }
 116   
 117  0 public Collection<Classfile> getDeprecatedClasses() {
 118  0 return deprecatedClasses;
 119    }
 120   
 121  0 public Collection<Field_info> getDeprecatedFields() {
 122  0 return deprecatedFields;
 123    }
 124   
 125  0 public Collection<Method_info> getDeprecatedMethods() {
 126  0 return deprecatedMethods;
 127    }
 128   
 129  0 public Collection<Classfile> getPublicClasses() {
 130  0 return publicClasses;
 131    }
 132   
 133  0 public Collection<Field_info> getPublicFields() {
 134  0 return publicFields;
 135    }
 136   
 137  0 public Collection<Method_info> getPublicMethods() {
 138  0 return publicMethods;
 139    }
 140   
 141  0 public Collection<InnerClass> getPublicInnerClasses() {
 142  0 return publicInnerClasses;
 143    }
 144   
 145  0 public Collection<Field_info> getProtectedFields() {
 146  0 return protectedFields;
 147    }
 148   
 149  0 public Collection<Method_info> getProtectedMethods() {
 150  0 return protectedMethods;
 151    }
 152   
 153  0 public Collection<InnerClass> getProtectedInnerClasses() {
 154  0 return protectedInnerClasses;
 155    }
 156   
 157  0 public Collection<Field_info> getPrivateFields() {
 158  0 return privateFields;
 159    }
 160   
 161  0 public Collection<Method_info> getPrivateMethods() {
 162  0 return privateMethods;
 163    }
 164   
 165  0 public Collection<InnerClass> getPrivateInnerClasses() {
 166  0 return privateInnerClasses;
 167    }
 168   
 169  0 public Collection<Classfile> getPackageClasses() {
 170  0 return packageClasses;
 171    }
 172   
 173  0 public Collection<Field_info> getPackageFields() {
 174  0 return packageFields;
 175    }
 176   
 177  0 public Collection<Method_info> getPackageMethods() {
 178  0 return packageMethods;
 179    }
 180   
 181  0 public Collection<InnerClass> getPackageInnerClasses() {
 182  0 return packageInnerClasses;
 183    }
 184   
 185  0 public Collection<Classfile> getAbstractClasses() {
 186  0 return abstractClasses;
 187    }
 188   
 189  0 public Collection<Method_info> getAbstractMethods() {
 190  0 return abstractMethods;
 191    }
 192   
 193  0 public Collection<InnerClass> getAbstractInnerClasses() {
 194  0 return abstractInnerClasses;
 195    }
 196   
 197  0 public Collection<Field_info> getStaticFields() {
 198  0 return staticFields;
 199    }
 200   
 201  0 public Collection<Method_info> getStaticMethods() {
 202  0 return staticMethods;
 203    }
 204   
 205  0 public Collection<InnerClass> getStaticInnerClasses() {
 206  0 return staticInnerClasses;
 207    }
 208   
 209  0 public Collection<Classfile> getFinalClasses() {
 210  0 return finalClasses;
 211    }
 212   
 213  0 public Collection<Field_info> getFinalFields() {
 214  0 return finalFields;
 215    }
 216   
 217  0 public Collection<Method_info> getFinalMethods() {
 218  0 return finalMethods;
 219    }
 220   
 221  0 public Collection<InnerClass> getFinalInnerClasses() {
 222  0 return finalInnerClasses;
 223    }
 224   
 225  0 public Collection<Method_info> getSynchronizedMethods() {
 226  0 return synchronizedMethods;
 227    }
 228   
 229  0 public Collection<Method_info> getNativeMethods() {
 230  0 return nativeMethods;
 231    }
 232   
 233  0 public Collection<Field_info> getVolatileFields() {
 234  0 return volatileFields;
 235    }
 236   
 237  0 public Collection<Field_info> getTransientFields() {
 238  0 return transientFields;
 239    }
 240   
 241  0 public Map<String, Long> getAttributeCounts() {
 242  0 return attributeCounts;
 243    }
 244   
 245  0 public Collection<Custom_attribute> getCustomAttributes() {
 246  0 return customAttributes;
 247    }
 248   
 249  0 public long[] getInstructionCounts() {
 250  0 return instructionCounts;
 251    }
 252   
 253    // Classfile
 254  0 public void visitClassfile(Classfile classfile) {
 255  0 if (classfile.isPublic()) {
 256  0 publicClasses.add(classfile);
 257    } else {
 258  0 packageClasses.add(classfile);
 259    }
 260   
 261  0 if (classfile.isFinal()) {
 262  0 finalClasses.add(classfile);
 263    }
 264   
 265  0 if (classfile.isInterface()) {
 266  0 interfaces.add(classfile);
 267    } else {
 268  0 classes.add(classfile);
 269    }
 270   
 271  0 if (classfile.isAbstract()) {
 272  0 abstractClasses.add(classfile);
 273    }
 274   
 275  0 super.visitClassfile(classfile);
 276    }
 277   
 278    // Features
 279  0 public void visitField_info(Field_info entry) {
 280  0 fields.add(entry);
 281   
 282  0 if (entry.isPublic()) {
 283  0 publicFields.add(entry);
 284  0 } else if (entry.isPrivate()) {
 285  0 privateFields.add(entry);
 286  0 } else if (entry.isProtected()) {
 287  0 protectedFields.add(entry);
 288    } else {
 289  0 packageFields.add(entry);
 290    }
 291   
 292  0 if (entry.isStatic()) {
 293  0 staticFields.add(entry);
 294    }
 295   
 296  0 if (entry.isFinal()) {
 297  0 finalFields.add(entry);
 298    }
 299   
 300  0 if (entry.isVolatile()) {
 301  0 volatileFields.add(entry);
 302    }
 303   
 304  0 if (entry.isTransient()) {
 305  0 transientFields.add(entry);
 306    }
 307   
 308  0 super.visitField_info(entry);
 309    }
 310   
 311  0 public void visitMethod_info(Method_info entry) {
 312  0 methods.add(entry);
 313   
 314  0 if (entry.isPublic()) {
 315  0 publicMethods.add(entry);
 316  0 } else if (entry.isPrivate()) {
 317  0 privateMethods.add(entry);
 318  0 } else if (entry.isProtected()) {
 319  0 protectedMethods.add(entry);
 320    } else {
 321  0 packageMethods.add(entry);
 322    }
 323   
 324  0 if (entry.isStatic()) {
 325  0 staticMethods.add(entry);
 326    }
 327   
 328  0 if (entry.isFinal()) {
 329  0 finalMethods.add(entry);
 330    }
 331   
 332  0 if (entry.isSynchronized()) {
 333  0 synchronizedMethods.add(entry);
 334    }
 335   
 336  0 if (entry.isNative()) {
 337  0 nativeMethods.add(entry);
 338    }
 339   
 340  0 if (entry.isAbstract()) {
 341  0 abstractMethods.add(entry);
 342    }
 343   
 344  0 super.visitMethod_info(entry);
 345    }
 346   
 347    // Attributes
 348  0 public void visitConstantValue_attribute(ConstantValue_attribute attribute) {
 349  0 super.visitConstantValue_attribute(attribute);
 350  0 visitAttribute("ConstantValue");
 351    }
 352   
 353  0 public void visitCode_attribute(Code_attribute attribute) {
 354  0 super.visitCode_attribute(attribute);
 355  0 visitAttribute("Code");
 356    }
 357   
 358  0 public void visitExceptions_attribute(Exceptions_attribute attribute) {
 359  0 super.visitExceptions_attribute(attribute);
 360  0 visitAttribute("Exceptions");
 361    }
 362   
 363  0 public void visitInnerClasses_attribute(InnerClasses_attribute attribute) {
 364  0 super.visitInnerClasses_attribute(attribute);
 365  0 visitAttribute("InnerClasses");
 366    }
 367   
 368  0 public void visitEnclosingMethod_attribute(EnclosingMethod_attribute attribute) {
 369  0 super.visitEnclosingMethod_attribute(attribute);
 370  0 visitAttribute("EnclosingMethod");
 371    }
 372   
 373  0 public void visitSynthetic_attribute(Synthetic_attribute attribute) {
 374  0 super.visitSynthetic_attribute(attribute);
 375  0 visitAttribute("Synthetic");
 376   
 377  0 Object owner = attribute.getOwner();
 378   
 379  0 if (owner instanceof Classfile) {
 380  0 syntheticClasses.add((Classfile) owner);
 381  0 } else if (owner instanceof Field_info) {
 382  0 syntheticFields.add((Field_info) owner);
 383  0 } else if (owner instanceof Method_info) {
 384  0 syntheticMethods.add((Method_info) owner);
 385    } else {
 386  0 Logger.getLogger(getClass()).warn("Synthetic attribute on unknown Visitable: " + owner.getClass().getName());
 387    }
 388    }
 389   
 390  0 public void visitSignature_attribute(Signature_attribute attribute) {
 391  0 super.visitSignature_attribute(attribute);
 392  0 visitAttribute("Signature");
 393    }
 394   
 395  0 public void visitSourceFile_attribute(SourceFile_attribute attribute) {
 396  0 super.visitSourceFile_attribute(attribute);
 397  0 visitAttribute("SourceFile");
 398    }
 399   
 400  0 public void visitSourceDebugExtension_attribute(SourceDebugExtension_attribute attribute) {
 401  0 super.visitSourceDebugExtension_attribute(attribute);
 402  0 visitAttribute("SourceDebugExtension");
 403    }
 404   
 405  0 public void visitLineNumberTable_attribute(LineNumberTable_attribute attribute) {
 406  0 super.visitLineNumberTable_attribute(attribute);
 407  0 visitAttribute("LineNumberTable");
 408    }
 409   
 410  0 public void visitLocalVariableTable_attribute(LocalVariableTable_attribute attribute) {
 411  0 super.visitLocalVariableTable_attribute(attribute);
 412  0 visitAttribute("LocalVariableTable");
 413    }
 414   
 415  0 public void visitLocalVariableType(LocalVariableType helper) {
 416  0 super.visitLocalVariableType(helper);
 417  0 visitAttribute("LocalVariableTypeTable");
 418    }
 419   
 420  0 public void visitDeprecated_attribute(Deprecated_attribute attribute) {
 421  0 super.visitDeprecated_attribute(attribute);
 422  0 visitAttribute("Deprecated");
 423   
 424  0 Object owner = attribute.getOwner();
 425   
 426  0 if (owner instanceof Classfile) {
 427  0 deprecatedClasses.add((Classfile) owner);
 428  0 } else if (owner instanceof Field_info) {
 429  0 deprecatedFields.add((Field_info) owner);
 430  0 } else if (owner instanceof Method_info) {
 431  0 deprecatedMethods.add((Method_info) owner);
 432    } else {
 433  0 Logger.getLogger(getClass()).warn("Deprecated attribute on unknown Visitable: " + owner.getClass().getName());
 434    }
 435    }
 436   
 437  0 public void visitCustom_attribute(Custom_attribute attribute) {
 438  0 super.visitCustom_attribute(attribute);
 439  0 visitAttribute("custom");
 440  0 customAttributes.add(attribute);
 441    }
 442   
 443  0 private void visitAttribute(String attributeName) {
 444  0 attributeCounts.put(attributeName, attributeCounts.get(attributeName) + 1);
 445    }
 446   
 447    // Attribute helpers
 448  0 public void visitInstruction(Instruction helper) {
 449  0 getInstructionCounts()[helper.getOpcode()]++;
 450   
 451  0 super.visitInstruction(helper);
 452    }
 453   
 454  0 public void visitInnerClass(InnerClass helper) {
 455  0 if (helper.isPublic()) {
 456  0 publicInnerClasses.add(helper);
 457  0 } else if (helper.isPrivate()) {
 458  0 privateInnerClasses.add(helper);
 459  0 } else if (helper.isProtected()) {
 460  0 protectedInnerClasses.add(helper);
 461    } else {
 462  0 packageInnerClasses.add(helper);
 463    }
 464   
 465  0 if (helper.isStatic()) {
 466  0 staticInnerClasses.add(helper);
 467    }
 468   
 469  0 if (helper.isFinal()) {
 470  0 finalInnerClasses.add(helper);
 471    }
 472   
 473  0 if (helper.isInterface()) {
 474  0 interfaces.add(helper);
 475    } else {
 476  0 classes.add(helper);
 477    }
 478   
 479  0 if (helper.isAbstract()) {
 480  0 abstractInnerClasses.add(helper);
 481    }
 482    }
 483    }