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

Add a new recipe to add comments to a Java method #4716

Closed
agoncal opened this issue Nov 26, 2024 · 2 comments · Fixed by #4719
Closed

Add a new recipe to add comments to a Java method #4716

agoncal opened this issue Nov 26, 2024 · 2 comments · Fixed by #4719
Assignees
Labels
good first issue Good for newcomers recipe Requested Recipe

Comments

@agoncal
Copy link
Contributor

agoncal commented Nov 26, 2024

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 is false):

rewriteRun(
    spec -> spec.recipe(new AddCommentToJavaMethod(" Short comment to add", "foo.Foo bar(..)", false)),
    //language=java
    java(
        """
                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(new AddCommentToJavaMethod(" 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=java
    java(
        """
                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?

Any additional context

Are you interested in contributing this recipe to OpenRewrite?

Yes.

@timtebeek timtebeek added the recipe Requested Recipe label Nov 26, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Nov 26, 2024
@timtebeek
Copy link
Contributor

Thanks for the offer to contribute! Feel free to open a draft PR at any moment to make it easier to provide you with feedback.

@agoncal
Copy link
Contributor Author

agoncal commented Nov 26, 2024

@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers recipe Requested Recipe
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants