You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to add a comment to a Java method. This comment could either be single line // or multiline /* */
What precondition(s) should be checked before applying this recipe?
Does the method exist
Describe the situation before applying the recipe
Adding a single line comment (isMultiline is false):
rewriteRun(
spec -> spec.recipe(newAddCommentToJavaMethod(" Short comment to add", "foo.Foo bar(..)", false)),
//language=javajava(
""" package foo; public class Foo { public void bar(String arg) {} } """,
""" package foo; public class Foo { // Short comment to add public void bar(String arg) {} } """
)
);
Adding a multiline comment (isMultiline is true):
rewriteRun(
spec -> spec.recipe(newAddCommentToJavaMethod(" This is a very long comment to add. The comment is longer than 80 characters and should use multiline comments, not single line.", "foo.Foo bar(..)", true)),
//language=javajava(
""" package foo; public class Foo { public void bar(String arg) {} } """,
""" package foo; public class Foo { /* This is a very long comment to add. The comment is longer than 80 characters and should use multiline comments, not single line.*/ public void bar(String arg) {} } """
)
);
Have you considered any alternatives or workarounds?
What problem are you trying to solve?
I am trying to add a comment to a Java method. This comment could either be single line // or multiline /* */
What precondition(s) should be checked before applying this recipe?
Does the method exist
Describe the situation before applying the recipe
Adding a single line comment (
isMultiline
isfalse
):Adding a multiline comment (
isMultiline
istrue
):Have you considered any alternatives or workarounds?
Any additional context
Are you interested in contributing this recipe to OpenRewrite?
Yes.
The text was updated successfully, but these errors were encountered: