当前位置:网站首页>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
边栏推荐
- What is the reason why easycvr can't watch the device video when it is connected to the home protocol?
- ICML 2022 | 基于解耦梯度优化的可迁移模仿学习方法
- [daily 3 questions (2)] maximum ascending subarray sum
- 从入门到精通|Yalmip+Cplex在电力系统中的应用(超棒,看不懂算我输,没有收获也算我输)
- MySQL高可用之MHA(一不小心和我的青春擦肩而過)
- 强化 WordPress 的 11 种有效方法
- Metaq installation deployment document
- 【每日3题(3)】符串中不同整数的数目
- Tacacs+服务器部署
- [tcapulusdb knowledge base] tcapulusdb technical support introduction
猜你喜欢
![[tcapulusdb knowledge base] tcapulusdb technical support introduction](/img/ae/9295c8ae642cde632d06966c28d342.png)
[tcapulusdb knowledge base] tcapulusdb technical support introduction

Flex layout

PotPlayer播放百度云盘视频
![[tcapulusdb knowledge base] Introduction to tcapulusdb restrictions](/img/d3/27f09f7f5ab8e27d1ab87a35a9c0f3.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb restrictions

Practice of curve replacing CEPH in Netease cloud music

12 SQL optimization schemes summarized by old drivers (very practical)

关于接口测试自动化的总结与思考

AutoSAR 软件开发培训

Introduction to LTSpice circuit simulation

"Popular science leaders say" intelligent bionic robot fish
随机推荐
NoSQL之Redis配置与优化(你不在南京的日子我替你吹了秦淮河的晚风)
MySQL中的日志管理 日志备份与恢复
本地部署Confluence遇到的问题:MySQL数据库编码、隔离级别、验证码不显示
【离散数学】单射、满射与双射
基于Krack的网络攻击「建议收藏」
[daily 3 questions (1)] the second largest number in the string
怎么期货开户?在哪里期货开户比较安全?
如何备份 WordPress 数据库
DPDK 20.11编译安装运行程序
Flex布局
编写自己的 WordPress 模板
共享主机和 WordPress 主机之间的区别
R 编程语言 - 简介
使用Karmada实现Helm应用的跨集群部署
AutoSAR 软件开发培训
Batchnorm2d principle, function and explanation of batchnorm2d function parameters in pytorch
【刷题日记】和为 K 的子数组
LTspice 电路仿真入门
强化 WordPress 的 11 种有效方法
55. 连续子数组的最大和