Skip to content

Commit

Permalink
Issue sevntu-checkstyle#734: Fixed PMD violations from main class (PM…
Browse files Browse the repository at this point in the history
…D use in tests needs to be discussed in sevntu-checkstyle#734 and/or elsewhere)
  • Loading branch information
mbert committed Apr 12, 2019
1 parent cebab91 commit 4c839de
Showing 1 changed file with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,35 @@ public class Jsr305AnnotationsCheck extends AbstractCheck {
"jsr305.contradicting.class.level.annotations";

/** Key for error message. */
public static final String MSG_PARAM_DEFINITIONS_WITH_CHECK_ANNOTATION =
public static final String MSG_PARAM_DEFINITIONS_WITH_CHECK =
"jsr305.param.definitions.with.check.annotation";

/** Key for error message. */
public static final String MSG_PARAM_DEFINITION_WITH_OVERRIDE_ANNOTATION =
public static final String MSG_PARAM_DEFINITION_WITH_OVERRIDE =
"jsr305.param.definition.with.override.annotation";

/** Key for error message. */
public static final String MSG_PARAM_DEFINITION_WITH_NONNULL_BY_DEFAULT_ANNOTATION =
public static final String MSG_PARAM_DEFINITION_WITH_NONNULL_BY_DEFAULT =
"jsr305.param.definition.with.nonnull.by.default.annotation";

/** Key for error message. */
public static final String MSG_PARAM_DEFINITION_WITH_NULLABLE_BY_DEFAULT_ANNOTATION =
public static final String MSG_PARAM_DEFINITION_WITH_NULLABLE_BY_DEFAULT =
"jsr305.param.definition.with.nullable.by.default.annotation";

/** Key for error message. */
public static final String MSG_PARAM_DEFINITION_WITH_RETURN_VALUES_DEFAULT_ANNOTATION =
public static final String MSG_PARAM_DEFINITION_WITH_RETURN_DEFAULT =
"jsr305.param.definition.with.return.values.default.annotation";

/** Key for error message. */
public static final String MSG_PARAM_NONNULL_AND_NULLABLE_ANNOTATION =
public static final String MSG_PARAM_NONNULL_AND_NULLABLE =
"jsr305.param.nonnull.and.nullable.annotation";

/** Key for error message. */
public static final String MSG_PRIMITIVES_WITH_NULLNESS_ANNOTATION =
"jsr305.primitives.with.nullness.annotation";

/** Key for error message. */
public static final String MSG_OVERRIDDEN_DEFINITIONS_WITH_INCREASED_PARAM_CONSTRAINT =
public static final String MSG_OVERRIDDEN_WITH_INCREASED_CONSTRAINT =
"jsr305.overridden.definitions.with.increased.param.constraint";

/** Key for error message. */
Expand All @@ -117,19 +117,19 @@ public class Jsr305AnnotationsCheck extends AbstractCheck {
"jsr305.parameter.without.nullness.annotation";

/** Key for error message. */
public static final String MSG_RETURN_VALUE_WITH_NONNULL_BY_DEFAULT_ANNOTATION =
public static final String MSG_RETURN_VALUE_WITH_NONNULL_BY_DEFAULT =
"jsr305.return.value.with.nonnull.by.default.annotation";

/** Key for error message. */
public static final String MSG_RETURN_VALUE_WITH_NULLABLE_ANNOTATION =
public static final String MSG_RETURN_VALUE_WITH_NULLABLE =
"jsr305.return.value.with.nullable.annotation";

/** Key for error message. */
public static final String MSG_CONTRADICTING_RETURN_VALUE_ANNOTATIONS =
"jsr305.contradicting.return.value.annotations";

/** Key for error message. */
public static final String MSG_OVERRIDDEN_METHOD_WITH_CHECK_RETURN_VALUE_ANNOTATION =
public static final String MSG_OVERRIDDEN_METHOD_WITH_CHECK_RETURN_VALUE =
"jsr305.overridden.method.with.check.return.value.annotation";

/** Key for error message. */
Expand Down Expand Up @@ -242,7 +242,7 @@ protected enum NullnessAnnotation {
* @param packageNames
* the package names, comma separated
*/
public void setPackages(final String[] packageNames) {
public void setPackages(final String... packageNames) {
packages = transformToUnique(packageNames);
}

Expand All @@ -251,7 +251,7 @@ public void setPackages(final String[] packageNames) {
* @return the map
*/
private static Map<String, NullnessAnnotation> createString2AnnotationMap() {
final Map<String, NullnessAnnotation> result = new HashMap<String, NullnessAnnotation>();
final Map<String, NullnessAnnotation> result = new HashMap<>();

for (final NullnessAnnotation annotation : NullnessAnnotation.values()) {
result.put(annotation.theAnnotationName, annotation);
Expand All @@ -266,7 +266,7 @@ private static Map<String, NullnessAnnotation> createString2AnnotationMap() {
* @param packageNames
* the package names, comma separated
*/
public void setExcludePackages(final String[] packageNames) {
public void setExcludePackages(final String... packageNames) {
excludePackages = transformToUnique(packageNames);
}

Expand All @@ -275,7 +275,7 @@ public void setExcludePackages(final String[] packageNames) {
*
* @return the excluded packages
*/
String[] getExcludePackages() {
public String[] getExcludePackages() {
return excludePackages;
}

Expand All @@ -285,9 +285,9 @@ String[] getExcludePackages() {
* the array
* @return a new, duplicate-free array
*/
private static String[] transformToUnique(final String[] input) {
final Set<String> inputSet = new HashSet<String>(Arrays.asList(input));
return inputSet.toArray(new String[inputSet.size()]);
private static String[] transformToUnique(final String... input) {
final Set<String> inputSet = new HashSet<>(Arrays.asList(input));
return inputSet.toArray(new String[0]);
}

@Override
Expand Down Expand Up @@ -417,7 +417,7 @@ private final class ClassJsr305Check extends AbstractJsr305Check {
* @param ast
* the ast
*/
ClassJsr305Check(final DetailAST ast) {
protected ClassJsr305Check(final DetailAST ast) {
super(ast);
}

Expand Down Expand Up @@ -446,7 +446,7 @@ private final class ParameterJsr305Check extends AbstractJsr305Check {
* @param ast
* the ast
*/
ParameterJsr305Check(final DetailAST ast) {
protected ParameterJsr305Check(final DetailAST ast) {
super(ast);
}

Expand All @@ -455,17 +455,17 @@ private final class ParameterJsr305Check extends AbstractJsr305Check {
*/
@Override
protected void runcheck() {
checkContainsAny(MSG_PARAM_DEFINITIONS_WITH_CHECK_ANNOTATION,
checkContainsAny(MSG_PARAM_DEFINITIONS_WITH_CHECK,
NullnessAnnotation.CHECK_FOR_NULL, NullnessAnnotation.CHECK_RETURN_VALUE);
checkContainsAny(MSG_PARAM_DEFINITION_WITH_OVERRIDE_ANNOTATION,
checkContainsAny(MSG_PARAM_DEFINITION_WITH_OVERRIDE,
NullnessAnnotation.OVERRIDE);
checkContainsAny(MSG_PARAM_DEFINITION_WITH_NONNULL_BY_DEFAULT_ANNOTATION,
checkContainsAny(MSG_PARAM_DEFINITION_WITH_NONNULL_BY_DEFAULT,
NullnessAnnotation.PARAMETERS_ARE_NONNULL_BY_DEFAULT);
checkContainsAny(MSG_PARAM_DEFINITION_WITH_NULLABLE_BY_DEFAULT_ANNOTATION,
checkContainsAny(MSG_PARAM_DEFINITION_WITH_NULLABLE_BY_DEFAULT,
NullnessAnnotation.PARAMETERS_ARE_NULLABLE_BY_DEFAULT);
checkContainsAny(MSG_PARAM_DEFINITION_WITH_RETURN_VALUES_DEFAULT_ANNOTATION,
checkContainsAny(MSG_PARAM_DEFINITION_WITH_RETURN_DEFAULT,
NullnessAnnotation.RETURN_VALUES_ARE_NONNULL_BY_DEFAULT);
checkContainsAll(MSG_PARAM_NONNULL_AND_NULLABLE_ANNOTATION,
checkContainsAll(MSG_PARAM_NONNULL_AND_NULLABLE,
NullnessAnnotation.NONNULL, NullnessAnnotation.NULLABLE);

final NullnessAnnotation firstAncestorAnnotation = getParentMethodOrClassAnnotation(
Expand All @@ -484,7 +484,7 @@ protected void runcheck() {
}
else {
if (isMethodOverridden && !allowOverridingParameter) {
checkContainsAny(MSG_OVERRIDDEN_DEFINITIONS_WITH_INCREASED_PARAM_CONSTRAINT,
checkContainsAny(MSG_OVERRIDDEN_WITH_INCREASED_CONSTRAINT,
NullnessAnnotation.NONNULL);
}
if (parametersAreNonnullByDefault) {
Expand Down Expand Up @@ -515,7 +515,7 @@ private abstract class AbstractMethodJsr305Check extends AbstractJsr305Check {
* @param ast
* the ast
*/
AbstractMethodJsr305Check(final DetailAST ast) {
protected AbstractMethodJsr305Check(final DetailAST ast) {
super(ast);
}

Expand Down Expand Up @@ -547,7 +547,7 @@ private final class MethodJsr305Check extends AbstractMethodJsr305Check {
* @param ast
* the ast
*/
MethodJsr305Check(final DetailAST ast) {
protected MethodJsr305Check(final DetailAST ast) {
super(ast);
}

Expand All @@ -556,13 +556,13 @@ private final class MethodJsr305Check extends AbstractMethodJsr305Check {
*/
@Override
protected void runReturnAnnotationCheck() {
checkContainsAny(MSG_RETURN_VALUE_WITH_NONNULL_BY_DEFAULT_ANNOTATION,
checkContainsAny(MSG_RETURN_VALUE_WITH_NONNULL_BY_DEFAULT,
NullnessAnnotation.RETURN_VALUES_ARE_NONNULL_BY_DEFAULT);
checkContainsAny(MSG_RETURN_VALUE_WITH_NULLABLE_ANNOTATION,
checkContainsAny(MSG_RETURN_VALUE_WITH_NULLABLE,
NullnessAnnotation.NULLABLE);
checkContainsAll(MSG_CONTRADICTING_RETURN_VALUE_ANNOTATIONS, NullnessAnnotation.NONNULL,
NullnessAnnotation.CHECK_FOR_NULL);
checkContainsAll(MSG_OVERRIDDEN_METHOD_WITH_CHECK_RETURN_VALUE_ANNOTATION,
checkContainsAll(MSG_OVERRIDDEN_METHOD_WITH_CHECK_RETURN_VALUE,
NullnessAnnotation.CHECK_RETURN_VALUE, NullnessAnnotation.OVERRIDE);
checkRedundancyDueToClassLevelAnnotation(MSG_REDUNDANT_NONNULL_BY_DEFAULT_ANNOTATION,
NullnessAnnotation.PARAMETERS_ARE_NONNULL_BY_DEFAULT);
Expand Down Expand Up @@ -621,7 +621,7 @@ private final class ConstructorJsr305Check extends AbstractMethodJsr305Check {
* @param ast
* the ast
*/
ConstructorJsr305Check(final DetailAST ast) {
protected ConstructorJsr305Check(final DetailAST ast) {
super(ast);
}

Expand Down Expand Up @@ -656,7 +656,7 @@ public abstract class AbstractJsr305Check {
* @param ast
* the ast
*/
AbstractJsr305Check(final DetailAST ast) {
protected AbstractJsr305Check(final DetailAST ast) {
errorFound = false;
theAst = ast;
if (ast == null) {
Expand Down Expand Up @@ -911,7 +911,7 @@ private Set<NullnessAnnotation> findAnnotation() {
* @return the annotations.
*/
private Set<NullnessAnnotation> findAnnotations(final DetailAST ast) {
final Set<NullnessAnnotation> result = new HashSet<NullnessAnnotation>();
final Set<NullnessAnnotation> result = new HashSet<>();

final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
if (modifiers != null) {
Expand All @@ -933,7 +933,7 @@ private Set<NullnessAnnotation> findAnnotations(final DetailAST ast) {
* @param ast
* the ast
*/
protected void addNextNullnessAnnotation(final Set<NullnessAnnotation> result,
protected final void addNextNullnessAnnotation(final Set<NullnessAnnotation> result,
DetailAST ast) {
final DetailAST identifier = ast.findFirstToken(TokenTypes.IDENT);
if (identifier != null) {
Expand Down Expand Up @@ -970,7 +970,7 @@ protected void addNextNullnessAnnotation(final Set<NullnessAnnotation> result,
result = foundAndLookedFor.iterator().next();
finished = true;
}
else if (foundAndLookedFor.size() > 0) {
else if (!foundAndLookedFor.isEmpty()) {
finished = true;
}
}
Expand Down

0 comments on commit 4c839de

Please sign in to comment.