当前位置:网站首页>Introduction to PMD source code analyzer
Introduction to PMD source code analyzer
2022-06-28 17:12:00 【Hua Weiyun】
When checking the code , It is often seen that the specification on which a defect is based comes from PMD. The frequency of seeing is higher , Curiosity comes :PMD What is it ? Why does it appear so frequently ?
So I searched the Internet , Find out PMD It means a lot of strange things . Can represent Programming Mistake Detector( Static code checking tool ),Program Managment Document( Project management documents ),Physical Media Dependent( Physical media decides ),Pretty Much Done( Almost finished ),Project Meets Deadline( It's the deadline for the project ) wait , Except that the first one has something to do with our code checking , In addition, we should understand it .
But what we are going to talk about here PMD In fact, it is used by the static code check plug-in tool Source code analyzer (source code analyzer). It can detect common programming defects in the code without running the project code ( Such as unused variables / Empty capture block , Unnecessary object creation, etc ), The way is to compare with the rules that have been made in advance ( Rules can be customized and extended , You can use Java To write , You can also use XPath Inquire about ), Compare the parts of the code that do not conform to the rules .
Besides ,PMD It also includes CPD(copy-paste-detector), A copy and paste detector . It can be C/C++, C#, Dart, Fortran, Go, Groovy, Java, JavaScript, JSP, Kotlin, Lua, Matlab, Modelica, Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift, Visualforce and XML Duplicate part found in language file .
PMD Support for multiple languages :Java, JavaScript, Salesforce.com Of Apex and Visualforce, Modelica, PLSQL, Apache Velocity, XML, XSL, Scala.
PMD How to detect defects
PMD How does it work ?
It USES JavaCC( An open source parser generator and lexical analyzer generator ) and Antlr( be based on LL Algorithm implementation of the syntax parser generator ), Parse the source file into an abstract syntax tree ; Then, according to the pre-determined rules, the corresponding nodes in the tree , Analyze its properties or structure , So as to find out the corresponding violations .
Abstract syntax tree , namely AST-Abstract Syntax Tree, Will pass the code structure through “ Trees ” In the form of , Code of each part ( For example, variable declaration 、if-else sentence 、 Variable assignment 、 class 、 Database query, etc ) Will become each node of the tree .
for instance :
public class ClassA { public static void MethodB() { if (false) { String varStr = "hello HW PaaS!"; } }}After converting the above code into a syntax tree , Its structure is similar to UserClass “ClassA” — Method “MethodB” — BlockStatment — IfElseBlockStatment — VariableDeclaraion “varStr”; It can be seen that , The root node of this tree is the class declaration , A child node is a function in a class , Mobile network type if sentence , Variables and other elements .
How to use PMD
Download binary compression package
We from Released version link Download the latest binary compressed package , Then extract it locally :
After decompression , Carry out orders bin/run.sh pmd Or bin\pmd.bat. Then the command line shown in the following picture , We can check for a specific code file , The following figure shows PMD Detected in the file 1 A violation of the rules :“for loop , Can be for-each Circular substitution ”:
Reference material
边栏推荐
- 【TcaplusDB知识库】查看tcapdir目录服务器
- rsync 远程同步(日落尤其温柔的人间皆是浪漫)
- [tcapulusdb knowledge base] batch copy the game area
- Tacacs+ server deployment
- 【TcaplusDB知识库】WebClient用户如何读取和修改数据
- 【TcaplusDB知识库】修改业务修改集群cluster
- Cardinality sorting - common sorting method (2/8)
- 如何登录到你的 WordPress 管理仪表板
- AutoSAR 软件开发培训
- Visubit "ai+3d vision" product series | loading assembly workstation
猜你喜欢

Free, powerful and high-value note taking software evaluation: OneNote, heptabase, hydrogen graph, flowus

天翼云Web应用防火墙(边缘云版)通过首批可信认证

Potplayer play Baidu Cloud disk video

Log management in MySQL log backup and recovery

'summary of common network protocols' summarized by Tsinghua leaders in 3 days

Csp-j1 csp-s1 preliminary training plan and learning points in summer and September 2022

rsync 远程同步(日落尤其温柔的人间皆是浪漫)

Curve 替换 Ceph 在网易云音乐的实践

批量修改指定字符文件名 bat脚本

这个简单的小功能,半年为我们产研团队省下213个小时
随机推荐
Must the database primary key be self incremented? What scenarios do not suggest self augmentation? ByteDance experience sharing using Flink state 𞓜 afternoon tea with sauce issue 16
Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush
[tcapulusdb knowledge base] how webclient users read and modify data
Redis持久化(少年一贯快马扬帆,道阻且长不转弯)
手机买场内基金开户选哪家证券公司比较好,比较安全呢
55. maximum sum of continuous subarrays
区间乘积的因子数之和
ICML 2022 | 基于解耦梯度优化的可迁移模仿学习方法
12 SQL optimization schemes summarized by old drivers (very practical)
Flex布局
「科普大佬说」 智能仿生机器鱼
It's completely cold! Tencent's well-known software was taken off the shelves, and netizens were all sobbing...
Krack based network attack "suggestions collection"
[tcapulusdb knowledge base] how webclient users read and modify data
免费、强大、高颜值的笔记软件评测: OneNote、Heptabase、氢图、FlowUs
Lucky draw animation - Carp jumps over the dragon's gate
Super detailed steps for MySQL master-slave switching
EasyCVR播放视频出现卡顿花屏时如何解决?
Inspur network wins step by step
【TcaplusDB知识库】WebClient用户如何读取和修改数据