1 17 package org.apache.bcel.generic; 18 19 import java.io.DataOutputStream ; 20 import java.io.IOException ; 21 import org.apache.bcel.Constants; 22 import org.apache.bcel.ExceptionConstants; 23 import org.apache.bcel.classfile.ConstantPool; 24 import org.apache.bcel.util.ByteSequence; 25 26 33 public final class INVOKEINTERFACE extends InvokeInstruction { 34 35 private int nargs; 37 38 42 INVOKEINTERFACE() { 43 } 44 45 46 public INVOKEINTERFACE(int index, int nargs) { 47 super(Constants.INVOKEINTERFACE, index); 48 length = 5; 49 if (nargs < 1) { 50 throw new ClassGenException("Number of arguments must be > 0 " + nargs); 51 } 52 this.nargs = nargs; 53 } 54 55 56 60 public void dump( DataOutputStream out ) throws IOException { 61 out.writeByte(opcode); 62 out.writeShort(index); 63 out.writeByte(nargs); 64 out.writeByte(0); 65 } 66 67 68 72 public int getCount() { 73 return nargs; 74 } 75 76 77 80 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException { 81 super.initFromFile(bytes, wide); 82 length = 5; 83 nargs = bytes.readUnsignedByte(); 84 bytes.readByte(); } 86 87 88 91 public String toString( ConstantPool cp ) { 92 return super.toString(cp) + " " + nargs; 93 } 94 95 96 public int consumeStack( ConstantPoolGen cpg ) { return nargs; } 99 100 101 public Class [] getExceptions() { 102 Class [] cs = new Class [4 + ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length]; 103 System.arraycopy(ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION, 0, cs, 0, 104 ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length); 105 cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length + 3] = ExceptionConstants.INCOMPATIBLE_CLASS_CHANGE_ERROR; 106 cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length + 2] = ExceptionConstants.ILLEGAL_ACCESS_ERROR; 107 cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length + 1] = ExceptionConstants.ABSTRACT_METHOD_ERROR; 108 cs[ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION.length] = ExceptionConstants.UNSATISFIED_LINK_ERROR; 109 return cs; 110 } 111 112 113 121 public void accept( Visitor v ) { 122 v.visitExceptionThrower(this); 123 v.visitTypedInstruction(this); 124 v.visitStackConsumer(this); 125 v.visitStackProducer(this); 126 v.visitLoadClass(this); 127 v.visitCPInstruction(this); 128 v.visitFieldOrMethod(this); 129 v.visitInvokeInstruction(this); 130 v.visitINVOKEINTERFACE(this); 131 } 132 } 133 | Popular Tags |