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
24 import org.apache.bcel.Const;
25
26
27
28
29
30
31
32
33 public final class ModuleProvides implements Cloneable, Node {
34
35 private final int providesIndex;
36 private final int providesWithCount;
37 private final int[] providesWithIndex;
38
39
40
41
42
43
44
45 ModuleProvides(final DataInput file) throws IOException {
46 providesIndex = file.readUnsignedShort();
47 providesWithCount = file.readUnsignedShort();
48 providesWithIndex = new int[providesWithCount];
49 for (int i = 0; i < providesWithCount; i++) {
50 providesWithIndex[i] = file.readUnsignedShort();
51 }
52 }
53
54
55
56
57
58
59
60 @Override
61 public void accept(final Visitor v) {
62 v.visitModuleProvides(this);
63 }
64
65
66
67
68
69
70 public ModuleProvides copy() {
71 try {
72 return (ModuleProvides) clone();
73 } catch (final CloneNotSupportedException e) {
74
75 }
76 return null;
77 }
78
79
80
81
82
83
84
85 public void dump(final DataOutputStream file) throws IOException {
86 file.writeShort(providesIndex);
87 file.writeShort(providesWithCount);
88 for (final int entry : providesWithIndex) {
89 file.writeShort(entry);
90 }
91 }
92
93
94
95
96 @Override
97 public String toString() {
98 return "provides(" + providesIndex + ", " + providesWithCount + ", ...)";
99 }
100
101
102
103
104 public String toString(final ConstantPool constantPool) {
105 final StringBuilder buf = new StringBuilder();
106 final String interfaceName = constantPool.constantToString(providesIndex, Const.CONSTANT_Class);
107 buf.append(Utility.compactClassName(interfaceName, false));
108 buf.append(", with(").append(providesWithCount).append("):\n");
109 for (final int index : providesWithIndex) {
110 final String className = constantPool.getConstantString(index, Const.CONSTANT_Class);
111 buf.append(" ").append(Utility.compactClassName(className, false)).append("\n");
112 }
113 return buf.substring(0, buf.length() - 1);
114 }
115 }