It finds unused variables, empty catch blocks,unnecessary object creation, and so forth.
Size: 56.9 KB
Language: en
Added: Jan 18, 2015
Slides: 9 pages
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 (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