Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments cannot be parsed properly #4624

Merged
merged 8 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,8 @@ private int positionOfNext(String untilDelim, @Nullable Character stop) {
case '*':
if(c2 == '/') {
inMultiLineComment = false;
delimIndex += 2;
delimIndex++;
continue;
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,8 @@ private int positionOfNext(String untilDelim, @Nullable Character stop) {
case '*':
if (c2 == '/') {
inMultiLineComment = false;
delimIndex += 2;
delimIndex++;
continue;
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,8 @@ private int positionOfNext(String untilDelim, @Nullable Character stop) {
case '*':
if (c2 == '/') {
inMultiLineComment = false;
delimIndex += 2;
delimIndex++;
continue;
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,8 @@ private int positionOfNext(String untilDelim, @Nullable Character stop) {
case '*':
if(c2 == '/') {
inMultiLineComment = false;
delimIndex += 2;
delimIndex++;
continue;
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,64 @@ void shouldResolvePathUsingPublicClasses(@Language("java") String source) {
rewriteRun(
java(
source,
spec -> spec.afterRecipe(cu -> assertThat(cu.getSourcePath()).isEqualTo(Path.of("my","example","PublicClass.java")))
spec -> spec.afterRecipe(cu -> assertThat(cu.getSourcePath()).isEqualTo(Path.of("my", "example", "PublicClass.java")))
)
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/1895")
void moduleInfo(){
void moduleInfo() {
// Ignored until properly handled: https://github.com/openrewrite/rewrite/issues/4054#issuecomment-2267605739
assertFalse(JavaParser.fromJavaVersion().build().accept(Path.of("src/main/java/foo/module-info.java")));
}

@Test
@Issue("https://github.com/openrewrite/rewrite/pull/4624")
void shouldParseComments() {
rewriteRun(
java(
"""
class A {
/*
* public Some getOther() { return other; }
*
*//**
* Sets the value of the other property.
*
* @param value allowed object is {@link Some }
*
*//*
* public void setOther(Some value) { this.other =
* value; }
*/
}
""",
spec -> spec.afterRecipe(cu -> assertThat(cu.getClasses().get(0).getBody().getEnd().getComments())
.extracting("text")
.containsExactly(
"""

* public Some getOther() { return other; }
*
\
""",
"""
*
* Sets the value of the other property.
*
* @param value allowed object is {@link Some }
*
\
""",
"""

* public void setOther(Some value) { this.other =
* value; }
\
"""
))
)
);
}
}