patch 3130615: fix xpath rule to consider the correct if-condition.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7358 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Andreas Dangel
2011-09-26 19:49:41 +00:00
parent 7868131b5c
commit 93f9d6760b
2 changed files with 20 additions and 1 deletions

View File

@ -49,6 +49,25 @@ public class Test {
__log.debug("bla" + "",e );
}
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
Complex logging wit misplaced guard
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Test {
private static final Log __log = LogFactory.getLog(Test.class);
public void test() {
if (true) {
// bad:
__log.debug("log something" + " and " + "concat strings");
// this is useless:
__log.isDebugEnabled();
}
}
}
]]></code>
</test-code>

View File

@ -104,7 +104,7 @@ public class Foo {
<property name="xpath">
<value>
<![CDATA[
//PrimaryPrefix[ends-with(Name/@Image, '.debug') and count(../descendant::AdditiveExpression) > 0 and count(ancestor::IfStatement/descendant::PrimaryExpression[ends-with(descendant::PrimaryPrefix/Name/@Image, 'isDebugEnabled')]) = 0]
//PrimaryPrefix[ends-with(Name/@Image, '.debug') and count(../descendant::AdditiveExpression) > 0 and count(ancestor::IfStatement/Expression/descendant::PrimaryExpression[ends-with(descendant::PrimaryPrefix/Name/@Image, 'isDebugEnabled')]) = 0]
]]>
</value>
</property>