diff --git a/.gitignore b/.gitignore index 08a3264a6..86c371fbf 100644 --- a/.gitignore +++ b/.gitignore @@ -93,3 +93,6 @@ hsf.configuration/ *.instance out !/p3c-idea/src/main/kotlin/com/alibaba/smartfox/work/tools/aone/ui/AoneBranchView.kt + +#versions-maven-plugin +*.versionsBackup \ No newline at end of file diff --git a/build.cmd b/build.cmd new file mode 100644 index 000000000..e18f2840d --- /dev/null +++ b/build.cmd @@ -0,0 +1,17 @@ +cd ./p3c-pmd +call mvn clean install -Dmaven.javadoc.skip=false -e +cd ../ +cd ./idea-plugin + +cd ./p3c-common +call ../gradlew publishToMavenLocal +cd ../ + +cd ./p3c-idea +call ../gradlew publishToMavenLocal +cd ../ + +call ./gradlew buildPlugin + +cd ../ +pause diff --git a/eclipse-plugin/com.alibaba.smartfox.eclipse.plugin/src/main/kotlin/com/alibaba/smartfox/eclipse/pmd/RulePriority.kt b/eclipse-plugin/com.alibaba.smartfox.eclipse.plugin/src/main/kotlin/com/alibaba/smartfox/eclipse/pmd/RulePriority.kt index 260ffc15c..bafd984cf 100644 --- a/eclipse-plugin/com.alibaba.smartfox.eclipse.plugin/src/main/kotlin/com/alibaba/smartfox/eclipse/pmd/RulePriority.kt +++ b/eclipse-plugin/com.alibaba.smartfox.eclipse.plugin/src/main/kotlin/com/alibaba/smartfox/eclipse/pmd/RulePriority.kt @@ -17,7 +17,11 @@ package com.alibaba.smartfox.eclipse.pmd enum class RulePriority(val priority: Int, val title: String) { - Blocker(1, "Blocker"), Critical(2, "Critical"), Major(3, "Major"); + Blocker(1, "Blocker"), + Critical(2, "Critical"), + Major(3, "Major"), + Warning(4, "Warning"), + WeakWarning(5, "Weak Warning"); override fun toString(): String { return title @@ -28,7 +32,7 @@ enum class RulePriority(val priority: Int, val title: String) { try { return RulePriority.values()[priority - 1] } catch (e: ArrayIndexOutOfBoundsException) { - return Major + return WeakWarning } } } diff --git a/eclipse-plugin/com.alibaba.smartfox.eclipse.plugin/src/main/kotlin/com/alibaba/smartfox/eclipse/ui/InspectionResults.kt b/eclipse-plugin/com.alibaba.smartfox.eclipse.plugin/src/main/kotlin/com/alibaba/smartfox/eclipse/ui/InspectionResults.kt index 3e1482081..8df16ebfc 100644 --- a/eclipse-plugin/com.alibaba.smartfox.eclipse.plugin/src/main/kotlin/com/alibaba/smartfox/eclipse/ui/InspectionResults.kt +++ b/eclipse-plugin/com.alibaba.smartfox.eclipse.plugin/src/main/kotlin/com/alibaba/smartfox/eclipse/ui/InspectionResults.kt @@ -98,6 +98,8 @@ object InspectionResults { return "${map[RulePriority.Blocker.title]?.count ?: 0} Blockers," + "${map[RulePriority.Critical.title]?.count ?: 0} Criticals," + - "${map[RulePriority.Major.title]?.count ?: 0} Majors" + "${map[RulePriority.Major.title]?.count ?: 0} Majors," + + "${map[RulePriority.Warning.title]?.count ?: 0} Warnings," + + "${map[RulePriority.WeakWarning.title]?.count ?: 0} Weak Warnings" } } diff --git a/eclipse-plugin/pom.xml b/eclipse-plugin/pom.xml index b93603c17..591fe6eb8 100644 --- a/eclipse-plugin/pom.xml +++ b/eclipse-plugin/pom.xml @@ -11,9 +11,9 @@ 1.0.0 ${tycho.version} - http://download.eclipse.org/releases/neon + https://download.eclipse.org/releases/neon UTF-8 - http://download.eclipse.org/tools/ajdt/46/dev/update + https://download.eclipse.org/tools/ajdt/46/dev/update 1.3.30 juno @@ -44,7 +44,7 @@ juno p2 - http://mirrors.ustc.edu.cn/eclipse/releases/juno/ + https://mirrors.ustc.edu.cn/eclipse/releases/juno/ sonatype-nexus-snapshots @@ -187,7 +187,7 @@ none - http://download.eclipse.org/eclipse/updates/4.4 + https://download.eclipse.org/eclipse/updates/4.4 diff --git a/idea-plugin/README_cn.md b/idea-plugin/README_cn.md index 90ab1feb9..f9242f7e3 100644 --- a/idea-plugin/README_cn.md +++ b/idea-plugin/README_cn.md @@ -93,7 +93,7 @@ Alt+Enter键可呼出Intention菜单,不同的规则会提示不同信息的Qu ![](https://gw.alicdn.com/tfscom/TB1ObqXifxNTKJjy0FjXXX6yVXa.png) #### 扫描结果 -检测结果直接使用IDEA Run Inspection By Name功能的结果界面,插件的检测结果分级为Blocker、Critical、Major。默认按等级分组,方便统计每个级别错误的数量。 +检测结果直接使用IDEA Run Inspection By Name功能的结果界面,插件的检测结果分级为Blocker、Critical、Major、Warning、Weak Warning。默认按等级分组,方便统计每个级别错误的数量。 ![](https://gw.alicdn.com/tfscom/TB1aC1yifJNTKJjSspoXXc6mpXa.png) diff --git a/idea-plugin/gradle.properties b/idea-plugin/gradle.properties index 3b8d8f0a7..3ac1ae6af 100644 --- a/idea-plugin/gradle.properties +++ b/idea-plugin/gradle.properties @@ -11,4 +11,4 @@ idea_version=IU-201.6668.121 plugin_name=Alibaba Java Coding Guidelines gradle_jetbrains_version=0.4.16 systemProp.file.encoding=UTF-8 -plugin_version=2.0.1.1x +plugin_version=2.0.1.2x-SNAPSHOT diff --git a/idea-plugin/p3c-common/build.gradle b/idea-plugin/p3c-common/build.gradle index 3d457b0a5..eb1c6fe68 100644 --- a/idea-plugin/p3c-common/build.gradle +++ b/idea-plugin/p3c-common/build.gradle @@ -50,9 +50,9 @@ version '2.0.1' ext.isReleaseVersion = !version.endsWith("SNAPSHOT") dependencies { - compile group: 'org.freemarker', name: 'freemarker', version: '2.3.25-incubating' - compile 'com.alibaba.p3c:p3c-pmd:2.0.1.1x' - compile group: 'org.javassist', name: 'javassist', version: '3.21.0-GA' + compile group: 'org.freemarker', name: 'freemarker', version: '2.3.30' + compile 'com.alibaba.p3c:p3c-pmd:2.0.1.2x-SNAPSHOT' + compile group: 'org.javassist', name: 'javassist', version: '3.27.0-GA' } uploadArchives { diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/activity/CommonSettingsApplicationStartupActivity.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/activity/CommonSettingsApplicationStartupActivity.kt index cc56164a2..8233f2d02 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/activity/CommonSettingsApplicationStartupActivity.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/activity/CommonSettingsApplicationStartupActivity.kt @@ -31,7 +31,7 @@ import com.intellij.openapi.project.Project * @author caikang * @date 2017/06/19 */ -class CommonSettingsApplicationStartupActivity() : AliBaseApplicationStartupActivity { +class CommonSettingsApplicationStartupActivity : AliBaseApplicationStartupActivity { companion object { val analyticsGroupId = "com.alibaba.p3c.analytics.action_group" val analyticsGroupText = "$analyticsGroupId.text" @@ -42,6 +42,8 @@ class CommonSettingsApplicationStartupActivity() : AliBaseApplicationStartupActi SeverityRegistrar.registerStandard(HighlightInfoTypes.BLOCKER, HighlightSeverities.BLOCKER) SeverityRegistrar.registerStandard(HighlightInfoTypes.CRITICAL, HighlightSeverities.CRITICAL) SeverityRegistrar.registerStandard(HighlightInfoTypes.MAJOR, HighlightSeverities.MAJOR) + SeverityRegistrar.registerStandard(HighlightInfoTypes.WARNING, HighlightSeverities.WARNING) + SeverityRegistrar.registerStandard(HighlightInfoTypes.WEAK_WARNING, HighlightSeverities.WEAK_WARNING) I18nResources.changeLanguage(p3cConfig.locale) val analyticsGroup = ActionManager.getInstance().getAction(analyticsGroupId) diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/PmdRuleInspectionIdentify.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/PmdRuleInspectionIdentify.kt index b84b5bd36..c3043f366 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/PmdRuleInspectionIdentify.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/PmdRuleInspectionIdentify.kt @@ -22,5 +22,4 @@ package com.alibaba.p3c.idea.inspection * @date 2017/03/16 6 */ -interface PmdRuleInspectionIdentify { -} \ No newline at end of file +interface PmdRuleInspectionIdentify \ No newline at end of file diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/RuleInspectionUtils.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/RuleInspectionUtils.kt index 3f0693d76..c8d82eb66 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/RuleInspectionUtils.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/inspection/RuleInspectionUtils.kt @@ -95,7 +95,9 @@ object RuleInspectionUtils { when (rulePriority) { RulePriority.HIGH -> return HighlightDisplayLevels.BLOCKER RulePriority.MEDIUM_HIGH -> return HighlightDisplayLevels.CRITICAL - else -> return HighlightDisplayLevels.MAJOR + RulePriority.MEDIUM -> return HighlightDisplayLevels.MAJOR + RulePriority.MEDIUM_LOW -> return HighlightDisplayLevels.WARNING + else -> return HighlightDisplayLevels.WEAK_WARNING } } @@ -110,8 +112,7 @@ object RuleInspectionUtils { map.put("message", StringUtils.trimToEmpty(rule.message)) map.put("description", StringUtils.trimToEmpty(rule.description)) val examples = rule.examples.map { - it?.trim { - c -> + it?.trim { c -> c == '\n' } } diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightDisplayLevels.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightDisplayLevels.kt index 4c42da961..87afd7b68 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightDisplayLevels.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightDisplayLevels.kt @@ -27,4 +27,6 @@ object HighlightDisplayLevels { val BLOCKER = HighlightDisplayLevel(HighlightSeverities.BLOCKER, HighlightDisplayLevel.ERROR.icon) val CRITICAL = HighlightDisplayLevel(HighlightSeverities.CRITICAL, HighlightDisplayLevel.WARNING.icon) val MAJOR = HighlightDisplayLevel(HighlightSeverities.MAJOR, HighlightDisplayLevel.WEAK_WARNING.icon) + val WARNING = HighlightDisplayLevel(HighlightSeverities.WARNING, HighlightDisplayLevel.WEAK_WARNING.icon) + val WEAK_WARNING = HighlightDisplayLevel(HighlightSeverities.WEAK_WARNING, HighlightDisplayLevel.INFO.icon) } diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightInfoTypes.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightInfoTypes.kt index 16504ca8a..d93707878 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightInfoTypes.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightInfoTypes.kt @@ -31,4 +31,8 @@ object HighlightInfoTypes { CodeInsightColors.WARNINGS_ATTRIBUTES) val MAJOR: HighlightInfoType = HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverities.MAJOR, CodeInsightColors.WEAK_WARNING_ATTRIBUTES) + val WARNING: HighlightInfoType = HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverities.WARNING, + CodeInsightColors.WEAK_WARNING_ATTRIBUTES) + val WEAK_WARNING: HighlightInfoType = HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverities.WEAK_WARNING, + CodeInsightColors.INFO_ATTRIBUTES) } diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightSeverities.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightSeverities.kt index 5f75753ba..80017e281 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightSeverities.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/p3c/idea/util/HighlightSeverities.kt @@ -24,16 +24,14 @@ import com.intellij.lang.annotation.HighlightSeverity * @date 2017/02/04 */ object HighlightSeverities { + val BLOCKER = HighlightSeverity("BLOCKER", 399) + + val CRITICAL = HighlightSeverity("CRITICAL", 398) + val MAJOR = HighlightSeverity("MAJOR", 397) + val WARNING = HighlightSeverity("WARNING", 396) - /** - * The standard severity level for warning annotations. - */ - val CRITICAL = HighlightSeverity("CRITICAL", 398) + val WEAK_WARNING = HighlightSeverity("WEAK_WARNING", 395) - /** - * The standard severity level for error annotations. - */ - val BLOCKER = HighlightSeverity("BLOCKER", 399) } diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/smartfox/idea/common/activity/AliBaseApplicationStartupActivity.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/smartfox/idea/common/activity/AliBaseApplicationStartupActivity.kt index 45de082d4..13825f868 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/smartfox/idea/common/activity/AliBaseApplicationStartupActivity.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/smartfox/idea/common/activity/AliBaseApplicationStartupActivity.kt @@ -23,5 +23,4 @@ import com.intellij.openapi.startup.StartupActivity * @author caikang * @date 2017/05/11 */ -interface AliBaseApplicationStartupActivity : StartupActivity { -} \ No newline at end of file +interface AliBaseApplicationStartupActivity : StartupActivity \ No newline at end of file diff --git a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/smartfox/idea/common/util/BalloonNotifications.kt b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/smartfox/idea/common/util/BalloonNotifications.kt index 813da44d1..8c126cbf5 100644 --- a/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/smartfox/idea/common/util/BalloonNotifications.kt +++ b/idea-plugin/p3c-common/src/main/kotlin/com/alibaba/smartfox/idea/common/util/BalloonNotifications.kt @@ -102,7 +102,7 @@ object BalloonNotifications { object LogNotifications { - val group = buildNotificationGroup(displayId = BalloonNotifications.displayId, displayType = NotificationDisplayType.NONE, isLogByDefault = true); + val group = buildNotificationGroup(displayId = BalloonNotifications.displayId, displayType = NotificationDisplayType.NONE, isLogByDefault = true) fun log(message: String, project: Project? = ProjectManager.getInstance().defaultProject, title: String = BalloonNotifications.TITLE, @@ -118,8 +118,8 @@ fun buildNotificationGroup(displayId: String, displayType: NotificationDisplayTy notificationGroupClass.constructors.forEach { if (it.parameters.size == 3) { return it.newInstance(displayId, displayType, isLogByDefault) - as NotificationGroup; + as NotificationGroup } } - throw MethodNotSupportedException("cannot find a suitable constructor for NotificationGroup who accepts [String,NotificationDisplayType,Boolean]"); + throw MethodNotSupportedException("cannot find a suitable constructor for NotificationGroup who accepts [String,NotificationDisplayType,Boolean]") } diff --git a/idea-plugin/p3c-common/src/main/resources/messages/P3cBundle.xml b/idea-plugin/p3c-common/src/main/resources/messages/P3cBundle.xml index 438ba9469..1792436f3 100644 --- a/idea-plugin/p3c-common/src/main/resources/messages/P3cBundle.xml +++ b/idea-plugin/p3c-common/src/main/resources/messages/P3cBundle.xml @@ -4,8 +4,7 @@ 阿里编码规约 切换语言至英文(English) 切换语言至中文 - - 重启后生效]]> + 重启后生效]]> 编码规约扫描 关闭实时检测功能 打开实时检测功能 @@ -15,48 +14,28 @@ 修改为小写驼峰命名(lowerCamelCase) 为变量添加! 替换为 - 通过类 '%s' 直接访问静态成员 - '%s.%s' - + 通过类 '%s' 直接访问静态成员 '%s.%s' 添加 @Override 注解 为语句加上大括号 翻转 equals 调用 修改为 String[] str 模式 'l' 替换为 'L' - - #ref #loc]]> - - 避免通过一个类的对象引用访问此类的静态变量或静态方法,无谓增加编译器解析成本,直接用类名来访问即可。 - - 不应该通过类实例访问静态成员 - %s #loc - + #ref #loc]]> + 避免通过一个类的对象引用访问此类的静态变量或静态方法,无谓增加编译器解析成本,直接用类名来访问即可。 + 不应该通过类实例访问静态成员 %s #loc 不能使用过时的类或方法。 - - 所有的覆写方法,必须加@Override注解。 - - - #ref()缺少 '@Override' 注解 #loc]]> - - Map/Set的key为自定义对象时,必须重写hashCode和equals。 - - - 参数类型 %s 没有重写hashCode和equals #loc - - - #ref 是非线程安全的,请加锁或者使用局部变量 #loc]]> - - #ref 没有加大括号 #loc]]> - - #ref 应该作为方法 "%s()"的调用方,而不是参数 #loc]]> - - #ref 数组定义格式错误 #loc]]> - - #ref 应该以大写L结尾 #loc]]> - - #ref #loc]]> + 所有的覆写方法,必须加@Override注解。 + #ref()缺少 '@Override' 注解 #loc]]> + Map/Set的key为自定义对象时,必须重写hashCode和equals。 + 参数类型 %s 没有重写hashCode和equals #loc + #ref 是非线程安全的,请加锁或者使用局部变量 #loc]]> + #ref 没有加大括号 #loc]]> + #ref 应该作为方法 "%s()"的调用方,而不是参数 #loc]]> + #ref 数组定义格式错误 #loc]]> + #ref 应该以大写L结尾 #loc]]> + #ref #loc]]> @@ -81,8 +60,7 @@ ]]> - - Map/Set的key为自定义对象时,必须重写hashCode和equals。
diff --git a/idea-plugin/p3c-common/src/main/resources/messages/P3cBundle_en.xml b/idea-plugin/p3c-common/src/main/resources/messages/P3cBundle_en.xml index c6d7936f4..05b7ee145 100644 --- a/idea-plugin/p3c-common/src/main/resources/messages/P3cBundle_en.xml +++ b/idea-plugin/p3c-common/src/main/resources/messages/P3cBundle_en.xml @@ -4,68 +4,39 @@ Alibaba Coding Guidelines Switch language to English Switch language to Chinese - - restart to get effect.]]> + restart to get effect.]]> Alibaba Coding Guidelines Analyze - Close inspection on the fly - + Close inspection on the fly Open inspection on the fly Delete starting '$' or '_' Add/Extract @author - Refactor to upper case with underscore - + Refactor to upper case with underscore Refactor to lower camel case name Add '!' for variable Replace with - Access static '%s.%s' via - class '%s' reference. - - Add @Override - annotation - + Access static '%s.%s' via class '%s' reference. + Add @Override annotation Add braces to statement Flip 'equals()' - Replace with Java-style array - declaration - + Replace with Java-style array declaration Replace 'l' with 'L' - - #ref should replace with equals for wrapper type #loc]]> - A static field - or method should be directly referred by its class name instead of its corresponding object name. - - %s access static - member via class instance is prohibited #loc - + #ref should replace with equals for wrapper type #loc]]> + A static field or method should be directly referred by its class name instead of its corresponding object name. + %s access static member via class instance is prohibited #loc - Using a deprecated class or - method is prohibited. - - An overridden - method from an interface or abstract class must be marked with @Override annotation. - - - #ref() #loc]]> - - Custom class must override 'hashCode' and 'equals' while use as key for Map or value for Set. - - - Type of parameter %s does not override 'hashCode' and 'equals' #loc - - - #ref is unsafe,lock or use local variable #loc]]> - - #ref without braces #loc]]> - - #ref is argument of '%s()', instead of its target #loc]]> - - #ref ends with lowercase 'l' #loc]]> - - + Using a deprecated class or method is prohibited. + An overridden method from an interface or abstract class must be marked with @Override annotation. + #ref() #loc]]> + Custom class must override 'hashCode' and 'equals' while use as key for Map or value for Set. + Type of parameter %s does not override 'hashCode' and 'equals' #loc + #ref is unsafe,lock or use local variable #loc]]> + #ref without braces #loc]]> + #ref is argument of '%s()', instead of its target #loc]]> + #ref ends with lowercase 'l' #loc]]> + - - #ref #loc]]> + #ref #loc]]> @@ -90,8 +61,7 @@ Counter example: For getObject() and get0bject(), the first one has a letter 'O' ]]> - - Custom class must override 'hashCode' and 'equals' while use as key for Map or value for Set.
diff --git a/idea-plugin/p3c-idea/build.gradle b/idea-plugin/p3c-idea/build.gradle index d6106e5a3..abbada233 100644 --- a/idea-plugin/p3c-idea/build.gradle +++ b/idea-plugin/p3c-idea/build.gradle @@ -26,8 +26,8 @@ intellij { version plugin_version dependencies { - compile group: 'org.freemarker', name: 'freemarker', version: '2.3.25-incubating' + compile group: 'org.freemarker', name: 'freemarker', version: '2.3.30' compile project(':p3c-common') - compile group: 'org.javassist', name: 'javassist', version: '3.21.0-GA' + compile group: 'org.javassist', name: 'javassist', version: '3.27.0-GA' } diff --git a/idea-plugin/p3c-idea/src/main/resources/META-INF/plugin.xml b/idea-plugin/p3c-idea/src/main/resources/META-INF/plugin.xml index d14ce4245..bb6b27e1a 100644 --- a/idea-plugin/p3c-idea/src/main/resources/META-INF/plugin.xml +++ b/idea-plugin/p3c-idea/src/main/resources/META-INF/plugin.xml @@ -29,7 +29,7 @@ - 2.0.1.1x + 2.0.1.2x-SNAPSHOT
  • Fix idea 2020.1 compatibility issue
  • fix javadoc in p3c-cmd
  • fix clinic dependency in p3c-cmd
  • @@ -104,8 +104,8 @@ - com.intellij.velocity - com.intellij.modules.java + com.intellij.velocity + com.intellij.modules.java com.intellij.modules.platform com.intellij.modules.lang com.intellij.modules.vcs diff --git a/idea-plugin/p3c-idea/src/main/resources/META-INF/pluginIcon.svg b/idea-plugin/p3c-idea/src/main/resources/META-INF/pluginIcon.svg new file mode 100644 index 000000000..ef6c8c07e --- /dev/null +++ b/idea-plugin/p3c-idea/src/main/resources/META-INF/pluginIcon.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/idea-plugin/p3c-idea/src/main/resources/META-INF/p3c.xml b/idea-plugin/p3c-idea/src/main/resources/META-INF/pluginWithJava.xml similarity index 100% rename from idea-plugin/p3c-idea/src/main/resources/META-INF/p3c.xml rename to idea-plugin/p3c-idea/src/main/resources/META-INF/pluginWithJava.xml diff --git a/idea-plugin/p3c-idea/src/main/resources/META-INF/pluginWithVelocity.xml b/idea-plugin/p3c-idea/src/main/resources/META-INF/pluginWithVelocity.xml new file mode 100644 index 000000000..6fb76a662 --- /dev/null +++ b/idea-plugin/p3c-idea/src/main/resources/META-INF/pluginWithVelocity.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/p3c-pmd/pom.xml b/p3c-pmd/pom.xml index 1ee28afaa..5abd4bee8 100644 --- a/p3c-pmd/pom.xml +++ b/p3c-pmd/pom.xml @@ -4,22 +4,39 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - org.sonatype.oss - oss-parent - 9 - com.alibaba.p3c p3c-pmd - 2.0.1.1x + 2.0.1.2x-SNAPSHOT jar p3c-pmd UTF-8 - 6.15.0 + UTF-8 + + UTF-8 + 8 + ${java.version} + ${java.version} + + + + 6.17.0 1.8 1.3.2 - 1.3.50 + 1.3.71 + + + + 2.7 + 2.1.2 + 2.7 + 1.1 + 3.13.0 + 3.8.1 + 3.2.0 + 3.1.1 + 3.0.0-M3 + 3.0.0-M1 Alibaba Java Coding Guidelines PMD implementations @@ -109,17 +126,156 @@ ${kotlin.version} + + + + update_dependencies + + + + + org.codehaus.mojo + versions-maven-plugin + ${versions-maven-plugin.version} + + false + + org.slf4j:* + net.sourceforge.pmd:* + + + + + initialize + + update-properties + + + + + + + + + + sonatype-oss-release + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + en + private + ../javadocs + ${project.build.sourceEncoding} + ${project.reporting.outputEncoding} + + -J-Duser.language=en_US + + + + + date + + + apiNote + a + API Note: + + + implSpec + a + Implementation Requirements: + + + implNote + a + Implementation Note: + + + param + + + return + + + throws + + + since + + + version + + + serialData + + + see + + + + ${maven.compiler.source} + + + + + + + + package + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + + + org.apache.maven.plugins maven-pmd-plugin - 3.11.0 + ${maven-pmd-plugin.version} ${project.build.sourceEncoding} ${maven.compiler.target} true + 2 rulesets/java/ali-comment.xml rulesets/java/ali-concurrent.xml @@ -190,7 +346,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + ${maven-compiler-plugin.version} ${maven.compiler.target} ${maven.compiler.target} @@ -224,8 +380,9 @@ + org.apache.maven.plugins maven-assembly-plugin - 3.0.0 + ${maven-assembly-plugin.version} jar-with-dependencies @@ -244,37 +401,132 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.4 + ${maven-javadoc-plugin.version} + + en + private + ../javadocs + ${project.build.sourceEncoding} + ${project.reporting.outputEncoding} + + -J-Duser.language=en_US + + + + + date + + + apiNote + a + API Note: + + + implSpec + a + Implementation Requirements: + + + implNote + a + Implementation Note: + + + param + + + return + + + throws + + + since + + + version + + + serialData + + + see + + + + ${maven.compiler.source} + + + + + - attach-javadocs + package jar + + + org.apache.maven.plugins + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + enforce-maven + + enforce + + + + + (,2.1.0),(2.1.0,2.2.0),(2.2.0,) + + Maven 2.1.0 and 2.2.0 produce + incorrect GPG signatures and checksums + respectively. + + + + + + + + + org.apache.maven.plugins + maven-release-plugin + ${maven-release-plugin.version} - - - date - - + forked-path + false + ${arguments} -Psonatype-oss-release + - + + + + central + http://central.maven.org/maven2/ + + + + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/I18nResources.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/I18nResources.java index c6c4973f4..8d6351851 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/I18nResources.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/I18nResources.java @@ -37,11 +37,11 @@ public class I18nResources { private static final String XML_LITERAL = "xml"; - private static String lang = System.getProperty("pmd.language", "zh"); + private static final String LANG = System.getProperty("pmd.language", "zh"); private static Locale currentLocale; - private static ResourceBundle resourceBundle = changeLanguage(lang); + private static ResourceBundle resourceBundle = changeLanguage(LANG); public static ResourceBundle changeLanguage(String language) { Locale locale = Locale.CHINESE.getLanguage().equals(language) ? Locale.CHINESE : Locale.ENGLISH; @@ -90,7 +90,7 @@ public static String getMessageWithExceptionHandled(String key) { } public static class XmlResourceBundle extends ResourceBundle { - private Properties props; + private final Properties props; XmlResourceBundle(InputStream stream) throws IOException { props = new Properties(); diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/concurrent/ThreadShouldSetNameRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/concurrent/ThreadShouldSetNameRule.java index efbe4c563..7b49ef21f 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/concurrent/ThreadShouldSetNameRule.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/concurrent/ThreadShouldSetNameRule.java @@ -113,11 +113,10 @@ private boolean checkThreadFactoryArgument(ASTExpression expression) { ASTLambdaExpression lambdaExpression = expression.getFirstDescendantOfType(ASTLambdaExpression.class); if (lambdaExpression != null) { return isThreadFactoryLambda(lambdaExpression); - } else if (expression.getType() != null - && RejectedExecutionHandler.class.isAssignableFrom(expression.getType())) { - return false; + } else { + return expression.getType() == null + || !RejectedExecutionHandler.class.isAssignableFrom(expression.getType()); } - return true; } private boolean isThreadFactoryLambda(ASTLambdaExpression lambdaExpression) { diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/naming/ClassNamingShouldBeCamelRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/naming/ClassNamingShouldBeCamelRule.java index 57ead3df3..964a0d004 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/naming/ClassNamingShouldBeCamelRule.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/naming/ClassNamingShouldBeCamelRule.java @@ -34,7 +34,7 @@ public class ClassNamingShouldBeCamelRule extends AbstractAliRule { private static final Pattern PATTERN - = Pattern.compile("^I?([A-Z][a-z0-9]+)+(([A-Z])|(DO|DTO|VO|DAO|BO|DAOImpl|YunOS|AO|PO))?$"); + = Pattern.compile("^I?([A-Z][a-z0-9]+)+(([A-Z])|(DO|DTO|VO|DAO|BO|DAOImpl|YunOS|AO|PO|DOMapper))?$"); private static final List CLASS_NAMING_WHITE_LIST = NameListConfig.NAME_LIST_SERVICE.getNameList( ClassNamingShouldBeCamelRule.class.getSimpleName(), "CLASS_NAMING_WHITE_LIST"); diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/naming/LowerCamelCaseVariableNamingRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/naming/LowerCamelCaseVariableNamingRule.java index e009beff4..c2efb7b65 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/naming/LowerCamelCaseVariableNamingRule.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/naming/LowerCamelCaseVariableNamingRule.java @@ -39,7 +39,7 @@ public class LowerCamelCaseVariableNamingRule extends AbstractAliRule { private static final String MESSAGE_KEY_PREFIX = "java.naming.LowerCamelCaseVariableNamingRule.violation.msg"; - private Pattern pattern = Pattern.compile("^[a-z][a-z0-9]*([A-Z][a-z0-9]+)*(DO|DTO|VO|DAO|BO|DOList|DTOList|VOList|DAOList|BOList|X|Y|Z|UDF|UDAF|[A-Z])?$"); + private final Pattern pattern = Pattern.compile("^[a-z][a-z0-9]*([A-Z][a-z0-9]+)*(DO|DTO|VO|DAO|BO|DOList|DTOList|VOList|DAOList|BOList|X|Y|Z|UDF|UDAF|[A-Z])?$"); @Override public Object visit(final ASTVariableDeclaratorId node, Object data) { diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/oop/VarargsParameterRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/oop/VarargsParameterRule.java new file mode 100644 index 000000000..a44832732 --- /dev/null +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/oop/VarargsParameterRule.java @@ -0,0 +1,44 @@ +package com.alibaba.p3c.pmd.lang.java.rule.oop; + +/* + * Copyright 1999-2017 Alibaba Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.alibaba.p3c.pmd.I18nResources; +import com.alibaba.p3c.pmd.lang.AbstractXpathRule; +import com.alibaba.p3c.pmd.lang.java.util.ViolationUtils; +import net.sourceforge.pmd.lang.ast.Node; + +/** + * [Mandatory] + * + * @author leonard99559 + * @date 2019/10/16 + */ +public class VarargsParameterRule extends AbstractXpathRule { + private static final String XPATH = "//FormalParameter[@Varargs = 'true' and ./Type[@TypeImage = 'Object']]"; + + public VarargsParameterRule() { + setXPath(XPATH); + } + + @Override + public void addViolation(Object data, Node node, String arg) { + ViolationUtils.addViolationWithPrecisePosition(this, node, data, + I18nResources.getMessage("java.oop.VarargsParameterRule.rule.msg", + node.getImage())); + } + +} \ No newline at end of file diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/other/AvoidApacheBeanUtilsCopyRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/other/AvoidApacheBeanUtilsCopyRule.java index 4ad8568de..dd4bd042a 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/other/AvoidApacheBeanUtilsCopyRule.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/other/AvoidApacheBeanUtilsCopyRule.java @@ -30,8 +30,9 @@ */ public class AvoidApacheBeanUtilsCopyRule extends AbstractXpathRule { private static final String XPATH = - "//PrimaryPrefix/Name[@Image='BeanUtils.copyProperties' and " - + "//ImportDeclaration[@ImportedName='org.apache.commons.beanutils.BeanUtils']]"; + "//PrimaryPrefix/Name[(@Image='BeanUtils.copyProperties' and " + + "//ImportDeclaration[@ImportedName='org.apache.commons.beanutils.BeanUtils']) or " + + "starts-with(@Image,'org.apache.commons.beanutils.BeanUtils.copyProperties')]"; public AvoidApacheBeanUtilsCopyRule() { setXPath(XPATH); diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/ConcurrentExceptionWithModifyOriginSubListRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/ConcurrentExceptionWithModifyOriginSubListRule.java index 3aeaf647b..9198d17d5 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/ConcurrentExceptionWithModifyOriginSubListRule.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/ConcurrentExceptionWithModifyOriginSubListRule.java @@ -96,14 +96,11 @@ private String getBeforeSubListVal(String image) { * @param variableName * @param item * @return - * @throws JaxenException */ private boolean checkBlockNodesValid(String variableName, Node item) { if (item instanceof ASTName) { String name = item.getImage(); - if (judgeName(name, variableName)) { - return true; - } + return judgeName(name, variableName); } return false; } diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/EqualsHashCodeRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/EqualsHashCodeRule.java new file mode 100644 index 000000000..810e5caab --- /dev/null +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/EqualsHashCodeRule.java @@ -0,0 +1,51 @@ +package com.alibaba.p3c.pmd.lang.java.rule.set; + +/* + * Copyright 1999-2017 Alibaba Group. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.alibaba.p3c.pmd.lang.java.rule.AbstractAliRule; +import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; +import org.jaxen.JaxenException; + +import java.util.List; + +/** + * [Mendatory] Equals method must be with hashCode() method. + * + * @author leonard99559 + * @date 2019/10/16 + */ +public class EqualsHashCodeRule extends AbstractAliRule { + + @Override + public Object visit(ASTCompilationUnit rootNode, Object data) { + + try { + List nodeList = rootNode.findChildNodesWithXPath( + "//ClassOrInterfaceBodyDeclaration[./Annotation[@AnnotationName = 'Override']]" + + "//MethodDeclaration[@MethodName = 'hashCode' or @MethodName = 'equals']"); + if (nodeList.size() == 1) { + addViolationWithMessage(data, nodeList.get(0), + "java.set.EqualsHashCodeRule.rule.msg"); + } + } catch (JaxenException e) { + e.printStackTrace(); + } + return super.visit(rootNode, data); + } + +} diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/UnsupportedExceptionWithModifyAsListRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/UnsupportedExceptionWithModifyAsListRule.java index 17f48f328..65c75fadb 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/UnsupportedExceptionWithModifyAsListRule.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/set/UnsupportedExceptionWithModifyAsListRule.java @@ -98,14 +98,11 @@ public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { * @param variableName * @param item * @return - * @throws JaxenException */ private boolean checkBlockNodesValid(String variableName, Node item) { if (item instanceof ASTName) { String name = item.getImage(); - if (judgeName(name, variableName)) { - return true; - } + return judgeName(name, variableName); } return false; } diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/util/namelist/NameListServiceImpl.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/util/namelist/NameListServiceImpl.java index 186458aee..65b5da548 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/util/namelist/NameListServiceImpl.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/util/namelist/NameListServiceImpl.java @@ -61,7 +61,7 @@ public Map getNameMap(String className, String name, Class kClas } private static class LinkedProperties extends Properties { - private LinkedHashSet linkedKeys = new LinkedHashSet<>(); + private final LinkedHashSet linkedKeys = new LinkedHashSet<>(); @Override public Object put(Object key, Object value) { diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/vm/rule/other/UseQuietReferenceNotationRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/vm/rule/other/UseQuietReferenceNotationRule.java index 736b7b364..acb268854 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/vm/rule/other/UseQuietReferenceNotationRule.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/vm/rule/other/UseQuietReferenceNotationRule.java @@ -15,12 +15,8 @@ */ package com.alibaba.p3c.pmd.lang.vm.rule.other; -import java.util.List; -import java.util.regex.Pattern; - import com.alibaba.p3c.pmd.I18nResources; import com.alibaba.p3c.pmd.lang.AbstractXpathRule; - import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.vm.ast.ASTDirective; @@ -28,6 +24,11 @@ import net.sourceforge.pmd.lang.vm.ast.Token; import net.sourceforge.pmd.lang.vm.ast.VmParserConstants; +import java.util.List; +import java.util.regex.Pattern; + +import static net.sourceforge.pmd.lang.rule.xpath.XPathRuleQuery.XPATH_1_0; + /** * [Mandatory] Variables must add exclamatory mark when passing to velocity engine from backend, like $!{var}. * Note: If attribute is null or does not exist, ${var} will be shown directly on web pages. @@ -48,10 +49,11 @@ public class UseQuietReferenceNotationRule extends AbstractXpathRule { * Check reference between two text nodes. Exclude references scan in method. */ private static final String XPATH = - "//Reference[matches(@literal, \"^\\$[^!]+\") and ./preceding-sibling::Text and ./following-sibling::Text]"; + "//Reference[matches(@literal, \"^\\$[^!]+\") and ./preceding-sibling::Text and ./following-sibling::Text]"; public UseQuietReferenceNotationRule() { setXPath(XPATH); + this.setVersion(XPATH_1_0); } @Override @@ -74,7 +76,7 @@ public void evaluate(Node node, RuleContext ctx) { @Override public void addViolation(Object data, Node node, String arg) { - String name = getIdentifyName((AbstractVmNode)node); + String name = getIdentifyName((AbstractVmNode) node); String text = I18nResources.getMessage("vm.other.UseQuietReferenceNotationRule.violation.msg", name); addViolationWithMessage(data, node, text); } diff --git a/p3c-pmd/src/main/resources/messages.xml b/p3c-pmd/src/main/resources/messages.xml index 848f3edd7..8a6846994 100644 --- a/p3c-pmd/src/main/resources/messages.xml +++ b/p3c-pmd/src/main/resources/messages.xml @@ -269,6 +269,15 @@ + + + @@ -357,6 +366,9 @@ + + + diff --git a/p3c-pmd/src/main/resources/messages_en.xml b/p3c-pmd/src/main/resources/messages_en.xml index 9491ff065..e418db71e 100644 --- a/p3c-pmd/src/main/resources/messages_en.xml +++ b/p3c-pmd/src/main/resources/messages_en.xml @@ -270,6 +270,15 @@ Explain 3: It is possible that when implementing the lock() method in Lock objec + + + @@ -356,6 +365,9 @@ Explain 3: It is possible that when implementing the lock() method in Lock objec + + + diff --git a/p3c-pmd/src/main/resources/rulesets/java/ali-oop.xml b/p3c-pmd/src/main/resources/rulesets/java/ali-oop.xml index 77ce92875..a663b31b3 100644 --- a/p3c-pmd/src/main/resources/rulesets/java/ali-oop.xml +++ b/p3c-pmd/src/main/resources/rulesets/java/ali-oop.xml @@ -153,5 +153,21 @@ Positive example: ]]> + + 4 + + + + diff --git a/p3c-pmd/src/main/resources/rulesets/java/ali-set.xml b/p3c-pmd/src/main/resources/rulesets/java/ali-set.xml index 1df62235e..6e1cd3196 100644 --- a/p3c-pmd/src/main/resources/rulesets/java/ali-set.xml +++ b/p3c-pmd/src/main/resources/rulesets/java/ali-set.xml @@ -129,5 +129,44 @@ Negative example: ]]> + + 1 + + + + diff --git a/p3c-pmd/src/test/java/com/alibaba/p3c/pmd/lang/java/rule/oop/OopRuleTest.java b/p3c-pmd/src/test/java/com/alibaba/p3c/pmd/lang/java/rule/oop/OopRuleTest.java index 9ab81aa27..47be8e49c 100644 --- a/p3c-pmd/src/test/java/com/alibaba/p3c/pmd/lang/java/rule/oop/OopRuleTest.java +++ b/p3c-pmd/src/test/java/com/alibaba/p3c/pmd/lang/java/rule/oop/OopRuleTest.java @@ -38,5 +38,6 @@ public void setUp() { addRule(RULESET, "PojoMustOverrideToStringRule"); addRule(RULESET, "StringConcatRule"); addRule(RULESET, "BigDecimalAvoidDoubleConstructorRule"); + addRule(RULESET, "VarargsParameterRule"); } } diff --git a/p3c-pmd/src/test/java/com/alibaba/p3c/pmd/lang/java/rule/set/SetRulesTest.java b/p3c-pmd/src/test/java/com/alibaba/p3c/pmd/lang/java/rule/set/SetRulesTest.java index b96c6e3e9..b3b736e14 100644 --- a/p3c-pmd/src/test/java/com/alibaba/p3c/pmd/lang/java/rule/set/SetRulesTest.java +++ b/p3c-pmd/src/test/java/com/alibaba/p3c/pmd/lang/java/rule/set/SetRulesTest.java @@ -35,5 +35,6 @@ public void setUp() { addRule(RULESET, "ConcurrentExceptionWithModifyOriginSubListRule"); addRule(RULESET, "DontModifyInForeachCircleRule"); addRule(RULESET, "UnsupportedExceptionWithModifyAsListRule"); + addRule(RULESET, "EqualsHashCodeRule"); } } diff --git a/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/oop/xml/VarargsParameterRule.xml b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/oop/xml/VarargsParameterRule.xml new file mode 100644 index 000000000..0db9bf1e7 --- /dev/null +++ b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/oop/xml/VarargsParameterRule.xml @@ -0,0 +1,27 @@ + + + + + + + + varargs-with-object-type + 1 + 2 + + + + + + \ No newline at end of file diff --git a/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/other/xml/AvoidApacheBeanUtilsCopyRule.xml b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/other/xml/AvoidApacheBeanUtilsCopyRule.xml index 727a9790e..fd48b92a8 100644 --- a/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/other/xml/AvoidApacheBeanUtilsCopyRule.xml +++ b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/other/xml/AvoidApacheBeanUtilsCopyRule.xml @@ -3,7 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests https://pmd.sourceforge.io/rule-tests_1_0_0.xsd"> - + + - + + + + Use Apache BeanUtils copy + 1 + 5 + + - - Use Apache BeanUtils copy - 1 - 5 - - + + + + Use Apache BeanUtils copy + 1 + 4 + + - + + + + Use Apache BeanUtils other + 0 + + + + - - - Use Spring BeanUtils copy - 0 - - + + + Use Spring BeanUtils copy + 0 + + + + + + + Use Not Apache BeanUtils copy + 0 + + diff --git a/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/set/xml/EqualsHashCodeRule.xml b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/set/xml/EqualsHashCodeRule.xml new file mode 100644 index 000000000..ffabef18c --- /dev/null +++ b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/set/xml/EqualsHashCodeRule.xml @@ -0,0 +1,80 @@ + + + + + + + + sets-EqualsHashCodeRule-ok. + 0 + + + + + + + + sets-EqualsHashCodeRule-missHashCodeWarn. + 1 + 5 + + + + + + + + sets-EqualsHashCodeRule-missEqualsWarn. + 1 + 5 + + +