From e32e6461693eb98b9a62a329097761a2457c02ba Mon Sep 17 00:00:00 2001 From: Martin Dietze Date: Wed, 15 May 2019 16:41:53 +0200 Subject: [PATCH] Issue #734: required changes to sevntu-checks.xml, increased test coverage, required javadoc --- .../checks/annotation/checkstyle-metadata.xml | 2 +- .../checks/coding/checkstyle-metadata.xml | 2 +- .../checks/design/checkstyle-metadata.xml | 2 +- .../checks/naming/checkstyle-metadata.xml | 2 +- .../checks/sizes/checkstyle-metadata.xml | 2 +- sevntu-checks/pom.xml | 3 +- sevntu-checks/sevntu-checks.xml | 2 +- .../checks/coding/Jsr305AnnotationsCheck.java | 236 ++++++++++-------- .../coding/Jsr305AnnotationsCheckTest.java | 33 +++ ...InputJsr305AnnotationsCheckWithArrays.java | 14 +- .../InputJsr305AnnotationsCheckWithClass.java | 22 +- ...Jsr305AnnotationsCheckWithConstructor.java | 8 +- ...notationsCheckWithDefaultReturnValues.java | 2 +- .../InputJsr305AnnotationsCheckWithEnum.java | 10 +- ...Jsr305AnnotationsCheckWithInheritance.java | 6 +- ...InputJsr305AnnotationsCheckWithLambda.java | 4 +- ...utJsr305AnnotationsCheckWithParameter.java | 10 +- ...tJsr305AnnotationsCheckWithPrimitives.java | 18 +- ...notationsCheckWithRedundantClassLevel.java | 2 +- ...Jsr305AnnotationsCheckWithReturnValue.java | 18 +- 20 files changed, 231 insertions(+), 167 deletions(-) diff --git a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/annotation/checkstyle-metadata.xml b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/annotation/checkstyle-metadata.xml index c2f55ecdac..dcada39336 100755 --- a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/annotation/checkstyle-metadata.xml +++ b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/annotation/checkstyle-metadata.xml @@ -1,7 +1,7 @@ +"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd"> 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 6fa4dda594..fcba5c0679 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 @@ -1,7 +1,7 @@ +"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd"> diff --git a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/design/checkstyle-metadata.xml b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/design/checkstyle-metadata.xml index b55cc10551..fed1a16517 100644 --- a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/design/checkstyle-metadata.xml +++ b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/design/checkstyle-metadata.xml @@ -1,7 +1,7 @@ +"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd"> diff --git a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/naming/checkstyle-metadata.xml b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/naming/checkstyle-metadata.xml index d96cd7fce5..cc36cae9ca 100644 --- a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/naming/checkstyle-metadata.xml +++ b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/naming/checkstyle-metadata.xml @@ -1,7 +1,7 @@ +"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd"> diff --git a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/sizes/checkstyle-metadata.xml b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/sizes/checkstyle-metadata.xml index d76ad4d19c..cdf360e456 100755 --- a/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/sizes/checkstyle-metadata.xml +++ b/eclipsecs-sevntu-plugin/src/com/github/sevntu/checkstyle/checks/sizes/checkstyle-metadata.xml @@ -1,7 +1,7 @@ +"https://checkstyle.org/eclipse-cs/dtds/checkstyle-metadata_1_1.dtd"> diff --git a/sevntu-checks/pom.xml b/sevntu-checks/pom.xml index 21a74eb8c5..a40e2ffc47 100644 --- a/sevntu-checks/pom.xml +++ b/sevntu-checks/pom.xml @@ -51,6 +51,7 @@ jsr305 3.0.2 + com.google.code.findbugs annotations @@ -294,8 +295,6 @@ .*.checks.coding.MapIterationInForEachLoopCheck9098 .*.checks.coding.NoNullForCollectionReturnCheck8596 .*.checks.coding.OverridableMethodInConstructorCheck9499 - .*.checks.coding.Jsr305AnnotationsCheck9698 - .*.checks.coding.Jsr305AnnotationsCheck.AbstractJsr305Check98100 .*.checks.design.HideUtilityClassConstructorCheck96100 diff --git a/sevntu-checks/sevntu-checks.xml b/sevntu-checks/sevntu-checks.xml index 527deaba9c..bc40e129f3 100644 --- a/sevntu-checks/sevntu-checks.xml +++ b/sevntu-checks/sevntu-checks.xml @@ -1,5 +1,5 @@  - + diff --git a/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheck.java b/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheck.java index 13f9479579..c262249323 100644 --- a/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheck.java +++ b/sevntu-checks/src/main/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheck.java @@ -84,51 +84,84 @@ *

