Python知识分享网 - 专业的Python学习网站 学Python,上Python222
JAVA PMD规则 详解 PDF 下载
发布于:2023-09-11 10:32:21
(假如点击没反应,多刷新两次就OK!)

JAVA PMD规则 详解 PDF 下载  图1

 

 

 

 

资料内容:

 

The Basic Ruleset contains a collection of good practices which everyone should follow. · EmptyCatchBlock: Empty Catch Block finds instances where an exception is caught, but nothing is done. In most circumstances, this swallows an exception which should either be acted on or reported. 翻译 空的 catch 块:发现空的 catch 块没做任何异常处理的事,在大多数情形下,这会 吞噬一些应该被处理或报告的异常 · EmptyIfStmt: Empty If Statement finds instances where a condition is checked but nothing is done about it. 翻译 空的 if 表达式:发现使用 if 进行了条件判断,但是判断之后没做任何处理 · EmptyWhileStmt: Empty While Statement finds all instances where a while statement does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if it's a while loop that does a lot in the exit expression, rewrite it to make it clearer. 翻译 空的 while 表达式:发现空的 while 表达式,如果是一个定时的循环,你应该在循 环体内使用 Thread.sleep() ;如果是对于退出处理做的一个处理大量事情的 while 循环,重 写代码使它更清晰 · EmptyTryBlock: Avoid empty try blocks - what's the point? 翻译 空的 try 块:避免空的 try 块 · EmptyFinallyBlock: Avoid empty finally blocks - these can be deleted. 翻译 空的 finally 块:避免空的 finally 块 - 这些是可以删掉的 · EmptySwitchStatements: Avoid empty switch statements. 翻译 空的 switch 表达式:避免空的 switch 表达式 · JumbledIncrementer: Avoid jumbled loop incrementers - it's usually a mistake, and it's confusing even if it's what's intended. 翻译 避免混乱的循环 增量 - 它常常是一个错误,而且容易让人迷惑 错误代码示例: public class JumbledIncrementerRule1 { public void foo() { for (int i = 0; i < 10; i++) { for (int k = 0; k < 20; i++) { System.out.println("Hello"); } } } } 父子循环都用 i++ · ForLoopShouldBeWhileLoop: Some for loops can be simplified to while loops - this makes them more concise. 翻译 有些 for 循环可以简化为 while 循环 - 这样可以更加简明 代码示例: public class Foo { void bar() { for (;true;) true; // 没有初始化块和变化块,相当于 : while (true) } } · UnnecessaryConversionTemporary: Avoid unnecessary temporaries when converting primitives to Strings 翻译 将原始类型转换为字符串类型时不必要的临时转换 代码示例: public String convert(int x) { // 多了一个创建对象环节 String foo = new Integer(x).toString(); // 下面这种写法就好了 return Integer.toString(x); }