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