我有很多评论如下.是否有简单的方法来删除所有评论?
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文件中的所有注释.
我为此目的制作了一个开源库,您可以删除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)
| 归档时间: |
|
| 查看次数: |
38041 次 |
| 最近记录: |