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_METHOD_PARAMETER_ARRAY = {};
42
43 private MethodParameter[] parameters = EMPTY_METHOD_PARAMETER_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
48 final int parameterCount = input.readUnsignedByte();
49 parameters = new MethodParameter[parameterCount];
50 for (int i = 0; i < parameterCount; i++) {
51 parameters[i] = new MethodParameter(input);
52 }
53 }
54
55 @Override
56 public void accept(final Visitor v) {
57 v.visitMethodParameters(this);
58 }
59
60 @Override
61 public Attribute copy(final ConstantPool constantPool) {
62 final MethodParameters c = (MethodParameters) clone();
63 c.parameters = new MethodParameter[parameters.length];
64
65 Arrays.setAll(c.parameters, i -> parameters[i].copy());
66 c.setConstantPool(constantPool);
67 return c;
68 }
69
70
71
72
73
74
75
76 @Override
77 public void dump(final DataOutputStream file) throws IOException {
78 super.dump(file);
79 file.writeByte(parameters.length);
80 for (final MethodParameter parameter : parameters) {
81 parameter.dump(file);
82 }
83 }
84
85 public MethodParameter[] getParameters() {
86 return parameters;
87 }
88
89 @Override
90 public Iterator<MethodParameter> iterator() {
91 return Stream.of(parameters).iterator();
92 }
93
94 public void setParameters(final MethodParameter[] parameters) {
95 this.parameters = parameters;
96 }
97 }