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