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 ModuleOpens implements Cloneable, Node {
34
35 private final int opensIndex;
36 private final int opensFlags;
37 private final int opensToCount;
38 private final int[] opensToIndex;
39
40
41
42
43
44
45
46 ModuleOpens(final DataInput file) throws IOException {
47 opensIndex = file.readUnsignedShort();
48 opensFlags = file.readUnsignedShort();
49 opensToCount = file.readUnsignedShort();
50 opensToIndex = new int[opensToCount];
51 for (int i = 0; i < opensToCount; i++) {
52 opensToIndex[i] = file.readUnsignedShort();
53 }
54 }
55
56
57
58
59
60
61
62 @Override
63 public void accept(final Visitor v) {
64 v.visitModuleOpens(this);
65 }
66
67
68
69
70
71
72 public ModuleOpens copy() {
73 try {
74 return (ModuleOpens) clone();
75 } catch (final CloneNotSupportedException e) {
76
77 }
78 return null;
79 }
80
81
82
83
84
85
86
87 public void dump(final DataOutputStream file) throws IOException {
88 file.writeShort(opensIndex);
89 file.writeShort(opensFlags);
90 file.writeShort(opensToCount);
91 for (final int entry : opensToIndex) {
92 file.writeShort(entry);
93 }
94 }
95
96
97
98
99 @Override
100 public String toString() {
101 return "opens(" + opensIndex + ", " + opensFlags + ", " + opensToCount + ", ...)";
102 }
103
104
105
106
107 public String toString(final ConstantPool constantPool) {
108 final StringBuilder buf = new StringBuilder();
109 final String packageName = constantPool.constantToString(opensIndex, Const.CONSTANT_Package);
110 buf.append(Utility.compactClassName(packageName, false));
111 buf.append(", ").append(String.format("%04x", opensFlags));
112 buf.append(", to(").append(opensToCount).append("):\n");
113 for (final int index : opensToIndex) {
114 final String moduleName = constantPool.getConstantString(index, Const.CONSTANT_Module);
115 buf.append(" ").append(Utility.compactClassName(moduleName, false)).append("\n");
116 }
117 return buf.substring(0, buf.length() - 1);
118 }
119 }