Example usage for org.aspectj.apache.bcel.generic InstructionList iterator

List of usage examples for org.aspectj.apache.bcel.generic InstructionList iterator

Introduction

In this page you can find the example usage for org.aspectj.apache.bcel.generic InstructionList iterator.

Prototype

public Iterator iterator() 

Source Link

Usage

From source file:br.jabuti.metrics.klass.MetricAMZNMS.java

License:Open Source License

@Override
public double getResult(Program prog, String className) {
    double theValue = 0.0;
    RClass rc = prog.get(className);//w  ww  .  j ava2 s .  c  o  m
    if (!(rc instanceof RClassCode)) {
        return -1.0;
    }
    int cont = 0;
    RClassCode rcc = (RClassCode) rc;
    JavaClass theClazz = rcc.getTheClass();
    ConstantPoolGen cp = new ConstantPoolGen(theClazz.getConstantPool());
    Method[] methods = theClazz.getMethods();
    for (int i = 0; i < methods.length; i++) {
        if (methods[i].isAbstract()) {
            continue;
        }
        MethodGen mg = new MethodGen(methods[i], theClazz.getClassName(), cp);
        InstructionList instructions = mg.getInstructionList();
        Iterator<Instruction> instructionsIterator = instructions.iterator();
        while (instructionsIterator.hasNext()) {
            Instruction instruction = instructionsIterator.next();
            if (instruction instanceof InvokeInstruction) {
                theValue++;
            }
        }
        cont++;
    }
    if (cont == 0) {
        return -1.0;
    }
    return theValue / cont;
}