PMD is an open source Code analyzer. You can find common programming flaws, such as unused variables, empty catch blocks, unnecessary object creation, and so on. Supports Java, JavaScript, Plsql, Apache Velocity, XML, XSL.
In addition to this, PMD also includes CPD (copy, paste detector). CPD can be found in duplicate Java, C, C + +, C #, PHP, Ruby, Fortran, JavaScript, Plsql, Apache Velocity, Ruby, Scala, Objective C, Matlab, Python, Go.
Key Features
Unlike other analysis tools, PMD learns about code errors through static analysis. In other words, an error is reported without running a Java program. PMD comes with many rules that can be used directly, using these rules to identify many problems with Java source programs, such as:
- Potential bug: Empty Try/catch/finally/switch statement
- Unused code: Unused local variables, parameters, private methods, and so on
- Optional code: Misuse of String/stringbuffer
- Complex expressions: Non-required if statements, for loops that can be completed with a while loop
- Duplicate code: Copy/Paste code means copy/paste bugs
- Loop body Create a new object: Try not to instantiate a new object in the for or while loop body
- Resource off: Connect,result,statement after use, make sure to shut down
In addition, users can define their own rules to check whether the Java code conforms to certain coding specifications. For example, you can write a rule that requires PMD to find all the operations that create the thread and socket objects.
Working principle
The core of PMD is the JAVACC parser generator. PMD combines JAVACC and EBNF (extended Backus-Noel Paradigm, Extended backus-naur formal) syntax, plus jjtree, to parse the Java source code into an abstract syntax tree (ast,abstract Syntax tree).
Installation and PMD plugins
PMD provides the installation plug-ins for various IDES:
- Maven PMD Plugin
- Eclipse Plugin
- NetBeans Plugin
- JBuilder Plugin
- JDeveloper Plugin
- IntelliJ Idea Plugin
Document
The official documentation describes details such as downloads, installation, related books, best practices, custom rules, and more.
- Official Document: Https://pmd.github.io/pmd-5.4.0/index.html
- Related open source projects and books: http://pmd.sourceforge.net/snapshot/overview/products.html
Official website: https://pmd.github.io/
Open Source Address: HTTPS://GITHUB.COM/PMD
Pmd:java Source code Scanner