Skip to content

Commit 22ff749

Browse files
committed
Ignore multi-line comments in more cases
In particular, multi-line comments that span only a single line.
1 parent e02dd1e commit 22ff749

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/main/java/org/gradlex/javamodule/dependencies/internal/utils/ModuleInfo.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ private boolean parse(String moduleLine, boolean insideComment) {
9090
return !moduleLine.contains("*/");
9191
}
9292

93-
List<String> tokens = Arrays.asList(moduleLine.replace(";","").replace("{","").trim().split("\\s+"));
93+
List<String> tokens = Arrays.asList(moduleLine
94+
.replace(";","")
95+
.replace("{","")
96+
.replaceAll("/\\*.*?\\*/"," ")
97+
.trim().split("\\s+"));
9498
int singleLineCommentStartIndex = tokens.indexOf("//");
9599
if (singleLineCommentStartIndex >= 0) {
96100
tokens = tokens.subList(0, singleLineCommentStartIndex);
@@ -110,6 +114,6 @@ private boolean parse(String moduleLine, boolean insideComment) {
110114
requires.add(tokens.get(1));
111115
}
112116
}
113-
return moduleLine.contains("/*");
117+
return moduleLine.lastIndexOf("/*") > moduleLine.lastIndexOf("*/");
114118
}
115119
}

src/test/groovy/org/gradlex/javamodule/dependencies/test/ModuleInfoParseTest.groovy

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,23 @@ class ModuleInfoParseTest extends Specification {
6161
moduleInfo.get(REQUIRES_STATIC_TRANSITIVE) == []
6262
}
6363

64+
def "ignores multi line comments between keywords"() {
65+
given:
66+
def moduleInfo = new ModuleInfo('''
67+
module some.thing {
68+
/*odd comment*/ requires transitive foo.bar.la;
69+
requires/* weird comment*/ static foo.bar.lo;
70+
requires /*something to say*/foo.bar.li; /*
71+
requires only.a.comment
72+
*/
73+
}
74+
''')
75+
76+
expect:
77+
moduleInfo.get(REQUIRES) == ["foo.bar.li"]
78+
moduleInfo.get(REQUIRES_TRANSITIVE) == ["foo.bar.la"]
79+
moduleInfo.get(REQUIRES_STATIC) == ["foo.bar.lo"]
80+
moduleInfo.get(REQUIRES_STATIC_TRANSITIVE) == []
81+
}
82+
6483
}

0 commit comments

Comments
 (0)