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