Example usage for org.aspectj.apache.bcel.generic InvokeInstruction getMethodName

List of usage examples for org.aspectj.apache.bcel.generic InvokeInstruction getMethodName

Introduction

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

Prototype

public String getMethodName(ConstantPool cpg) 

Source Link

Usage

From source file:br.jabuti.graph.datastructure.dug.CFGCallNode.java

License:Open Source License

public CFGCallNode(CFGNode x, InstructionNode ins, ConstantPoolGen cp) {
    super(x);/*  w w w . j  a v  a  2s  .  co  m*/
    InvokeInstruction y = (InvokeInstruction) ins.ih.getInstruction();

    name = y.getMethodName(cp);
    Type[] vt = y.getArgumentTypes(cp);

    param = new String[vt.length];
    for (int i = 0; i < vt.length; i++) {
        param[i] = vt[i].getSignature();
    }

    if (y instanceof INVOKESTATIC || y instanceof INVOKESPECIAL) {
        classe = new String[1];
        classe[0] = y.getClassName(cp);
    } else {
        Vector vtype = new Vector();

        vt = ins.getStackAt(ins.argStackFrom);
        for (int i = 0; i < vt.length; i++) {
            String s = vt[i].getSignature();

            if (!vtype.contains(s)) {
                vtype.add(s);
            }
        }
        classe = (String[]) vtype.toArray(new String[0]);
    }

    specialMethod = NOTHING_SPECIAL;
    for (int i = 0; i < aspectVector.size(); i++) {
        String s = (String) aspectVector.elementAt(i);
        if (name.startsWith(s)) {
            specialMethod = ASPECT_METHOD;
            break;
        }
    }
}

From source file:br.jabuti.lookup.java.bytecode.RClassCode.java

License:Open Source License

/** Retorna uma lista de metodos chamados por um dado metodo
 * desta classe.// w  w  w  .  jav  a2 s .  c  o m
 * @param assinatura - a assinatura do metodo que se deseja analisar
 * @return a lista de metodos chamados pelo metodo passado como argumento.
 * Se o metodo solicitado nao for encontrado na classe, retorna null.
 */
public String[] getCalledMethods(String assinatura) {
    JavaClass jc = this.getTheClass();
    Method[] mv = jc.getMethods();
    Method m = null;
    String met = new String();
    int i;
    for (i = 0; i < mv.length; i++) {
        m = mv[i];

        met = jc.getClassName() + "." + mv[i].getName() + mv[i].getSignature();
        System.out.println("Metodo Aplicao = " + met);
        System.out.println("Metodo Parametro = " + assinatura);

        if (met.equals(assinatura))
            break;
    }
    if (i == mv.length)
        return null;
    ConstantPoolGen cp = new ConstantPoolGen(jc.getConstantPool());
    MethodGen mg = new MethodGen(m, jc.getClassName(), cp);

    InstructionList il = mg.getInstructionList();
    InstructionHandle[] ih = il.getInstructionHandles();
    Vector v = new Vector();

    for (int x = 0; x < ih.length; x++) {
        Instruction ins = ih[x].getInstruction();
        if (ins instanceof InvokeInstruction) {
            InvokeInstruction invoke = (InvokeInstruction) ins;
            String s = invoke.getClassName(cp) + "." + invoke.getMethodName(cp) + invoke.getSignature(cp);

            //System.out.println("gettype = " + invoke.getClassType(cp));
            System.out.println("metodo retornado = " + s);
            v.add(s);
        }
    }
    return (String[]) v.toArray(new String[0]);
}