Objective:
PMD is a static code analysis tool that can automatically detect various potential defects as well as unsafe or non-optimized code.
PMD is more focused on pre-detection flaws, and it provides a highly configurable rich set of rules that users can easily configure to treat specific projects using those rules.
Installation and use:
1. How to install the PMD plug-in in eclipse
Eclipse menu > Help > Install New software >
In the pop-up window, enter pmd-http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/
, click Add > Confirm >
will automatically download the plugin, download takes a little time,> choose to install Subclipse 3 can;
2. Activate the PMD plugin. Ecplise menu PROJECT->PROPERTIES->PMD, select the rule to apply in this window, and specify the relative importance of configuring PMD for specific items, currently only the Enable PMD check box is selected, leaving the default rule set.
3. Run PMD. Click Project resources, right-->pmd->check code with PMD. The PMD issue is listed by problem severity in the violation overview view. In violations Outlinew, right-click Show Details to see a more detailed description of the rule and sample code that describes the rule.
(PMD detects a project, class, individual file, etc.)
4. Several forms of inspection results
Right-click each result to perform several operations
? Show Details ... : Show Details
? Mark as reviewed: (marked as censored) menu item, which adds a comment to the code to instruct PMD to ignore this issue here.
? Remove violation: You can manually correct the problem and remove this problem directly from the list by using remove violation (remove violation)
? Clear violations Reviews: Clear Previous tags
PMD can also directly inspect a project to generate multiple formats of report files
Appendix:
PMD comes with a number of rules that can be used directly
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, you can customize the 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. You can also change the check contents of your own rule according to the actual situation
PMD self-rule and custom rules, interested in their own research;
The following time is shared;
Copyright NOTICE: This article for Bo Master ido original article, without Bo Master permission not reproduced.
Static code checking tool-PMD Beginner's introductory article