Skip to content

Commit 65197bf

Browse files
authored
Fix Incorrect Comment Handling (#84)
* fix incorrect comment handling * Update ModuleInfoReaderWriter.java * fix multi-line comments
1 parent 2e82d8b commit 65197bf

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

prism-core/src/main/java/io/avaje/prism/internal/ModuleInfoReaderWriter.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.avaje.prism.internal;
22

33
import java.io.PrintWriter;
4+
import java.util.regex.Pattern;
45

56
public class ModuleInfoReaderWriter {
67
private ModuleInfoReaderWriter() {}
@@ -38,6 +39,9 @@ public static void write(PrintWriter out, String packageName) {
3839
+ "\n"
3940
+ " private static final String SPLIT_PATTERN = \"\\\\s*,\\\\s*\";\n"
4041
+ " 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"
4145
+ " private static final Pattern REQUIRES_PATTERN =\n"
4246
+ " Pattern.compile(\"requires\\\\s+(transitive\\\\s+)?(static\\\\s+)?([\\\\w.$]+);\");\n"
4347
+ " private static final Pattern PROVIDES_PATTERN =\n"
@@ -54,10 +58,14 @@ public static void write(PrintWriter out, String packageName) {
5458
+ " private final List<Opens> opens = new ArrayList<>();\n"
5559
+ " private final List<Provides> provides = new ArrayList<>();\n"
5660
+ " 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"
5865
+ " public ModuleInfoReader() throws IOException {\n"
5966
+ " this(APContext.getProjectModuleElement(), APContext.getModuleInfoReader());\n"
60-
+ " }\n\n"
67+
+ " }\n"
68+
+ "\n"
6169
+ " /**\n"
6270
+ " * Parse a module-info and create a new instance\n"
6371
+ " *\n"
@@ -77,12 +85,13 @@ public static void write(PrintWriter out, String packageName) {
7785
+ " */\n"
7886
+ " public ModuleInfoReader(ModuleElement moduleElement, CharSequence moduleString) {\n"
7987
+ " 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"
8695
+ "\n"
8796
+ " while (requiresMatcher.find()) {\n"
8897
+ " boolean transitive = requiresMatcher.group(1) != null;\n"
@@ -134,6 +143,7 @@ public static void write(PrintWriter out, String packageName) {
134143
+ " }\n"
135144
+ " }\n"
136145
+ "\n"
146+
+ "\n"
137147
+ " private String resolveImport(List<String> imports, String providedInterface) {\n"
138148
+ " return imports.stream()\n"
139149
+ " .filter(s -> s.contains(providedInterface))\n"
@@ -245,7 +255,7 @@ public static void write(PrintWriter out, String packageName) {
245255
+ " }\n"
246256
+ " }\n"
247257
+ "\n"
248-
+ " private static boolean buildPluginAvailable() {\n"
258+
+ " private static boolean buildPluginAvailable() {\n"
249259
+ " return isPresent(\"avaje-plugin-exists.txt\");\n"
250260
+ " }\n"
251261
+ "\n"

0 commit comments

Comments
 (0)