<?xml version="1.0"?>

<ruleset name="PMD specific rules"
    xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
  <description>These rules check for problems that are specific to the PMD codebase and may not be applicable to other projects.</description>

  <rule name="UseInstanceOftoCompareClasses"
      language="java" since="5.0"
      message="replace o.getClass().equals(MyClass.class) with o instanceof MyClass"
      class="net.sourceforge.pmd.lang.rule.XPathRule">
    <description>replace o.getClass().equals(MyClass.class) with o instanceof MyClass. Make sure MyClass doesn't have descendants</description>
    <priority>3</priority>
    <properties>
      <property name="xpath">
        <value>
<![CDATA[
//PrimaryExpression[
(PrimaryPrefix[Name[ends-with(@Image, 'getClass')]] or PrimarySuffix[@Image='getClass'])
and
PrimarySuffix[Arguments[count(ArgumentList)=0]]
and
PrimarySuffix[@Image='equals']
and
PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix
/ResultType/Type/ReferenceType/ClassOrInterfaceType
]
]]>
        </value>
      </property>
    </properties>
  </rule>

  <rule name="ReversedUseInstanceOftoCompareClasses"
      language="java" since="5.0"
      message="replace MyClass.class.equals(o.getClass()) with o instanceof MyClass"
      class="net.sourceforge.pmd.lang.rule.XPathRule">
    <description>replace MyClass.class.equals(o.getClass()) with o instanceof MyClass. Make sure MyClass doesn't have descendants</description>
    <priority>3</priority>
    <properties>
      <property name="xpath">
        <value>
<![CDATA[
//PrimaryExpression[
PrimaryPrefix[ResultType/Type/ReferenceType/ClassOrInterfaceType]
and
PrimarySuffix[@Image='equals']
and
PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression[
  PrimaryPrefix[Name[ends-with(@Image, 'getClass')]]
  and
  PrimarySuffix[Arguments[count(ArgumentList)=0]]
  ]
]
]]>
        </value>
      </property>
    </properties>
  </rule>

</ruleset>
