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
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 @Override
92 public String toString() {
93 return "requires(" + requiresIndex + ", " + String.format("%04x", requiresFlags) + ", " + requiresVersionIndex + ")";
94 }
95
96
97
98
99 public String toString(final ConstantPool constantPool) {
100 final StringBuilder buf = new StringBuilder();
101 final String moduleName = constantPool.constantToString(requiresIndex, Const.CONSTANT_Module);
102 buf.append(Utility.compactClassName(moduleName, false));
103 buf.append(", ").append(String.format("%04x", requiresFlags));
104 final String version = requiresVersionIndex == 0 ? "0" : constantPool.getConstantString(requiresVersionIndex, Const.CONSTANT_Utf8);
105 buf.append(", ").append(version);
106 return buf.toString();
107 }
108 }