forked from phoedos/pmd
Fixed docs, thx to David Karr for the correction
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4361 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -48,6 +48,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li>David Karr - reported stale XPath documentation</li>
|
||||
<li>Christopher Stach - several bug reports for rules that didn't handle JDK 1.5 enums</li>
|
||||
<li>Jarkko Hietaniemin - rewrote most of cpd.sh, tweaked C/CPP grammar to allow $ in identifiers, several CPD documentation suggestions, noted missing CPD scripts in binary release</li>
|
||||
<li>Dawid Weiss - Reported bug in UnusedPrivateMethod</li>
|
||||
|
@ -95,7 +95,11 @@ Writing PMD rules with XPath can be a bit easier than writing rules with Java co
|
||||
<p>You'll quickly see that all three local variables are matched. A possible
|
||||
solution for this is to request that the parent of the local variable
|
||||
declaration is the MethodDeclaration node:</p>
|
||||
<source><![CDATA[//LocalVariableDeclaration[name(../../..) = 'MethodDeclaration']]]></source>
|
||||
<source>
|
||||
<![CDATA[
|
||||
//LocalVariableDeclaration[name(../../..) = 'MethodDeclaration']
|
||||
]]>
|
||||
</source>
|
||||
<subsection name="Matching variables by name">
|
||||
<p>Let's consider that we are writing rules for logger. Let's assume we
|
||||
use the Java logging API and we want to find all classes that have more
|
||||
@ -141,7 +145,12 @@ Writing PMD rules with XPath can be a bit easier than writing rules with Java co
|
||||
}
|
||||
]]></source>
|
||||
<p>The following expression does the magic we need:</p>
|
||||
<source><![CDATA[//VariableDeclarator[../Type/Name[@Image='Factory'] and ..[@Final='false'] ]]]></source>
|
||||
<source><![CDATA[
|
||||
//VariableDeclarator
|
||||
[../Type/ReferenceType/ClassOrInterfaceType
|
||||
[@Image = 'Factory'] and ..[@Final='false']]
|
||||
]]>
|
||||
</source>
|
||||
<p>I must recommend at this point that you experiment with Designer putting
|
||||
the final modifier to the Factory and verifying that the results produced
|
||||
are those expected.</p>
|
||||
|
Reference in New Issue
Block a user