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