删除Java文件中的所有注释

Ahm*_*aya 18 java eclipse

我有很多评论如下.是否有简单的方法来删除所有评论?

IDE Eclipse Kepler

/* 34:   */

/*

 * JD-Core Version:    0.7.0.1

 */
Run Code Online (Sandbox Code Playgroud)

Ahm*_*aya 48

我找到了解决方案正则表达式与多行搜索.

以下是用于查找两种类型注释的正则表达式

\/\*([\S\s]+?)\*\/(?s)/\*.*?\*/

打开.java包含注释的文件并打开"搜索"对话框.(Search -> File Search)并粘贴上述注册表中的一个,然后选中Regular expression右侧的复选框.现在,您可以搜索并选择"全部替换",将其替换为第二个框中键入的内容.

使用replace-with选项我已经清除了java文件中的所有注释.


Ert*_*tin 5

我为此目的制作了一个开源,您可以删除Java注释。

它支持删除或不删除TODO。

它还支持JavaScript,HTML,CSS,Properties,JSP和XML注释。

小代码段如何使用它:

 public static void main(String[] args) throws CommentRemoverException {

 // root dir is: /Users/user/Projects/MyProject
 // example for startInternalPath

 CommentRemover commentRemover = new CommentRemover.CommentRemoverBuilder()
        .removeJava(true) // Remove Java file Comments....
        .removeJavaScript(true) // Remove JavaScript file Comments....
        .removeJSP(true) // etc.. goes like that
        .removeTodos(false) //  Do Not Touch Todos (leave them alone)
        .removeSingleLines(true) // Remove single line type comments
        .removeMultiLines(true) // Remove multiple type comments
        .startInternalPath("src.main.app") // Starts from {rootDir}/src/main/app , leave it empty string when you want to start from root dir
        .setExcludePackages(new String[]{"src.main.java.app.pattern"}) // Refers to {rootDir}/src/main/java/app/pattern and skips this directory
        .build();

 CommentProcessor commentProcessor = new CommentProcessor(commentRemover);
                  commentProcessor.start();        
  }
Run Code Online (Sandbox Code Playgroud)


Wes*_*eso 5

我已经用Ctrl+F命令和这个正则表达式完成了这个。

这只能替换 //comments

//(.?+)+
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明