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 ModuleRequires implements Cloneable, Node {
36
37 private final int requiresIndex;
38 private final int requiresFlags;
39 private final int requiresVersionIndex;
40
41
42
43
44
45
46
47 ModuleRequires(final DataInput file) throws IOException {
48 requiresIndex = file.readUnsignedShort();
49 requiresFlags = file.readUnsignedShort();
50 requiresVersionIndex = file.readUnsignedShort();
51 }
52
53
54
55
56
57
58
59 @Override
60 public void accept(final Visitor v) {
61 v.visitModuleRequires(this);
62 }
63
64
65
66
67 public ModuleRequires copy() {
68 try {
69 return (ModuleRequires) clone();
70 } catch (final CloneNotSupportedException e) {
71
72 }
73 return null;
74 }
75
76
77
78
79
80
81
82 public void dump(final DataOutputStream file) throws IOException {
83 file.writeShort(requiresIndex);
84 file.writeShort(requiresFlags);
85 file.writeShort(requiresVersionIndex);
86 }
87
88
89
90
91
92
93
94 public String getModuleName(final ConstantPool constantPool) {
95 return constantPool.constantToString(requiresIndex, Const.CONSTANT_Module);
96 }
97
98
99
100
101
102
103 public int getRequiresFlags() {
104 return requiresFlags;
105 }
106
107
108
109
110
111
112
113 public String getVersion(final ConstantPool constantPool) {
114 return requiresVersionIndex == 0 ? "0" : constantPool.getConstantString(requiresVersionIndex, Const.CONSTANT_Utf8);
115 }
116
117
118
119
120 @Override
121 public String toString() {
122 return "requires(" + requiresIndex + ", " + String.format("%04x", requiresFlags) + ", " + requiresVersionIndex + ")";
123 }
124
125
126
127
128 public String toString(final ConstantPool constantPool) {
129 final StringBuilder buf = new StringBuilder();
130 final String moduleName = getModuleName(constantPool);
131 buf.append(moduleName);
132 buf.append(", ").append(String.format("%04x", requiresFlags));
133 final String version = getVersion(constantPool);
134 buf.append(", ").append(version);
135 return buf.toString();
136 }
137 }