* Example code: *

+ *

+ * Configure the check so that it scans the packages of the classes we want to run this on: + *

+ * + *
+ * <module name="Jsr305Annotations">
+ *   <property name="packages" value="org,com"/>
+ *   </module>
+ * 
+ * * *
- * // no class-level annotation
+ * // Example 1: a class without any class-level annotations
  * class Class1 {
- *     @CheckForNull // Error: obj2 not annotated!
- *     String method1(@Nullable Object obj1, Object obj2) { ... }
+ *     @CheckForNull // Violation: obj2 not annotated!
+ *     String method1(@Nullable Object obj1, Object obj2) {
+ *         return "";
+ *     }
  *
- *     // Error: return value not annotated
- *     String method2() { ... }
+ *     // Violation: return value not annotated
+ *     String method2() {
+ *         return "";
+ *     }
  * }
  *
- * // with class-level defaults
+ * // Example 2: a class with class-level annotations for parameters
  * @ParametersAreNonnullByDefault
  * class Class2 {
  *     @CheckForNull // Legal
- *     String method1(Object obj1, Object obj2) { ... }
+ *     String method1(Object obj1, Object obj2) {
+ *         return "";
+ *     }
  *
  *     @Nonnull // Legal
- *     String method2(Object obj1, @Nullable Object obj2) { ... }
+ *     String method2(Object obj1, @Nullable Object obj2) {
+ *         return "";
+ *     }
  *
- *     @Nonnull // Error, redefinition of obj2's nullness
- *     String method3(Object obj1, @Nonnull Object obj2) { ... }
+ *     @Nonnull // Violation, redefinition of obj2's nullness
+ *     String method3(Object obj1, @Nonnull Object obj2) {
+ *         return "";
+ *     }
  *
- *     // Error: return value not annotated
- *     String method4() { ... }
+ *     // Violation: return value not annotated
+ *     String method4() {
+ *         return "";
+ *     }
  * }
  *
+ * // Example 3: a class overriding some methods
  * class Class3 implements Interface1 {
- *    @Override // Legal
- *    public Object method1(Object obj1, Object obj2) { ... }
+ *     @Override // Legal
+ *     public Object method1(Object obj1, Object obj2) {
+ *         return "";
+ *     }
  *
- *    @Override
- *    @Nonnull // Legal, return value becomes less "nullable"
- *    public Object method2(Object obj1, Object obj2) { ... }
+ *     @Override
+ *     @Nonnull // Legal, return value becomes less "nullable"
+ *     public Object method2(Object obj1, Object obj2) {
+ *         return "";
+ *     }
  *
- *    @Override // Error: Setting a parameter to non-null in an overridden method is illegal
- *    public Object method3(@Nonnull Object obj1, Object obj2) { ... }
+ *     @Override // Violation: Setting a parameter to non-null in an overridden method
+ *     public Object method3(@Nonnull Object obj1, Object obj2) {
+ *         return "";
+ *     }
  *
- *    @Override // Legal: parameter obj2 becomes more "nullable"
- *    public Object method4(Object obj1, @Nullable Object obj2) { ... }
+ *     @Override // Legal: parameter obj2 becomes more "nullable"
+ *     public Object method4(Object obj1, @Nullable Object obj2) {
+ *         return "";
+ *     }
  *
- *    @Override
- *    @CheckForNull // Error: return value becomes more "nullable"
- *    public Object method5() { ... }
- *}
+ *     @Override
+ *     @CheckForNull // Violation: return value becomes more "nullable"
+ *     public Object method5() {
+ *         return "";
+ *     }
+ * }
  * 
