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 static String getToModuleNameAtIndex(final ConstantPool constantPool, final int index) {
36 return constantPool.getConstantString(index, Const.CONSTANT_Module);
37 }
38 private final int opensIndex;
39 private final int opensFlags;
40 private final int opensToCount;
41
42 private final int[] opensToIndex;
43
44
45
46
47
48
49
50 ModuleOpens(final DataInput file) throws IOException {
51 opensIndex = file.readUnsignedShort();
52 opensFlags = file.readUnsignedShort();
53 opensToCount = file.readUnsignedShort();
54 opensToIndex = new int[opensToCount];
55 for (int i = 0; i < opensToCount; i++) {
56 opensToIndex[i] = file.readUnsignedShort();
57 }
58 }
59
60
61
62
63
64
65
66 @Override
67 public void accept(final Visitor v) {
68 v.visitModuleOpens(this);
69 }
70
71
72
73
74 public ModuleOpens copy() {
75 try {
76 return (ModuleOpens) clone();
77 } catch (final CloneNotSupportedException e) {
78
79 }
80 return null;
81 }
82
83
84
85
86
87
88
89 public void dump(final DataOutputStream file) throws IOException {
90 file.writeShort(opensIndex);
91 file.writeShort(opensFlags);
92 file.writeShort(opensToCount);
93 for (final int entry : opensToIndex) {
94 file.writeShort(entry);
95 }
96 }
97
98
99
100
101
102
103 public int getOpensFlags() {
104 return opensFlags;
105 }
106
107
108
109
110
111
112
113 public String getPackageName(final ConstantPool constantPool) {
114 return constantPool.constantToString(opensIndex, Const.CONSTANT_Package);
115 }
116
117
118
119
120
121
122
123 public String[] getToModuleNames(final ConstantPool constantPool) {
124 final String[] toModuleNames = new String[opensToCount];
125 for (int i = 0; i < opensToCount; i++) {
126 toModuleNames[i] = getToModuleNameAtIndex(constantPool, opensToIndex[i]);
127 }
128 return toModuleNames;
129 }
130
131
132
133
134 @Override
135 public String toString() {
136 return "opens(" + opensIndex + ", " + opensFlags + ", " + opensToCount + ", ...)";
137 }
138
139
140
141
142 public String toString(final ConstantPool constantPool) {
143 final StringBuilder buf = new StringBuilder();
144 final String packageName = getPackageName(constantPool);
145 buf.append(packageName);
146 buf.append(", ").append(String.format("%04x", opensFlags));
147 buf.append(", to(").append(opensToCount).append("):\n");
148 for (final int index : opensToIndex) {
149 final String moduleName = getToModuleNameAtIndex(constantPool, index);
150 buf.append(" ").append(moduleName).append("\n");
151 }
152 return buf.substring(0, buf.length() - 1);
153 }
154 }