javaintellij-ideacommentsautomated-refactoring

How do i reformat java comments, to remove whitespaces in intellij?


What IntelliJ format setting should be set to automatically change line comments to look like:

    validcode();
    // comment1
    // comment2
    validCode();

from lookin like this:

    validcode();
    //       comment1
    //       comment2
    validCode();

No result with all the settings i have tried.


Solution

  • There may be a way to do this via editor settings. But you could remedy this using a regex replace all:

    Find:    //\s{2,}(.*)$
    Replace: // $1
    

    This would be under the assumption that once a // style comment has been declared, the remainder of that line belongs to the comment.

    Note that you could even apply the above replacement to all files in the project, or all Java source files in the project, module, etc.