What is-pmd

3trg 806 views 9 slides Jan 18, 2015
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

PMD is a source code analyzer.

It finds unused variables, empty catch blocks,unnecessary object creation, and so forth.


Slide Content

What is PMD ?
PMD is a source code analyzer.
It finds unused variables, empty catch blocks,
unnecessary object creation, and so forth.

PMD works by scanning Java code and checks for violations
in three major areas:
– Compliance with coding standards
– Coding antipatterns
– Cut and Paste Detector (CPD)

Compliance with coding standards
●Naming conventions
–class, method, parameter and variable names
●Class and method length
●Existence and formatting of comments and JavaDocs

Coding antipatterns
●Possible bugs - Empty try/catch/finally/switch blocks
●Dead code - Unused local variables, parameters and private methods
●Empty (if/while) statements
●Suboptimal code - wasteful String/StringBuffer usage

Coding antipatterns (2)
Overcomplicated expressions
–unnecessary if statements, for loops that could be while loops
Duplicate code
–copied/pasted code means copied/pasted bugs
Classes with high Cyclomatic Complexity measurements

Cut and Paste Detector (CPD)
a tool that scans files and looks for suspect code replication.
CPD can be parametrized by the minimum size of the code block.

Stakeholders
●Developers use PMD to comply with coding standards and
deliver quality code.
●Team leaders and Quality Assurance folks use it to change the
nature of code reviews.
●Team members can do peer-to-peer discussion
PMD has the potential to transform a mechanical and syntax check
oriented code review into a to dynamic peer-to-peer discussion.

Rules
PMD comes with many predefined rules; we can add more or
customize existing one.
EmptyFinallyBlock
–Avoid empty finally blocks - these can be deleted
UnnecessaryReturn
–Avoid unnecessary return statements
LongVariable
–Detects when a field, local variable is declared with a long name

PMD rules has been grouped into Rule sets
Rule set: Naming Rules
–Rule: VariableNamingConventions
–Rule: MethodNamingConventions
–Rule: ClassNamingConventions
–Rule: NoPackage
Rule set: Unused Code Rules
–Rule: UnusedPrivateField
–Rule: UnusedLocalVariable