List of usage examples for org.aspectj.apache.bcel.generic InvokeInstruction getSignature
public String getSignature(ConstantPool cp)
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./*from w w w.ja va2 s . co 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]); }