Coverage Report - com.jeantessier.classreader.FeatureDependencyCollector
 
Classes in this File Line Coverage Branch Coverage Complexity
FeatureDependencyCollector
0%
0/32
0%
0/23
3.143
 
 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 org.apache.oro.text.perl.*;
 36  
 
 37  0
 public class FeatureDependencyCollector extends CollectorBase {
 38  0
     private static final Perl5Util perl = new Perl5Util();
 39  
 
 40  
     private Class_info thisClass;
 41  
 
 42  
     public void visitClassfile(Classfile classfile) {
 43  0
         thisClass = classfile.getRawClass();
 44  
 
 45  0
         classfile.getConstantPool().accept(this);
 46  0
     }
 47  
 
 48  
     public void visitFieldRef_info(FieldRef_info entry) {
 49  0
         if (entry.getRawClass() != thisClass) {
 50  0
             add(entry.getClassName() + "." + entry.getRawNameAndType().getName());
 51  
         }
 52  0
     }
 53  
 
 54  
     public void visitMethodRef_info(MethodRef_info entry) {
 55  0
         if ((entry.getRawClass() != thisClass) && !perl.match("/<.*init>/", entry.getRawNameAndType().getName())) {
 56  0
             add(entry.getClassName() + "." + entry.getRawNameAndType().getName());
 57  
         }
 58  0
     }
 59  
 
 60  
     public void visitInterfaceMethodRef_info(InterfaceMethodRef_info entry) {
 61  0
         if (entry.getRawClass() != thisClass) {
 62  0
             add(entry.getClassName() + "." + entry.getRawNameAndType().getName());
 63  
         }
 64  0
     }
 65  
 
 66  
     public void visitMethod_info(Method_info entry) {
 67  0
         processSignature(entry.getDescriptor());
 68  
     
 69  0
         super.visitMethod_info(entry);
 70  0
     }
 71  
 
 72  
     public void visitInstruction(Instruction helper) {
 73  0
         switch (helper.getOpcode()) {
 74  
             case 0xb2: // getstatic
 75  
             case 0xb3: // putstatic
 76  
             case 0xb4: // getfield
 77  
             case 0xb5: // putfield
 78  
             case 0xb6: // invokevirtual
 79  
             case 0xb7: // invokespecial
 80  
             case 0xb8: // invokestatic
 81  
             case 0xb9: // invokeinterface
 82  0
                 helper.getIndexedConstantPoolEntry().accept(this);
 83  0
                 break;
 84  
             default:
 85  
                 // Do nothing
 86  
                 break;
 87  
         }
 88  
 
 89  0
         super.visitInstruction(helper);
 90  0
     }
 91  
 
 92  
     private void processSignature(String str) {
 93  0
         int currentPos = 0;
 94  
         int startPos;
 95  
         int endPos;
 96  
 
 97  0
         while ((startPos = str.indexOf('L', currentPos)) != -1) {
 98  0
             if ((endPos = str.indexOf(';', startPos)) != -1) {
 99  0
                 String candidate = str.substring(startPos + 1, endPos);
 100  0
                 if (!thisClass.getName().equals(candidate)) {
 101  0
                     add(ClassNameHelper.path2ClassName(candidate));
 102  
                 }
 103  0
                 currentPos = endPos + 1;
 104  0
             } else {
 105  0
                 currentPos = startPos + 1;
 106  
             }
 107  
         }
 108  0
     }
 109  
 }