All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.pmd.rules.pmd.XPathRule.html Maven / Gradle / Ivy

Go to download

PMD is a tool that looks for potential problems like possible bugs, dead code, suboptimal code, overcomplicated expressions or duplicate code.

There is a newer version: 3.3.2
Show newest version
PMD provides a very handy method for creating new rules by writing an XPath query. When the XPath query finds a match, a violation is created.
Let's take a simple example: assume we have a Factory class that must be always declared final.
We'd like to report a violation each time a declaration of Factory is not declared final. Consider the following class:
public class a {
  Factory f1;

  void myMethod() {
    Factory f2;
    int a;
  }
}
The following expression does the magic we need:
//VariableDeclarator
 [../Type/ReferenceType/ClassOrInterfaceType
  [@Image = 'Factory'] and ..[@Final='false']]
See the XPath rule tutorial for more information.




© 2015 - 2024 Weber Informatics LLC | Privacy Policy