码迷,mamicode.com
首页 > 其他好文 > 详细

PMD教程

时间:2017-04-24 09:57:50      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:建议   gobject   cal   object   objects   方法   输出   anti   解决   


1.单词
violations outline:错误大纲
2.错误级别
红色
很高的错误
橙色
错误
黄色
很高的警告
绿色
警告
蓝色
输出信息
3.提示
Avoid excessively long variable names like machineLineService
避免像machineLineService的命名
Local variable ‘queryString‘ could be declared fina
变量应该定义为final
Package name contains upper case characters
包名不应该大写
- Avoid instantiating new objects
inside loops
避免再循环中重复的构建实例
parameter ‘ch‘ is not assigned and could be declared final
参数不分,可以声明为final
Variables that are not final should not contain underscores (except for underscores in standard prefix/suffix).
不是最终的变量不应该带有下划线
Assigning an Object to null is a code smell. Consider
refactoring.
为分配一个对象的代码认为时重构的
得出来的规范
1.变量名字要短
2.不变的string变量要定义为final
3.包名不应该大写
4.最终的变量应该多次命名应该带有下划线
5.avoid循环重复new对象
6.不应该多用括号
7.一个方法应该只有一个返回点
8.使用集合的类的isEmpty()判断集合是否为空
9.符号之间的要空格
10.捕捉了异常再抛出了异常
11.如果字符串的变量多次使用,那么定义为常量
12.不要实例化Sting对象,那样会破坏享元策略
13.方法的名字一定要第一个单词小写,之后每一个单词的首字母大写
14.
violations Overview
Element 包中类的建议提示
#Violations
建议级别
#Violations/LOC
#Violations/Method
Project
属于那个项目里边的
violations Overview 视图的提示
LongVariable
变量过长
MethodeArgumentCouldBeFinal
AvoidInstantiatingObjectsInLoops
循环中重复new对象
LocalVariableCouldBeFinal
变量定义应该用final
使用的时候检测错误有没有解决就手动 在Violations Overview中右键类选择check code with pmd
优化策略
1.避免多个返回点
2.简化if-else 如果出现在返回值时,返回决定
3.不要给Boolean,Integer和String 类型创建新的实例
4.以final类型标记方法参数
5.switch里面要有default
6.final只会负责不可变他负责的那一片内存地址

PMD教程

标签:建议   gobject   cal   object   objects   方法   输出   anti   解决   

原文地址:http://www.cnblogs.com/thehugo/p/6755114.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!