1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21
22 import org.apache.bcel.Const;
23 import org.apache.bcel.ExceptionConst;
24 import org.apache.bcel.classfile.ConstantPool;
25 import org.apache.bcel.util.ByteSequence;
26
27
28
29
30
31
32
33
34
35
36
37 public final class INVOKEINTERFACE extends InvokeInstruction {
38
39 private int nargs;
40
41
42
43
44 INVOKEINTERFACE() {
45 }
46
47 public INVOKEINTERFACE(final int index, final int nargs) {
48 super(Const.INVOKEINTERFACE, index);
49 super.setLength(5);
50 if (nargs < 1) {
51 throw new ClassGenException("Number of arguments must be > 0 " + nargs);
52 }
53 this.nargs = nargs;
54 }
55
56
57
58
59
60
61
62 @Override
63 public void accept(final Visitor v) {
64 v.visitExceptionThrower(this);
65 v.visitTypedInstruction(this);
66 v.visitStackConsumer(this);
67 v.visitStackProducer(this);
68 v.visitLoadClass(this);
69 v.visitCPInstruction(this);
70 v.visitFieldOrMethod(this);
71 v.visitInvokeInstruction(this);
72 v.visitINVOKEINTERFACE(this);
73 }
74
75 @Override
76 public int consumeStack(final ConstantPoolGen cpg) {
77 return nargs;
78 }
79
80
81
82
83
84
85 @Override
86 public void dump(final DataOutputStream out) throws IOException {
87 out.writeByte(super.getOpcode());
88 out.writeShort(super.getIndex());
89 out.writeByte(nargs);
90 out.writeByte(0);
91 }
92
93
94
95
96 public int getCount() {
97 return nargs;
98 }
99
100 @Override
101 public Class<?>[] getExceptions() {
102 return ExceptionConst.createExceptions(ExceptionConst.EXCS.EXCS_INTERFACE_METHOD_RESOLUTION, ExceptionConst.UNSATISFIED_LINK_ERROR,
103 ExceptionConst.ABSTRACT_METHOD_ERROR, ExceptionConst.ILLEGAL_ACCESS_ERROR, ExceptionConst.INCOMPATIBLE_CLASS_CHANGE_ERROR);
104 }
105
106
107
108
109 @Override
110 protected void initFromFile(final ByteSequence bytes, final boolean wide) throws IOException {
111 super.initFromFile(bytes, wide);
112 super.setLength(5);
113 nargs = bytes.readUnsignedByte();
114 bytes.readByte();
115 }
116
117
118
119
120 @Override
121 public String toString(final ConstantPool cp) {
122 return super.toString(cp) + " " + nargs;
123 }
124 }