1
1
package io .avaje .prism .internal ;
2
2
3
3
import java .io .PrintWriter ;
4
+ import java .util .regex .Pattern ;
4
5
5
6
public class ModuleInfoReaderWriter {
6
7
private ModuleInfoReaderWriter () {}
@@ -38,6 +39,9 @@ public static void write(PrintWriter out, String packageName) {
38
39
+ "\n "
39
40
+ " private static final String SPLIT_PATTERN = \" \\ \\ s*,\\ \\ s*\" ;\n "
40
41
+ " private static final Pattern IMPORT_PATTERN = Pattern.compile(\" import\\ \\ s+([\\ \\ w.$]+);\" );\n "
42
+ + "\n "
43
+ + " private static final Pattern COMMENT_PATTERN = Pattern.compile(\" (/.*)|(\\ \\ *.*)\" );\n "
44
+ + "\n "
41
45
+ " private static final Pattern REQUIRES_PATTERN =\n "
42
46
+ " Pattern.compile(\" requires\\ \\ s+(transitive\\ \\ s+)?(static\\ \\ s+)?([\\ \\ w.$]+);\" );\n "
43
47
+ " private static final Pattern PROVIDES_PATTERN =\n "
@@ -54,10 +58,14 @@ public static void write(PrintWriter out, String packageName) {
54
58
+ " private final List<Opens> opens = new ArrayList<>();\n "
55
59
+ " private final List<Provides> provides = new ArrayList<>();\n "
56
60
+ " private final ModuleElement moduleElement;\n "
57
- + "\n /** Parse the module-info.java using the ModuleElement from the APContext and create a new instance */\n "
61
+ + "\n "
62
+ + " /**\n "
63
+ + " * Parse the module-info.java using the ModuleElement from the APContext and create a new instance\n "
64
+ + " */\n "
58
65
+ " public ModuleInfoReader() throws IOException {\n "
59
66
+ " this(APContext.getProjectModuleElement(), APContext.getModuleInfoReader());\n "
60
- + " }\n \n "
67
+ + " }\n "
68
+ + "\n "
61
69
+ " /**\n "
62
70
+ " * Parse a module-info and create a new instance\n "
63
71
+ " *\n "
@@ -77,12 +85,13 @@ public static void write(PrintWriter out, String packageName) {
77
85
+ " */\n "
78
86
+ " public ModuleInfoReader(ModuleElement moduleElement, CharSequence moduleString) {\n "
79
87
+ " this.moduleElement = moduleElement;\n "
80
- + " Matcher importMatcher = IMPORT_PATTERN.matcher(moduleString);\n "
81
- + " Matcher requiresMatcher = REQUIRES_PATTERN.matcher(moduleString);\n "
82
- + " Matcher providesMatcher = PROVIDES_PATTERN.matcher(moduleString);\n "
83
- + " Matcher opensMatcher = OPENS_PATTERN.matcher(moduleString);\n "
84
- + " Matcher exportsMatcher = EXPORTS_PATTERN.matcher(moduleString);\n "
85
- + " Matcher usesMatcher = USES_PATTERN.matcher(moduleString);\n "
88
+ + " var input = COMMENT_PATTERN.matcher(moduleString).replaceAll(\" \" );\n "
89
+ + " Matcher importMatcher = IMPORT_PATTERN.matcher(input);\n "
90
+ + " Matcher requiresMatcher = REQUIRES_PATTERN.matcher(input);\n "
91
+ + " Matcher providesMatcher = PROVIDES_PATTERN.matcher(input);\n "
92
+ + " Matcher opensMatcher = OPENS_PATTERN.matcher(input);\n "
93
+ + " Matcher exportsMatcher = EXPORTS_PATTERN.matcher(input);\n "
94
+ + " Matcher usesMatcher = USES_PATTERN.matcher(input);\n "
86
95
+ "\n "
87
96
+ " while (requiresMatcher.find()) {\n "
88
97
+ " boolean transitive = requiresMatcher.group(1) != null;\n "
@@ -134,6 +143,7 @@ public static void write(PrintWriter out, String packageName) {
134
143
+ " }\n "
135
144
+ " }\n "
136
145
+ "\n "
146
+ + "\n "
137
147
+ " private String resolveImport(List<String> imports, String providedInterface) {\n "
138
148
+ " return imports.stream()\n "
139
149
+ " .filter(s -> s.contains(providedInterface))\n "
@@ -245,7 +255,7 @@ public static void write(PrintWriter out, String packageName) {
245
255
+ " }\n "
246
256
+ " }\n "
247
257
+ "\n "
248
- + " private static boolean buildPluginAvailable() {\n "
258
+ + " private static boolean buildPluginAvailable() {\n "
249
259
+ " return isPresent(\" avaje-plugin-exists.txt\" );\n "
250
260
+ " }\n "
251
261
+ "\n "
0 commit comments