Pmd:java Source code Scanner

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.