骏烈 7 years ago
parent 1ade912a4e
commit 40eaededd1

@ -61,7 +61,7 @@ object CodeAnalysis {
if (monitor.isCanceled) {
return@run Status.CANCEL_STATUS
}
if(it.isAccessible){
if (it.isAccessible) {
it.accept(fileVisitor)
}
}

@ -95,7 +95,7 @@ Counter example:
a.add("1");
a.add("2");
for (String temp : a) {
if ("1".equals(temp)){
if ("1".equals(temp)) {
a.remove(temp);
}
}
@ -204,7 +204,7 @@ Positive example:
// please refer to the pseudo-code as follows
boolean existed = (file.open(fileName, "w") != null) && (...) || (...);
if (existed) {
...
//...
}
```
@ -212,7 +212,7 @@ Positive example:
```java
if ((file.open(fileName, "w") != null) && (...) || (...)) {
...
// ...
}
```

@ -25,15 +25,15 @@ import net.sourceforge.pmd.lang.java.typeresolution.TypeHelper;
* @date 2016/11/16
*/
public class NodeUtils {
public static boolean isParentOrSelf(Node descendant,Node ancestor){
if(descendant == ancestor) {
public static boolean isParentOrSelf(Node descendant, Node ancestor) {
if (descendant == ancestor) {
return true;
}
if(descendant == null || ancestor == null){
if (descendant == null || ancestor == null) {
return false;
}
Node parent = descendant.jjtGetParent();
while(parent != ancestor && parent != null){
while (parent != ancestor && parent != null) {
parent = parent.jjtGetParent();
}
return parent == ancestor;
@ -41,6 +41,7 @@ public class NodeUtils {
/**
* TODO optimize
*
* @param expression expression
* @return true if wrapper type
*/

@ -11,14 +11,14 @@
<priority>1</priority>
<example>
<![CDATA[
Negative example:
Negative example:
//It is hard to tell whether it is number 11 or Long 1.
Long warn = 1l;
]]>
</example>
<example>
<![CDATA[
Positive example:
Positive example:
Long notwarn = 1L;
]]>
</example>
@ -31,18 +31,18 @@
<example>
<![CDATA[
Negative example:
Negative example:
//Magic values, except for predefined, are forbidden in coding.
if(key.equals("Id#taobao_1")){
if (key.equals("Id#taobao_1")) {
//...
}
]]>
</example>
<example>
<![CDATA[
Positive example:
Positive example:
String KEY_PRE = "Id#taobao_1";
if(key.equals(KEY_PRE)){
if (KEY_PRE.equals(key)) {
//...
}
]]>

@ -12,12 +12,12 @@
<example>
<![CDATA[
switch( x ){
case 1 :
break ;
case 2 :
break ;
default :
switch (x) {
case 1:
break;
case 2:
break;
default:
}
]]>
</example>
@ -31,7 +31,7 @@
<example>
<![CDATA[
if(flag) {
if (flag) {
System.out.println("hello world");
}
]]>
@ -49,7 +49,7 @@
<![CDATA[
Negative example:
if ((file.open(fileName, "w") != null) && (...) || (...)) {
...
// ...
}
]]>
</example>
@ -58,7 +58,7 @@ Negative example:
Positive example:
boolean existed = (file.open(fileName, "w") != null) && (...) || (...);
if (existed) {
...
//...
}
]]>
</example>

@ -14,7 +14,7 @@
<![CDATA[
public void f(String str){
String inner = "hi";
if(inner.equals(str)){
if (inner.equals(str)) {
System.out.println("hello world");
}
}
@ -34,7 +34,7 @@
Integer a = 235;
Integer b = 235;
if (a.equals(b)) {
//相等
// code
}
]]>
</example>
@ -112,7 +112,7 @@
<example>
<![CDATA[
反例:
Negative example:
String result;
for (String string : tagNameList) {
result = result + string;
@ -121,7 +121,7 @@
</example>
<example>
<![CDATA[
正例:
Positive example:
StringBuilder stringBuilder = new StringBuilder();
for (String string : tagNameList) {
stringBuilder.append(string);

@ -101,10 +101,9 @@ Negative example:
Iterator<Integer> it=b.iterator();
while(it.hasNext()){
Integer temp = it.next();
if(delCondition){
if (delCondition) {
it.remove();
}
}
]]>
</example>

@ -11,7 +11,7 @@
<test-code>
<description>UndefineMagicConstant.</description>
<expected-problems>0</expected-problems>
<code-ref id="constants-ok" />
<code-ref id="constants-ok"/>
</test-code>
<code-fragment id="constants-err"><![CDATA[
@ -22,27 +22,27 @@
Boolean h = false;
Long m = 2L;
String n = "";
if(i > 2){
if (i > 2) {
}
if(i > 1){
if (i > 1) {
}
if(m > 1L){
if (m > 1L) {
}
if(i != null){
if (i != null) {
}
if(h != false){
if (h != false) {
}
if(n.equals("")){
if (n.equals("")) {
}
for(int j=0 ; j< 10 ; i++){
if(i > 2){
for (int j = 0; j < 10; i++) {
if (i > 2) {
}
if(i != null){
if (i != null) {
}
}
while(k < 1){
if(i > 2){
while (k < 1) {
if (i > 2) {
}
k++;
}
@ -55,7 +55,7 @@
<description>UndefineMagicConstant.</description>
<expected-problems>2</expected-problems>
<expected-linenumbers>8,20</expected-linenumbers>
<code-ref id="constants-err" />
<code-ref id="constants-err"/>
</test-code>
<code-fragment id="constants-err-2"><![CDATA[
@ -73,7 +73,7 @@
<description>UndefineMagicConstant.</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>3</expected-linenumbers>
<code-ref id="constants-err-2" />
<code-ref id="constants-err-2"/>
</test-code>
</test-data>

@ -13,14 +13,14 @@
<test-code>
<description>sets-UnsupportedExceptionWithModifyAsListRule-ok.</description>
<expected-problems>0</expected-problems>
<code-ref id="sets-UnsupportedExceptionWithModifyAsListRule-ok" />
<code-ref id="sets-UnsupportedExceptionWithModifyAsListRule-ok"/>
</test-code>
<code-fragment id="sets-UnsupportedExceptionWithModifyAsListRule-warn"><![CDATA[
public class Foo {
private void method1() {
if(true){
List<String> list = Arrays.asList("a","b","c");
if (true) {
List<String> list = Arrays.asList("a", "b", "c");
list.add("d");
list.remove("22");
list.clear();
@ -31,8 +31,8 @@
}
private void method2() {
if(true){
List<String> list = Arrays.asList("a","b","c");
if (true) {
List<String> list = Arrays.asList("a", "b", "c");
list.add("d");
}
List<String> list = new ArrayList<String>();
@ -46,7 +46,7 @@
<description>sets-UnsupportedExceptionWithModifyAsListRule-warn.</description>
<expected-problems>4</expected-problems>
<expected-linenumbers>5,6,7,17</expected-linenumbers>
<code-ref id="sets-UnsupportedExceptionWithModifyAsListRule-warn" />
<code-ref id="sets-UnsupportedExceptionWithModifyAsListRule-warn"/>
</test-code>
</test-data>
Loading…
Cancel
Save