*/ public class Jsr305AnnotationsCheck extends AbstractCheck { @@ -260,10 +293,10 @@ protected enum NullnessAnnotation { "edu.umd.cs.findbugs.annotations"); /** The annotation's name. */ - private final String theAnnotationName; + private final String annotationName; /** The annotation's fully qualified class name. */ - private final String theFqcn; + private final String fullyQualifiedClassName; /** * Constructor. @@ -273,8 +306,8 @@ protected enum NullnessAnnotation { * the package name */ NullnessAnnotation(final String annotationName, final String packageName) { - this.theAnnotationName = annotationName; - this.theFqcn = packageName + "." + annotationName; + this.annotationName = annotationName; + this.fullyQualifiedClassName = packageName + "." + annotationName; } } @@ -352,8 +385,8 @@ private static Map createString2AnnotationMap() { final Map result = new HashMap<>(); for (final NullnessAnnotation annotation : NullnessAnnotation.values()) { - result.put(annotation.theAnnotationName, annotation); - result.put(annotation.theFqcn, annotation); + result.put(annotation.annotationName, annotation); + result.put(annotation.fullyQualifiedClassName, annotation); } return Collections.unmodifiableMap(result); @@ -463,6 +496,42 @@ public void setAllowOverridingParameter(final boolean newAllowOverridingParamete this.allowOverridingParameter = newAllowOverridingParameter; } + /** + * Find the nullness annotations. + * @param ast + * the ast + * @return the annotations. + */ + private static Set findAnnotations(final DetailAST ast) { + final Set result = new HashSet<>(); + + final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS); + for (AST child = modifiers.getFirstChild(); child != null; child = child.getNextSibling()) { + if (child.getType() == TokenTypes.ANNOTATION) { + addNextNullnessAnnotation(result, (DetailAST) child); + } + } + + return result; + } + + /** + * Adds the nullness annotation from the argument's first token if any. + * @param result + * the result + * @param ast + * the ast + */ + private static void addNextNullnessAnnotation(final Set result, + DetailAST ast) { + final DetailAST identifier = ast.findFirstToken(TokenTypes.IDENT); + final String annotationName = identifier.getText(); + final NullnessAnnotation annotation = STRING2ANNOTATION.get(annotationName); + if (annotation != null) { + result.add(annotation); + } + } + /** * Class ClassJsr305Handler. Checks a class. */ @@ -704,9 +773,9 @@ public abstract class AbstractJsr305Handler { /** Has an error been found. */ private boolean errorFound; /** The found annotations. */ - private final Set theAnnotations; + private final Set annotations; /** The ast. */ - private final DetailAST theAst; + private final DetailAST ast; /** * Construtor. @@ -714,9 +783,9 @@ public abstract class AbstractJsr305Handler { * the ast */ protected AbstractJsr305Handler(final DetailAST ast) { - theAst = ast; - errorFound = false; - theAnnotations = findAnnotation(); + this.ast = ast; + this.errorFound = false; + annotations = findAnnotation(); } /** @@ -735,29 +804,29 @@ public final void check() { * Emits an error if any of the given annotations are found. * @param msg * the error message to emit - * @param annotations + * @param search * the annotations to look for */ - protected void checkContainsAny(final String msg, final NullnessAnnotation... annotations) { - if (!errorFound && containsAny(annotations)) { + protected void checkContainsAny(final String msg, final NullnessAnnotation... search) { + if (!errorFound && containsAny(search)) { error(msg); } } /** * Check whether any of the given annotations are found. - * @param annotations + * @param search * the annotations to look for * @return true if yes */ - protected boolean containsAny(final NullnessAnnotation... annotations) { + protected boolean containsAny(final NullnessAnnotation... search) { Boolean result = null; - if (theAnnotations.isEmpty()) { + if (this.annotations.isEmpty()) { result = false; } else { - for (final NullnessAnnotation obj : annotations) { - if (theAnnotations.contains(obj)) { + for (final NullnessAnnotation obj : search) { + if (this.annotations.contains(obj)) { result = true; break; } @@ -773,11 +842,11 @@ protected boolean containsAny(final NullnessAnnotation... annotations) { * Emits an error if all given annotations are found. * @param msg * the error message to emit - * @param annotations + * @param search * the annotations to look for */ - protected void checkContainsAll(final String msg, final NullnessAnnotation... annotations) { - if (!errorFound && containsAll(annotations)) { + protected void checkContainsAll(final String msg, final NullnessAnnotation... search) { + if (!errorFound && containsAll(search)) { error(msg); } } @@ -786,14 +855,14 @@ protected void checkContainsAll(final String msg, final NullnessAnnotation... an * Emits an error if both this and the parent class have redundant nullness annotations. * @param msg * the error message to emit - * @param annotations + * @param search * the annotations to look for */ protected void checkRedundancyDueToClassLevelAnnotation(final String msg, - final NullnessAnnotation... annotations) { + final NullnessAnnotation... search) { if (!errorFound) { - for (final NullnessAnnotation nullnessAnnotation : annotations) { - final boolean thisIsAnnotated = theAnnotations.contains(nullnessAnnotation); + for (final NullnessAnnotation nullnessAnnotation : search) { + final boolean thisIsAnnotated = this.annotations.contains(nullnessAnnotation); final boolean parentIsAnnotated = getParentMethodOrClassAnnotation(nullnessAnnotation) != null; if (thisIsAnnotated && parentIsAnnotated) { @@ -806,19 +875,19 @@ protected void checkRedundancyDueToClassLevelAnnotation(final String msg, /** * Check whether all the given annotations are present. - * @param annotations + * @param search * the annotations to look for * @return true if yes */ - protected boolean containsAll(final NullnessAnnotation... annotations) { + protected boolean containsAll(final NullnessAnnotation... search) { Boolean result = null; - if (theAnnotations.isEmpty()) { + if (this.annotations.isEmpty()) { // an empty list of annotations can never contain all result = false; } else { - for (final NullnessAnnotation obj : annotations) { - if (!theAnnotations.contains(obj)) { + for (final NullnessAnnotation obj : search) { + if (!this.annotations.contains(obj)) { result = false; break; } @@ -834,12 +903,12 @@ protected boolean containsAll(final NullnessAnnotation... annotations) { * Make sure that none of the given annotations are present. * @param msg * the error message to emit if one of the given annotations was found - * @param annotations + * @param search * the annotations to look for */ protected void checkContainsNone(final String msg, - final NullnessAnnotation... annotations) { - if (!errorFound && !containsAny(annotations)) { + final NullnessAnnotation... search) { + if (!errorFound && !containsAny(search)) { error(msg); } } @@ -851,7 +920,7 @@ protected void checkContainsNone(final String msg, * the message */ protected void reportError(final String msg) { - log(theAst, msg); + log(ast, msg); } /** @@ -870,7 +939,7 @@ protected void error(final String msg) { * @return true if yes */ protected boolean isPrimitiveType() { - final DetailAST parameterType = theAst.findFirstToken(TokenTypes.TYPE); + final DetailAST parameterType = ast.findFirstToken(TokenTypes.TYPE); final boolean result; final DetailAST identToken = parameterType.getFirstChild(); @@ -917,7 +986,7 @@ protected boolean isArrayOrElipsis(final DetailAST identToken) { * @return true if yes */ protected boolean isVoid() { - final DetailAST parameterType = theAst.findFirstToken(TokenTypes.TYPE); + final DetailAST parameterType = ast.findFirstToken(TokenTypes.TYPE); final boolean result; final DetailAST identToken = parameterType.getFirstChild(); result = identToken.getType() == TokenTypes.LITERAL_VOID; @@ -929,44 +998,7 @@ protected boolean isVoid() { * @return the annotations. */ private Set findAnnotation() { - return findAnnotations(theAst); - } - - /** - * Find the nullness annotations. - * @param ast - * the ast - * @return the annotations. - */ - private Set findAnnotations(final DetailAST ast) { - final Set result = new HashSet<>(); - - final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS); - for (AST child = modifiers.getFirstChild(); child != null; child = - child.getNextSibling()) { - if (child.getType() == TokenTypes.ANNOTATION) { - addNextNullnessAnnotation(result, (DetailAST) child); - } - } - - return result; - } - - /** - * Adds the nullness annotation from the argument's first token if any. - * @param result - * the result - * @param ast - * the ast - */ - protected final void addNextNullnessAnnotation(final Set result, - DetailAST ast) { - final DetailAST identifier = ast.findFirstToken(TokenTypes.IDENT); - final String annotationName = identifier.getText(); - final NullnessAnnotation annotation = STRING2ANNOTATION.get(annotationName); - if (annotation != null) { - result.add(annotation); - } + return findAnnotations(ast); } /** @@ -980,7 +1012,7 @@ protected final void addNextNullnessAnnotation(final Set res boolean finished = false; NullnessAnnotation result = null; - for (DetailAST current = theAst.getParent(); current != null && !finished; current = + for (DetailAST current = ast.getParent(); current != null && !finished; current = current.getParent()) { final int tokenType = current.getType(); @@ -1040,7 +1072,7 @@ protected Set collectLookedForAnnotations(DetailAST current, * @return true if yes */ protected boolean isMethodOverridden() { - DetailAST current = theAst; + DetailAST current = ast; Boolean result = null; for (; current != null && result == null; current = current.getParent()) { switch (current.getType()) { diff --git a/sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheckTest.java b/sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheckTest.java index 998d1bf782..b0e561b675 100644 --- a/sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheckTest.java +++ b/sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/Jsr305AnnotationsCheckTest.java @@ -19,10 +19,17 @@ package com.github.sevntu.checkstyle.checks.coding; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.Assert; import org.junit.Test; import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil; public class Jsr305AnnotationsCheckTest extends AbstractModuleTestSupport { @@ -358,4 +365,30 @@ public void testExcludePackage() throws Exception { verify(checkConfig, getPath("InputJsr305AnnotationsCheckWithParameter.java"), expected); } + /** + * This must be a reflection test as it is too difficult to hit normally and the responsible + * code can't be removed without hitting checkstyle violations. This test targets the handling + * of token types not in 'acceptable tokens' (which should normally not occur). + * + * @throws Exception + * if there is an unexcpected error. + */ + @Test + public void testHandleDefinition() throws Exception { + final DetailAST ast = new DetailAST(); + ast.setType(TokenTypes.WILDCARD_TYPE); + + final Method handleDefinition = + TestUtil.getClassDeclaredMethod(Jsr305AnnotationsCheck.class, "handleDefinition"); + + try { + handleDefinition.invoke(new Jsr305AnnotationsCheck(), ast); + Assert.fail("Exception expected."); + } + catch (final InvocationTargetException exc) { + Assert.assertTrue("IllegalArgumentException expected from 'handleDefinition'", + exc.getCause().getClass().equals(IllegalArgumentException.class)); + } + } + } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithArrays.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithArrays.java index 5d3506ac50..6bd0a53e1f 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithArrays.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithArrays.java @@ -37,7 +37,7 @@ public class InputJsr305AnnotationsCheckWithArrays { obj = nullable; } - InputJsr305AnnotationsCheckWithArrays(final short[] array) { // error + InputJsr305AnnotationsCheckWithArrays(final short[] array) { // violation obj = array; } @@ -49,7 +49,7 @@ public class InputJsr305AnnotationsCheckWithArrays { obj = varargs; } - InputJsr305AnnotationsCheckWithArrays(final double... varargs) { // error + InputJsr305AnnotationsCheckWithArrays(final double... varargs) { // violation obj = varargs; } @@ -61,7 +61,7 @@ public class InputJsr305AnnotationsCheckWithArrays { obj = varargs; } - InputJsr305AnnotationsCheckWithArrays(final Serializable... varargs) { // error + InputJsr305AnnotationsCheckWithArrays(final Serializable... varargs) { // violation obj = varargs; } @@ -73,7 +73,7 @@ public class InputJsr305AnnotationsCheckWithArrays { obj = iterable; } - InputJsr305AnnotationsCheckWithArrays(final Comparable comparable) { // error + InputJsr305AnnotationsCheckWithArrays(final Comparable comparable) { // violation obj = comparable; } @@ -87,7 +87,7 @@ int[] retCheckForNull() { // ok return null; } - int[] retNoAnnotation() { // error + int[] retNoAnnotation() { // violation return new int[] {}; } @@ -99,7 +99,7 @@ void testNullableArray(@Nullable final int[] array) { // ok array[1] = 0; } - void testNoAnnotationArray(final int[] array) { // error + void testNoAnnotationArray(final int[] array) { // violation array[1] = 0; } @@ -111,7 +111,7 @@ void testNullableVarargs(@Nullable final int... varargs) { // ok varargs[1] = 0; } - void testNoAnnotationVarargs(final int... varargs) { // error + void testNoAnnotationVarargs(final int... varargs) { // violation varargs[1] = 0; } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithClass.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithClass.java index e4204dc0e4..26b796a0d2 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithClass.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithClass.java @@ -29,7 +29,7 @@ public class InputJsr305AnnotationsCheckWithClass { - @ParametersAreNonnullByDefault // error, double annotation + @ParametersAreNonnullByDefault // violation, double annotation @ParametersAreNullableByDefault class BothParameterAnnotationsClass { @@ -40,7 +40,7 @@ interface ParameterAnnotationsInterface { void setUnannotated(String unannotated); // ok - void setNullable(@Nullable String nullable); // error, redundant + void setNullable(@Nullable String nullable); // violation, redundant void setNonnull(@Nonnull String nonnull); // ok @@ -48,7 +48,7 @@ interface ParameterAnnotationsInterface { interface NoParameterAnnotationsInterface { - void setUnannotated(String unannotated); // error, missing + void setUnannotated(String unannotated); // violation, missing void setNullable(@Nonnull String nullable); // ok @@ -65,14 +65,14 @@ public void setUnannotated(final String unannotated) { // ok public void setNullable(@Nullable final String nullable) { // ok } - public void setNonnull(@Nonnull final String nonnull) { // error, redundant + public void setNonnull(@Nonnull final String nonnull) { // violation, redundant } } class NoParameterAnnotationsClass { - public void setUnannotated(final String unannotated) { // error, missing + public void setUnannotated(final String unannotated) { // violation, missing } public void setNullable(@Nullable final String nullable) { // ok @@ -116,16 +116,16 @@ public void setNullable(final String nullable) { // ok public void setNonnull(final String nonnull) { // ok } - public void setAnotherUnannotated(final String unannotated) { // error + public void setAnotherUnannotated(final String unannotated) { // violation } } @ReturnValuesAreNonnullByDefault interface ReturnValueAnnotationInterface { - @Nonnull // error, redundant + @Nonnull // violation, redundant String getNonnull(); - @ReturnValuesAreNonnullByDefault // error, disallowed + @ReturnValuesAreNonnullByDefault // violation, disallowed String getNonnullByDefault(); @CheckForNull // ok @@ -134,12 +134,12 @@ interface ReturnValueAnnotationInterface { @ReturnValuesAreNonnullByDefault static class ReturnValueAnnotationClass { - @Nonnull // error, redundant + @Nonnull // violation, redundant public String getNonnull() { return ""; } - @ReturnValuesAreNonnullByDefault // error, disallowed + @ReturnValuesAreNonnullByDefault // violation, disallowed public String getNonnullByDefault() { return ""; } @@ -154,7 +154,7 @@ interface NoReturnValueAnnotationInterface { @Nonnull // ok String getNonnull(); - @ReturnValuesAreNonnullByDefault // error, disallowed + @ReturnValuesAreNonnullByDefault // violation, disallowed String getNonnullByDefault(); @CheckForNull // ok diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithConstructor.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithConstructor.java index 7f84cdac11..941765096d 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithConstructor.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithConstructor.java @@ -34,12 +34,12 @@ public class InputJsr305AnnotationsCheckWithConstructor { @Nullable private final Object nullable; - public InputJsr305AnnotationsCheckWithConstructor(@Nonnull @Nullable final Enum value) { // error + public InputJsr305AnnotationsCheckWithConstructor(@Nonnull @Nullable final Enum value) { // violation nullable = value; nonnull = new Object(); } - public InputJsr305AnnotationsCheckWithConstructor(final Class clz) { // error + public InputJsr305AnnotationsCheckWithConstructor(final Class clz) { // violation nonnull = new Object(); nullable = clz; } @@ -51,7 +51,7 @@ public InputJsr305AnnotationsCheckWithConstructor(final String string1, @Nullabl } @ParametersAreNonnullByDefault - public InputJsr305AnnotationsCheckWithConstructor(@Nonnull final String string1, final Integer string2) { // error + public InputJsr305AnnotationsCheckWithConstructor(@Nonnull final String string1, final Integer string2) { // violation nonnull = string1; nullable = string2; } @@ -63,7 +63,7 @@ public InputJsr305AnnotationsCheckWithConstructor(@Nonnull final Integer int1, f } @ParametersAreNullableByDefault - public InputJsr305AnnotationsCheckWithConstructor(final Integer int1, @Nullable final String int2) { // error + public InputJsr305AnnotationsCheckWithConstructor(final Integer int1, @Nullable final String int2) { // violation if (int1 != null) { nonnull = int1; } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithDefaultReturnValues.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithDefaultReturnValues.java index 9e9649ec40..68475ac15c 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithDefaultReturnValues.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithDefaultReturnValues.java @@ -32,7 +32,7 @@ public String toString() { return super.toString(); } - @Nonnull // error + @Nonnull // violation public Object bar() { return new Object(); } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithEnum.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithEnum.java index 7bf0a9a05c..7b067f1dce 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithEnum.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithEnum.java @@ -39,7 +39,7 @@ public void setUnannotated(final String foo) { // ok public void setNullable(@Nullable final String foo) { // ok } - public void setNonnull(@Nonnull final String foo) { // error, redundant + public void setNonnull(@Nonnull final String foo) { // violation, redundant } } @@ -47,7 +47,7 @@ public void setNonnull(@Nonnull final String foo) { // error, redundant enum NoParameterAnnotationsEnum { TEST; - public void setUnannotated(final String foo) { // error, missing + public void setUnannotated(final String foo) { // violation, missing } public void setNullable(@Nullable final String foo) { // ok @@ -61,12 +61,12 @@ public void setNonnull(@Nonnull final String foo) { // ok @ReturnValuesAreNonnullByDefault enum ReturnValueAnnotationEnum { TEST; - @Nonnull // error, redundant + @Nonnull // violation, redundant public String getNonnull() { return ""; } - @ReturnValuesAreNonnullByDefault // error, disallowed + @ReturnValuesAreNonnullByDefault // violation, disallowed public String getNonnnullByDefault() { return ""; } @@ -77,7 +77,7 @@ public String getCheckForNull() { } } - @ParametersAreNonnullByDefault // error + @ParametersAreNonnullByDefault // violation @ParametersAreNullableByDefault enum BothAnnotations { TEST; diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithInheritance.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithInheritance.java index 9d4ebc0e2b..18943c82f4 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithInheritance.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithInheritance.java @@ -40,7 +40,7 @@ public void getUnannotated(final String unannotated) { public void getNullable(final String nullable) { } - public void getAnotherUnannotated(final String getAnotherUnannotated) { // error + public void getAnotherUnannotated(final String getAnotherUnannotated) { // violation } @Override @@ -72,7 +72,7 @@ public void getUnannotated(@Nullable final String unannotated) { public void getNullable(final String nullable) { } - public void getAnotherUnannotated(final String unannotated) { // error + public void getAnotherUnannotated(final String unannotated) { // violation } @Override @@ -85,7 +85,7 @@ public Object nonnull() { @ParametersAreNullableByDefault // ok static class AnnotatedInheritor implements Inherited { - // this should not be an error, we are inheriting via the @Override + // this should not be an violation, we are inheriting via the @Override // annotation @Override public void getUnannotated(final String unannotated) { diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithLambda.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithLambda.java index b67f9fa037..b062d75bef 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithLambda.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithLambda.java @@ -30,7 +30,7 @@ public final class InputJsr305AnnotationsCheckWithLambda { object -> object.toString(); // ok public static final ToIntFunction HASH_CODE = - (@Nonnull Object object) -> object.hashCode(); // error + (@Nonnull Object object) -> object.hashCode(); // violation /** * Private util class constructor. @@ -39,7 +39,7 @@ private InputJsr305AnnotationsCheckWithLambda() { // empty } - public String error() { // error + public String violation() { // error return ""; } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithParameter.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithParameter.java index cc412f2c89..feb8058106 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithParameter.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithParameter.java @@ -33,11 +33,11 @@ public class InputJsr305AnnotationsCheckWithParameter private static final long serialVersionUID = 1L; @Nonnull - public String missingNullnessParameter(final Object obj) { // error + public String missingNullnessParameter(final Object obj) { // violation return obj.toString(); } - public boolean missingNullnessParameter(final Object obj1, final Object obj2) { // 2x error + public boolean missingNullnessParameter(final Object obj1, final Object obj2) { // 2x violation return obj1.equals(obj2); } @@ -65,12 +65,12 @@ public boolean nullableParameter(@Nullable final Object obj1, } @Nonnull - public String checkForNullParameter(@CheckForNull final Object obj) { // error + public String checkForNullParameter(@CheckForNull final Object obj) { // violation return String.valueOf(obj); } @Override - public boolean equals(@Nonnull final Object obj) { // error + public boolean equals(@Nonnull final Object obj) { // violation return super.equals(obj); } @@ -85,7 +85,7 @@ public int compareTo(@Nullable final InputJsr305AnnotationsCheckWithParameter ob } @Nonnull - public String nonnullNullable(@Nonnull @Nullable final Object obj) { // error + public String nonnullNullable(@Nonnull @Nullable final Object obj) { // violation return String.valueOf(obj); } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithPrimitives.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithPrimitives.java index 40819aa6cf..5d3bfeccbd 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithPrimitives.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithPrimitives.java @@ -25,40 +25,40 @@ public class InputJsr305AnnotationsCheckWithPrimitives { - public boolean nonnullParameter(@Nonnull final int param) { // error + public boolean nonnullParameter(@Nonnull final int param) { // violation return param == 0; } - public boolean nullableParameter(@Nullable final int param) { // error + public boolean nullableParameter(@Nullable final int param) { // violation return param == 0; } - public boolean checkForNullParameter(@CheckForNull final int param) { // error + public boolean checkForNullParameter(@CheckForNull final int param) { // violation return param == 0; } - @Nonnull // error + @Nonnull // violation public int returnNonnull() { return 0; } - @CheckForNull // error + @CheckForNull // violation public int returnCheckForNull() { return 0; } - @Nullable // error + @Nullable // violation public int returnNullable() { return 0; } - @Override // error + @Override // violation @Nonnull public boolean equals(Object object) { return super.equals(object); } - @Override // error + @Override // violation @Nonnull public int hashCode() { return super.hashCode(); @@ -96,7 +96,7 @@ public char primitivesChar(final char primitive) { // ok return primitive; } - public int primitivesNonnull(@Nonnull final int primitive) { // error + public int primitivesNonnull(@Nonnull final int primitive) { // violation return primitive + 1; } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithRedundantClassLevel.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithRedundantClassLevel.java index ee33fd8c82..cd179414f1 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithRedundantClassLevel.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithRedundantClassLevel.java @@ -25,7 +25,7 @@ @ParametersAreNullableByDefault public class InputJsr305AnnotationsCheckWithRedundantClassLevel { - @ParametersAreNullableByDefault // error + @ParametersAreNullableByDefault // violation public void redundant1() { } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithReturnValue.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithReturnValue.java index b5dccef022..adad1f5c0d 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithReturnValue.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputJsr305AnnotationsCheckWithReturnValue.java @@ -43,12 +43,12 @@ Object returnCheckForNull() { return null; } - @Nullable // error + @Nullable // violation Object returnNullable() { return null; } - @Nonnull // error + @Nonnull // violation @CheckForNull Object returnNonnullCheckForNull() { return new Object(); @@ -66,13 +66,13 @@ Object returnCheckReturnValueNonnull() { return new Object(); } - @Override // error + @Override // violation @Nonnull public boolean equals(final Object obj) { return super.equals(obj); } - @Override // error + @Override // violation @CheckForNull public int hashCode() { return super.hashCode(); @@ -89,25 +89,25 @@ public String toString() { return super.toString(); } - @ParametersAreNonnullByDefault // error + @ParametersAreNonnullByDefault // violation @ParametersAreNullableByDefault @Nonnull - public String concat(final String string1, final String string2) { // error + public String concat(final String string1, final String string2) { // violation return string1 + string2; } - @Override // error + @Override // violation @CheckReturnValue public int compareTo(@Nullable final InputJsr305AnnotationsCheckWithReturnValue obj) { return 0; } - @CheckReturnValue // error + @CheckReturnValue // violation public void voidNoCheckReturnValue() { hashCode(); } - @Nonnull // error + @Nonnull // violation public void voidNoNonnull() { hashCode(); }