41 public class ModuleBuilder { |
41 public class ModuleBuilder { |
42 |
42 |
43 private final ToolBox tb; |
43 private final ToolBox tb; |
44 private final String name; |
44 private final String name; |
45 private String comment = ""; |
45 private String comment = ""; |
|
46 private boolean open; |
46 private List<String> requires = new ArrayList<>(); |
47 private List<String> requires = new ArrayList<>(); |
47 private List<String> exports = new ArrayList<>(); |
48 private List<String> exports = new ArrayList<>(); |
48 private List<String> opens = new ArrayList<>(); |
49 private List<String> opens = new ArrayList<>(); |
49 private List<String> uses = new ArrayList<>(); |
50 private List<String> uses = new ArrayList<>(); |
50 private List<String> provides = new ArrayList<>(); |
51 private List<String> provides = new ArrayList<>(); |
51 private List<String> content = new ArrayList<>(); |
52 private List<String> content = new ArrayList<>(); |
52 private Set<Path> modulePath = new LinkedHashSet<>(); |
53 private Set<Path> modulePath = new LinkedHashSet<>(); |
53 |
54 |
54 /** |
55 /** |
55 * Creates a builder for a module. |
56 * Creates a builder for a module. |
56 * @param tb a Toolbox that can be used to compile the module declaration. |
57 * @param tb a Toolbox that can be used to compile the module declaration |
57 * @param name the name of the module to be built |
58 * @param name the name of the module to be built |
58 */ |
59 */ |
59 public ModuleBuilder(ToolBox tb, String name) { |
60 public ModuleBuilder(ToolBox tb, String name) { |
|
61 this(tb, false, name); |
|
62 } |
|
63 |
|
64 /** |
|
65 * Creates a builder for a module. |
|
66 * @param tb a Toolbox that can be used to compile the module declaration |
|
67 * @param open whether or not this is an open module |
|
68 * @param name the name of the module to be built |
|
69 */ |
|
70 public ModuleBuilder(ToolBox tb, boolean open, String name) { |
60 this.tb = tb; |
71 this.tb = tb; |
|
72 this.open = open; |
61 this.name = name; |
73 this.name = name; |
62 } |
74 } |
63 |
75 |
64 /** |
76 /** |
65 * Sets the doc comment for the declaration. |
77 * Sets the doc comment for the declaration. |
211 StringBuilder sb = new StringBuilder(); |
223 StringBuilder sb = new StringBuilder(); |
212 if (!comment.isEmpty()) { |
224 if (!comment.isEmpty()) { |
213 sb.append("/**\n * ") |
225 sb.append("/**\n * ") |
214 .append(comment.replace("\n", "\n * ")) |
226 .append(comment.replace("\n", "\n * ")) |
215 .append("\n */\n"); |
227 .append("\n */\n"); |
|
228 } |
|
229 if (open) { |
|
230 sb.append("open "); |
216 } |
231 } |
217 sb.append("module ").append(name).append(" {\n"); |
232 sb.append("module ").append(name).append(" {\n"); |
218 requires.forEach(r -> sb.append(" " + r + "\n")); |
233 requires.forEach(r -> sb.append(" " + r + "\n")); |
219 exports.forEach(e -> sb.append(" " + e + "\n")); |
234 exports.forEach(e -> sb.append(" " + e + "\n")); |
220 opens.forEach(o -> sb.append(" " + o + "\n")); |
235 opens.forEach(o -> sb.append(" " + o + "\n")); |