1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.bcel.classfile;
19
20 import java.io.DataInput;
21 import java.io.DataOutputStream;
22 import java.io.IOException;
23 import java.util.Arrays;
24
25 import org.apache.bcel.Const;
26
27
28
29
30
31
32
33
34
35 public class BootstrapMethod implements Cloneable {
36
37
38 private int bootstrapMethodRef;
39
40
41 private int[] bootstrapArguments;
42
43
44
45
46
47
48 public BootstrapMethod(final BootstrapMethod c) {
49 this(c.getBootstrapMethodRef(), c.getBootstrapArguments());
50 }
51
52
53
54
55
56
57
58 BootstrapMethod(final DataInput input) throws IOException {
59 this(input.readUnsignedShort(), input.readUnsignedShort());
60
61 for (int i = 0; i < bootstrapArguments.length; i++) {
62 bootstrapArguments[i] = input.readUnsignedShort();
63 }
64 }
65
66
67 private BootstrapMethod(final int bootstrapMethodRef, final int numBootstrapArguments) {
68 this(bootstrapMethodRef, new int[numBootstrapArguments]);
69 }
70
71
72
73
74
75 public BootstrapMethod(final int bootstrapMethodRef, final int[] bootstrapArguments) {
76 this.bootstrapMethodRef = bootstrapMethodRef;
77 this.bootstrapArguments = bootstrapArguments;
78 }
79
80
81
82
83 public BootstrapMethod copy() {
84 try {
85 return (BootstrapMethod) clone();
86 } catch (final CloneNotSupportedException e) {
87
88 }
89 return null;
90 }
91
92
93
94
95
96
97
98 public final void dump(final DataOutputStream file) throws IOException {
99 file.writeShort(bootstrapMethodRef);
100 file.writeShort(bootstrapArguments.length);
101 for (final int bootstrapArgument : bootstrapArguments) {
102 file.writeShort(bootstrapArgument);
103 }
104 }
105
106
107
108
109 public int[] getBootstrapArguments() {
110 return bootstrapArguments;
111 }
112
113
114
115
116 public int getBootstrapMethodRef() {
117 return bootstrapMethodRef;
118 }
119
120
121
122
123 public int getNumBootstrapArguments() {
124 return bootstrapArguments.length;
125 }
126
127
128
129
130 public void setBootstrapArguments(final int[] bootstrapArguments) {
131 this.bootstrapArguments = bootstrapArguments;
132 }
133
134
135
136
137 public void setBootstrapMethodRef(final int bootstrapMethodRef) {
138 this.bootstrapMethodRef = bootstrapMethodRef;
139 }
140
141
142
143
144 @Override
145 public final String toString() {
146 return "BootstrapMethod(" + bootstrapMethodRef + ", " + bootstrapArguments.length + ", " + Arrays.toString(bootstrapArguments) + ")";
147 }
148
149
150
151
152 public final String toString(final ConstantPool constantPool) {
153 final StringBuilder buf = new StringBuilder();
154 final String bootstrapMethodName = constantPool.constantToString(bootstrapMethodRef, Const.CONSTANT_MethodHandle);
155 buf.append(Utility.compactClassName(bootstrapMethodName, false));
156 final int bootstrapArgumentsLen = bootstrapArguments.length;
157 if (bootstrapArgumentsLen > 0) {
158 buf.append("\nMethod Arguments:");
159 for (int i = 0; i < bootstrapArgumentsLen; i++) {
160 buf.append("\n ").append(i).append(": ");
161 buf.append(constantPool.constantToString(constantPool.getConstant(bootstrapArguments[i])));
162 }
163 }
164 return buf.toString();
165 }
166 }