1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.bcel.classfile;
21
22 import java.io.DataInput;
23 import java.io.DataOutputStream;
24 import java.io.IOException;
25
26 import org.apache.bcel.Const;
27
28
29
30
31
32
33
34
35 public final class ModuleExports implements Cloneable, Node {
36
37 private static String getToModuleNameAtIndex(final ConstantPool constantPool, final int index) {
38 return constantPool.getConstantString(index, Const.CONSTANT_Module);
39 }
40 private final int exportsIndex;
41 private final int exportsFlags;
42 private final int exportsToCount;
43
44 private final int[] exportsToIndex;
45
46
47
48
49
50
51
52 ModuleExports(final DataInput file) throws IOException {
53 exportsIndex = file.readUnsignedShort();
54 exportsFlags = file.readUnsignedShort();
55 exportsToCount = file.readUnsignedShort();
56 exportsToIndex = new int[exportsToCount];
57 for (int i = 0; i < exportsToCount; i++) {
58 exportsToIndex[i] = file.readUnsignedShort();
59 }
60 }
61
62
63
64
65
66
67
68 @Override
69 public void accept(final Visitor v) {
70 v.visitModuleExports(this);
71 }
72
73
74
75
76 public ModuleExports copy() {
77 try {
78 return (ModuleExports) clone();
79 } catch (final CloneNotSupportedException e) {
80
81 }
82 return null;
83 }
84
85
86
87
88
89
90
91 public void dump(final DataOutputStream file) throws IOException {
92 file.writeShort(exportsIndex);
93 file.writeShort(exportsFlags);
94 file.writeShort(exportsToCount);
95 for (final int entry : exportsToIndex) {
96 file.writeShort(entry);
97 }
98 }
99
100
101
102
103
104
105 public int getExportsFlags() {
106 return exportsFlags;
107 }
108
109
110
111
112
113
114
115 public String getPackageName(final ConstantPool constantPool) {
116 return constantPool.constantToString(exportsIndex, Const.CONSTANT_Package);
117 }
118
119
120
121
122
123
124
125 public String[] getToModuleNames(final ConstantPool constantPool) {
126 final String[] toModuleNames = new String[exportsToCount];
127 for (int i = 0; i < exportsToCount; i++) {
128 toModuleNames[i] = getToModuleNameAtIndex(constantPool, exportsToIndex[i]);
129 }
130 return toModuleNames;
131 }
132
133
134
135
136 @Override
137 public String toString() {
138 return "exports(" + exportsIndex + ", " + exportsFlags + ", " + exportsToCount + ", ...)";
139 }
140
141
142
143
144 public String toString(final ConstantPool constantPool) {
145 final StringBuilder buf = new StringBuilder();
146 final String packageName = getPackageName(constantPool);
147 buf.append(packageName);
148 buf.append(", ").append(String.format("%04x", exportsFlags));
149 buf.append(", to(").append(exportsToCount).append("):\n");
150 for (final int index : exportsToIndex) {
151 final String moduleName = getToModuleNameAtIndex(constantPool, index);
152 buf.append(" ").append(moduleName).append("\n");
153 }
154 return buf.substring(0, buf.length() - 1);
155 }
156 }