Fixed bug; thx to Luis Alberto DomÃnguez Ruiz for the report
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2533 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -15,23 +15,26 @@ public class IfElseStmtsMustUseBracesRuleTest extends SimpleAggregatorTst {
|
||||
|
||||
public void setUp() {
|
||||
rule = new XPathRule();
|
||||
rule.addProperty("xpath", "//IfStatement[count(*) > 2][not(Statement/Block)]");
|
||||
rule.addProperty("xpath", "//Statement[parent::IfStatement and not(child::Block)]");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[] {
|
||||
new TestDescriptor(TEST1, "simple failure case", 1, rule),
|
||||
new TestDescriptor(TEST1, "else without braces", 1, rule),
|
||||
new TestDescriptor(TEST2, "ok", 0, rule),
|
||||
new TestDescriptor(TEST3, "two sets of missing braces", 2, rule),
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" int y;" + PMD.EOL +
|
||||
" public void foo() { " + PMD.EOL +
|
||||
" if (true) " + PMD.EOL +
|
||||
" y=2;" + PMD.EOL +
|
||||
" else " + PMD.EOL +
|
||||
" x=4;" + PMD.EOL +
|
||||
" if (true) {" + PMD.EOL +
|
||||
" x=2;" + PMD.EOL +
|
||||
" } else " + PMD.EOL +
|
||||
" y=4;" + PMD.EOL +
|
||||
" " + PMD.EOL +
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
@ -45,4 +48,15 @@ public class IfElseStmtsMustUseBracesRuleTest extends SimpleAggregatorTst {
|
||||
" }" + PMD.EOL +
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String TEST3 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" public void foo() { " + PMD.EOL +
|
||||
" if (true) " + PMD.EOL +
|
||||
" y=2;" + PMD.EOL +
|
||||
" else " + PMD.EOL +
|
||||
" x=4;" + PMD.EOL +
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ The Braces Ruleset contains a collection of braces rules.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[count(*) > 2][not(Statement/Block)]
|
||||
//Statement[parent::IfStatement and not(child::Block)]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
@ -38,6 +38,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li>Luis Alberto Domínguez Ruiz - bug report for IfElseStmtsMustUseBracesRule</li>
|
||||
<li>Chad Loder - SuspiciousOctalEscapeRule, EmptyStatementNotInLoop, SuspiciousHashcodeMethodName, NonCaseLabelInSwitchStatement, DefaultLabelNotLastInSwitchStmt, NonStaticInitializer, ExplicitCallToFinalize, MethodWithSameNameAsEnclosingClassRuleTest, FinalizeDoesNotCallSuperFinalize, FinalizeOverloaded, FinalizeOnlyCallsSuperFinalize, UnconditionalIfStatement, AvoidDollarSigns, EmptyStaticInitializer, EmptyFinalizerMethod rule, DontImportSun rule, improvements to ASTBooleanLiteral</li>
|
||||
<li>Maik Schreiber - AccessNode bug report, other bug reports</li>
|
||||
<li>Lokesh Gupta - improvements to the AST viewer</li>
|
||||
|
Reference in New Issue
Block a user