1 17 package org.apache.bcel.generic; 18 19 import java.util.StringTokenizer ; 20 import org.apache.bcel.Constants; 21 import org.apache.bcel.classfile.Constant; 22 import org.apache.bcel.classfile.ConstantPool; 23 24 30 public abstract class InvokeInstruction extends FieldOrMethod implements ExceptionThrower, 31 TypedInstruction, StackConsumer, StackProducer { 32 33 37 InvokeInstruction() { 38 } 39 40 41 44 protected InvokeInstruction(short opcode, int index) { 45 super(opcode, index); 46 } 47 48 49 52 public String toString( ConstantPool cp ) { 53 Constant c = cp.getConstant(index); 54 StringTokenizer tok = new StringTokenizer (cp.constantToString(c)); 55 return Constants.OPCODE_NAMES[opcode] + " " + tok.nextToken().replace('.', '/') 56 + tok.nextToken(); 57 } 58 59 60 65 public int consumeStack( ConstantPoolGen cpg ) { 66 String signature = getSignature(cpg); 67 Type[] args = Type.getArgumentTypes(signature); 68 int sum; 69 if (opcode == Constants.INVOKESTATIC) { 70 sum = 0; 71 } else { 72 sum = 1; } 74 int n = args.length; 75 for (int i = 0; i < n; i++) { 76 sum += args[i].getSize(); 77 } 78 return sum; 79 } 80 81 82 87 public int produceStack( ConstantPoolGen cpg ) { 88 return getReturnType(cpg).getSize(); 89 } 90 91 92 94 public Type getType( ConstantPoolGen cpg ) { 95 return getReturnType(cpg); 96 } 97 98 99 101 public String getMethodName( ConstantPoolGen cpg ) { 102 return getName(cpg); 103 } 104 105 106 108 public Type getReturnType( ConstantPoolGen cpg ) { 109 return Type.getReturnType(getSignature(cpg)); 110 } 111 112 113 115 public Type[] getArgumentTypes( ConstantPoolGen cpg ) { 116 return Type.getArgumentTypes(getSignature(cpg)); 117 } 118 } 119 | Popular Tags |