From 25592524c31f7cb5434bba32a14dba73db8d4004 Mon Sep 17 00:00:00 2001 From: Martin Dietze Date: Mon, 8 Apr 2019 15:01:56 +0200 Subject: [PATCH] Issue #734: New check 'Jsr305AnnotationsCheck' --- .../coding/checkstyle-metadata.properties | 7 + .../checks/coding/checkstyle-metadata.xml | 43 + sevntu-checks/pom.xml | 13 + sevntu-checks/sevntu-checks.xml | 8 + .../checks/coding/Jsr305AnnotationsCheck.java | 1043 +++++++++++++++++ .../checks/coding/messages.properties | 25 + .../coding/Jsr305AnnotationsCheckTest.java | 565 +++++++++ .../coding/Jsr305AnnotionsTestUtil.java | 267 +++++ .../checks/coding/test/ArraysTestObject.java | 140 +++ .../checks/coding/test/ClassTestObject.java | 195 +++ .../coding/test/ConstructorTestObject.java | 107 ++ .../test/DefaultReturnValuesTestObject.java | 42 + .../test/DefectConstructorTestObject.java | 37 + .../checks/coding/test/EnumTestObject.java | 96 ++ .../coding/test/InheritanceTestObject.java | 117 ++ .../checks/coding/test/LambdaTestObject.java | 49 + .../coding/test/ParameterTestObject.java | 112 ++ .../coding/test/PrimitivesTestObject.java | 120 ++ .../test/RedundantClassLevelTestObject.java | 38 + .../coding/test/ReturnValueTestObject.java | 129 ++ .../main/resources/checkstyle_packages.xml | 2 +- .../sonar/checkstyle-extensions.xml | 25 + 22 files changed, 3179 insertions(+), 1 deletion(-) create mode 100644 sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheck.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheckTest.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotionsTestUtil.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/ArraysTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/ClassTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/ConstructorTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/DefaultReturnValuesTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/DefectConstructorTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/EnumTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/InheritanceTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/LambdaTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/ParameterTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/PrimitivesTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/RedundantClassLevelTestObject.java create mode 100644 sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/test/ReturnValueTestObject.java diff --git a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/coding/checkstyle-metadata.properties b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/coding/checkstyle-metadata.properties index e7efd317dd..d6f785e827 100755 --- a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/coding/checkstyle-metadata.properties +++ b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/coding/checkstyle-metadata.properties @@ -188,3 +188,10 @@ MoveVariableInsideIfCheck.desc = Checks if a variable is only used inside if sta RequireFailForTryCatchInJunitCheck.name = Require Fail For Try/Catch in JUnit Check RequireFailForTryCatchInJunitCheck.desc = Checks if a try/catch block has a junit fail assertion inside the try for a junit method. + +Jsr305AnnotationsCheck.name=Jsr305AnnotationsCheck +Jsr305AnnotationsCheck.desc=Checks method parameters and return values for the presence of @Nonnull, @Nullable, or @CheckForNull annotations. +Jsr305AnnotationsCheck.packages=Packages to be checked. +Jsr305AnnotationsCheck.excludePackages=Packages excluded from checking. +Jsr305AnnotationsCheck.allowOverridingReturnValue=Allow Overriding return values, useful for upgrading. +Jsr305AnnotationsCheck.allowOverridingParameter=Allow Overriding paramaters, useful for upgrading. diff --git a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/coding/checkstyle-metadata.xml b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/coding/checkstyle-metadata.xml index 3392c3bec1..6fa4dda594 100644 --- a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/coding/checkstyle-metadata.xml +++ b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/coding/checkstyle-metadata.xml @@ -556,5 +556,48 @@ + + + %Jsr305AnnotationsCheck.desc + + %Jsr305AnnotationsCheck.packages + + + %Jsr305AnnotationsCheck.excludePackages + + + %Jsr305AnnotationsCheck.allowOverridingReturnValue + + + %Jsr305AnnotationsCheck.allowOverridingParameter + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sevntu-checks/pom.xml b/sevntu-checks/pom.xml index 51520c4a20..7298767531 100644 --- a/sevntu-checks/pom.xml +++ b/sevntu-checks/pom.xml @@ -45,6 +45,17 @@ test ${checkstyle.eclipse-cs.version} + + + com.google.code.findbugs + jsr305 + 3.0.1 + + + com.google.code.findbugs + annotations + 3.0.1 + junit junit @@ -283,6 +294,8 @@ .*.checks.coding.MapIterationInForEachLoopCheck9098 .*.checks.coding.NoNullForCollectionReturnCheck8596 .*.checks.coding.OverridableMethodInConstructorCheck9499 + .*.checks.coding.Jsr305AnnotationsCheck8493 + .*.checks.coding.Jsr305AnnotationsCheck.AbstractJsr305Check9598 .*.checks.design.HideUtilityClassConstructorCheck94100 diff --git a/sevntu-checks/sevntu-checks.xml b/sevntu-checks/sevntu-checks.xml index d4c7612e18..dacefc8868 100644 --- a/sevntu-checks/sevntu-checks.xml +++ b/sevntu-checks/sevntu-checks.xml @@ -216,6 +216,14 @@ + + + + + + + +