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 import java.util.Iterator;
25 import java.util.stream.Stream;
26
27 import org.apache.bcel.Const;
28
29
30
31
32
33
34
35
36 public class MethodParameters extends Attribute implements Iterable<MethodParameter> {
37
38
39
40
41 private static final MethodParameter[] EMPTY_ARRAY = {};
42
43 private MethodParameter[] parameters = EMPTY_ARRAY;
44
45 MethodParameters(final int nameIndex, final int length, final DataInput input, final ConstantPool constantPool) throws IOException {
46 super(Const.ATTR_METHOD_PARAMETERS, nameIndex, length, constantPool);
47 final int parameterCount = input.readUnsignedByte();
48 parameters = new MethodParameter[parameterCount];
49 for (int i = 0; i < parameterCount; i++) {
50 parameters[i] = new MethodParameter(input);
51 }
52 }
53
54 @Override
55 public void accept(final Visitor v) {
56 v.visitMethodParameters(this);
57 }
58
59 @Override
60 public Attribute copy(final ConstantPool constantPool) {
61 final MethodParameters c = (MethodParameters) clone();
62 c.parameters = new MethodParameter[parameters.length];
63 Arrays.setAll(c.parameters, i -> parameters[i].copy());
64 c.setConstantPool(constantPool);
65 return c;
66 }
67
68
69
70
71
72
73
74 @Override
75 public void dump(final DataOutputStream file) throws IOException {
76 super.dump(file);
77 file.writeByte(parameters.length);
78 for (final MethodParameter parameter : parameters) {
79 parameter.dump(file);
80 }
81 }
82
83 public MethodParameter[] getParameters() {
84 return parameters;
85 }
86
87 @Override
88 public Iterator<MethodParameter> iterator() {
89 return Stream.of(parameters).iterator();
90 }
91
92 public void setParameters(final MethodParameter[] parameters) {
93 this.parameters = parameters != null ? parameters : EMPTY_ARRAY;
94 }
95 }