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 ModuleExports 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 exportsIndex;
39 private final int exportsFlags;
40 private final int exportsToCount;
41
42 private final int[] exportsToIndex;
43
44
45
46
47
48
49
50 ModuleExports(final DataInput file) throws IOException {
51 exportsIndex = file.readUnsignedShort();
52 exportsFlags = file.readUnsignedShort();
53 exportsToCount = file.readUnsignedShort();
54 exportsToIndex = new int[exportsToCount];
55 for (int i = 0; i < exportsToCount; i++) {
56 exportsToIndex[i] = file.readUnsignedShort();
57 }
58 }
59
60
61
62
63
64
65
66 @Override
67 public void accept(final Visitor v) {
68 v.visitModuleExports(this);
69 }
70
71
72
73
74 public ModuleExports copy() {
75 try {
76 return (ModuleExports) 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(exportsIndex);
91 file.writeShort(exportsFlags);
92 file.writeShort(exportsToCount);
93 for (final int entry : exportsToIndex) {
94 file.writeShort(entry);
95 }
96 }
97
98
99
100
101
102
103 public int getExportsFlags() {
104 return exportsFlags;
105 }
106
107
108
109
110
111
112
113 public String getPackageName(final ConstantPool constantPool) {
114 return constantPool.constantToString(exportsIndex, Const.CONSTANT_Package);
115 }
116
117
118
119
120
121
122
123 public String[] getToModuleNames(final ConstantPool constantPool) {
124 final String[] toModuleNames = new String[exportsToCount];
125 for (int i = 0; i < exportsToCount; i++) {
126 toModuleNames[i] = getToModuleNameAtIndex(constantPool, exportsToIndex[i]);
127 }
128 return toModuleNames;
129 }
130
131
132
133
134 @Override
135 public String toString() {
136 return "exports(" + exportsIndex + ", " + exportsFlags + ", " + exportsToCount + ", ...)";
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", exportsFlags));
147 buf.append(", to(").append(exportsToCount).append("):\n");
148 for (final int index : exportsToIndex) {
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 }