Merge branch 'pr/3716' into pmd7-pr-3716
This commit is contained in:
2 files changed
+86
-13
No files matched your search
+13
-13
@@ -33,7 +33,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTFinallyClause node, Object data) {
|
||||
if (isEmpty(node.getBody())) {
|
||||
addViolation(data, node, "Empty finally clause");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty finally clause");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTSynchronizedStatement node, Object data) {
|
||||
if (isEmpty(node.getBody())) {
|
||||
addViolation(data, node, "Empty synchronized statement");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty synchronized statement");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTSwitchStatement node, Object data) {
|
||||
if (node.getNumChildren() == 1) {
|
||||
addViolation(data, node, "Empty switch statement");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty switch statement");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTBlock node, Object data) {
|
||||
if (isEmpty(node) && node.getParent() instanceof ASTBlock) {
|
||||
addViolation(data, node, "Empty block");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty block");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -65,10 +65,10 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTIfStatement node, Object data) {
|
||||
if (isEmpty(node.getThenBranch())) {
|
||||
addViolation(data, node, "Empty if statement");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty if statement");
|
||||
}
|
||||
if (node.hasElse() && isEmpty(node.getElseBranch())) {
|
||||
addViolation(data, node.getElseBranch(), "Empty else statement");
|
||||
asCtx(data).addViolationWithMessage(node.getElseBranch(), "Empty else statement");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTWhileStatement node, Object data) {
|
||||
if (isEmpty(node.getBody())) {
|
||||
addViolation(data, node, "Empty while statement");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty while statement");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTForStatement node, Object data) {
|
||||
if (isEmpty(node.getBody())) {
|
||||
addViolation(data, node, "Empty for statement");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty for statement");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
return null;
|
||||
}
|
||||
if (isEmpty(node.getBody())) {
|
||||
addViolation(data, node, "Empty for-each statement");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty foreach statement");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTDoStatement node, Object data) {
|
||||
if (isEmpty(node.getBody())) {
|
||||
addViolation(data, node, "Empty do..while statement");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty do..while statement");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
@Override
|
||||
public Object visit(ASTInitializer node, Object data) {
|
||||
if (isEmpty(node.getBody())) {
|
||||
addViolation(data, node, "Empty initializer statement");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty initializer statement");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -136,9 +136,9 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule {
|
||||
}
|
||||
|
||||
if (hasResource && !allResourcesIgnored) {
|
||||
addViolation(data, node, "Empty try body - you could rename the resource to 'ignored'");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty try body - you could rename the resource to ''ignored''");
|
||||
} else if (!hasResource) {
|
||||
addViolation(data, node, "Empty try body");
|
||||
asCtx(data).addViolationWithMessage(node, "Empty try body");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
+73
@@ -7,6 +7,9 @@
|
||||
<description>pos, empty try block</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>3</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty try body</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class EmptyTryBlock1 {
|
||||
public void foo() {
|
||||
@@ -23,6 +26,9 @@
|
||||
<description>pos, empty try block</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>3</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty try body</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class EmptyTryBlock2 {
|
||||
public void foo() {
|
||||
@@ -38,6 +44,9 @@
|
||||
<description>pos, empty finally block</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>5</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty finally clause</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class EmptyTryBlock2 {
|
||||
public void foo() {
|
||||
@@ -68,6 +77,10 @@
|
||||
<test-code>
|
||||
<description>pos, empty try and finally block</description>
|
||||
<expected-problems>2</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty try body</message>
|
||||
<message>Empty finally clause</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class EmptyTryBlock3 {
|
||||
public void foo() {
|
||||
@@ -82,6 +95,9 @@
|
||||
<test-code>
|
||||
<description>#432 empty try-with-resource - not ok</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty try body - you could rename the resource to 'ignored'</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
class X {
|
||||
void method() {
|
||||
@@ -113,6 +129,9 @@
|
||||
<description>empty concise try-with-resource - not ok</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>4</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty try body - you could rename the resource to 'ignored'</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
import java.io.InputStream;
|
||||
class X {
|
||||
@@ -127,6 +146,9 @@
|
||||
<test-code>
|
||||
<description>pos, empty synchronized stmt</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty synchronized statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void foo() {
|
||||
@@ -151,6 +173,9 @@
|
||||
<test-code>
|
||||
<description>pos, empty switch stmt</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty switch statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class EmptySwitchStmt1 {
|
||||
public void bar() {
|
||||
@@ -180,6 +205,9 @@
|
||||
<test-code>
|
||||
<description>pos, empty block</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty block</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
@@ -204,6 +232,9 @@
|
||||
<test-code>
|
||||
<description>empty initializer failure case (non static)</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty initializer statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
{}
|
||||
@@ -214,6 +245,9 @@
|
||||
<test-code>
|
||||
<description>empty initializer failure case (static)</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty initializer statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
static {}
|
||||
@@ -224,6 +258,9 @@
|
||||
<test-code>
|
||||
<description>not an initializer - empty statement block</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty block</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
@@ -260,6 +297,10 @@
|
||||
<description>pos, empty for</description>
|
||||
<expected-problems>2</expected-problems>
|
||||
<expected-linenumbers>3,5</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty for statement</message>
|
||||
<message>Empty for statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
@@ -277,6 +318,10 @@
|
||||
<description>pos, empty do..while</description>
|
||||
<expected-problems>2</expected-problems>
|
||||
<expected-linenumbers>4,6</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty do..while statement</message>
|
||||
<message>Empty do..while statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
@@ -295,6 +340,10 @@
|
||||
<description>pos, empty foreach</description>
|
||||
<expected-problems>2</expected-problems>
|
||||
<expected-linenumbers>6,8</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty for statement</message>
|
||||
<message>Empty for statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
import java.util.List;
|
||||
|
||||
@@ -335,6 +384,9 @@
|
||||
<description>pos, empty while</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>3</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty while statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
@@ -351,6 +403,9 @@
|
||||
<test-code>
|
||||
<description>while(true);</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty while statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
@@ -364,6 +419,9 @@
|
||||
<description>one empty if statement</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>3</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty if statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar(int x) {
|
||||
@@ -378,6 +436,10 @@ public class Foo {
|
||||
<description>empty if with else statement</description>
|
||||
<expected-problems>2</expected-problems>
|
||||
<expected-linenumbers>3,4</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty if statement</message>
|
||||
<message>Empty else statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar(int x) {
|
||||
@@ -393,6 +455,11 @@ public class Foo {
|
||||
<description>empty if with else and else if statement</description>
|
||||
<expected-problems>3</expected-problems>
|
||||
<expected-linenumbers>3,4,5</expected-linenumbers>
|
||||
<expected-messages>
|
||||
<message>Empty if statement</message>
|
||||
<message>Empty if statement</message>
|
||||
<message>Empty else statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar(int x) {
|
||||
@@ -422,6 +489,9 @@ public class Foo {
|
||||
<test-code>
|
||||
<description>empty if statement</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty if statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar(int x) {
|
||||
@@ -434,6 +504,9 @@ public class Foo {
|
||||
<test-code>
|
||||
<description>empty if statement with comment</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-messages>
|
||||
<message>Empty if statement</message>
|
||||
</expected-messages>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
void bar(int x) {
|
||||
|
||||
Reference in new issue
Block a user