Skip to content

Commit

Permalink
minor: resolve legacy sevntu suppressions
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Oct 21, 2022
1 parent 09c9464 commit 1ebd62a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
9 changes: 3 additions & 6 deletions sevntu-checks/sevntu-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
"https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
<!-- not easy to break apart the switch -->
<suppress checks="ChildBlockLength" files="ChecksTest.java"/>

<!-- Tone down the checking for test code -->
<suppress checks="IllegalCatchExtended" files="[\\/]internal[\\/]\w+Util\.java"/>
<suppress checks="MultipleStringLiteralsExtended" files=".*[\\/]+src[\\/]test[\\/]"/>
<suppress checks="LineLengthExtended" files=".*[\\/]src[\\/]test[\\/]"/>

<!-- START of legacy code, all violations will be resolved during transition to main project -->
<suppress checks="MultipleStringLiteralsExtended" files="(CustomDeclarationOrderCheck|ForbidWildcardAsReturnTypeCheck).java"/>
<suppress checks="LineLengthExtended" files="DiamondOperatorForVariableDefinitionCheck.java"/>
<suppress checks="ChildBlockLength" files="ChecksTest.java"/>
<!-- END of legacy code -->
</suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ public class CustomDeclarationOrderCheck extends AbstractCheck {
/** Prefix for setter method name. */
private static final String SETTER_PREFIX = "set";

/** Macro string for String. */
private static final String STRING_MACRO = "String";

/** Default format for custom declaration check. */
private static final String DEFAULT_DECLARATION = "Field(.*public .*) "
+ "### Field(.*protected .*) ### Field(.*private .*) ### CTOR(.*) ### "
Expand Down Expand Up @@ -1147,7 +1150,7 @@ private static boolean hasOnlyStringArrayParameter(final DetailAST parametersAST
if (hasChildToken(parameterTypeAST, TokenTypes.ARRAY_DECLARATOR)) {
final String parameterName =
parameterTypeAST.getFirstChild().getText();
result = "String".equals(parameterName);
result = STRING_MACRO.equals(parameterName);
}
else {
result = false;
Expand Down Expand Up @@ -1179,7 +1182,7 @@ private static boolean hasOnlyStringEllipsisParameter(final DetailAST parameters
parameterDefinitionAST.findFirstToken(TokenTypes.TYPE);
final String parameterName =
getIdentifier(parameterTypeAST);
result = "String".equals(parameterName);
result = STRING_MACRO.equals(parameterName);
}
else {
result = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,29 @@ public class ForbidWildcardAsReturnTypeCheck extends AbstractCheck {
/** {@link Deprecated Deprecated} annotation name. */
private static final String DEPRECATED = "Deprecated";

/** Macro string for "java.lang.". */
private static final String JAVA_LANG_MACRO = "java.lang.";

/** Fully-qualified {@link Deprecated Deprecated} annotation name. */
private static final String FQ_DEPRECATED = "java.lang." + DEPRECATED;
private static final String FQ_DEPRECATED = JAVA_LANG_MACRO + DEPRECATED;

/** {@link Override Override} annotation name. */
private static final String OVERRIDE = "Override";

/** Fully-qualified {@link Override Override} annotation name. */
private static final String FQ_OVERRIDE = "java.lang." + OVERRIDE;
private static final String FQ_OVERRIDE = JAVA_LANG_MACRO + OVERRIDE;

/** Macro string for public. */
private static final String PUBLIC_MACRO = "public";

/** Macro string for private. */
private static final String PRIVATE_MACRO = "private";

/** Macro string for protected. */
private static final String PROTECTED_MACRO = "protected";

/** Macro string for package. */
private static final String PACKAGE_MACRO = "package";

/**
* Empty array of DetailAST.
Expand Down Expand Up @@ -264,10 +279,10 @@ public void visitToken(DetailAST methodDefAst) {
* @return {@code true} if the method should be checked.
*/
private boolean isCheckableMethodScope(String methodScope) {
return checkPublicMethods && "public".equals(methodScope)
|| checkPrivateMethods && "private".equals(methodScope)
|| checkProtectedMethods && "protected".equals(methodScope)
|| checkPackageMethods && "package".equals(methodScope);
return checkPublicMethods && PUBLIC_MACRO.equals(methodScope)
|| checkPrivateMethods && PRIVATE_MACRO.equals(methodScope)
|| checkProtectedMethods && PROTECTED_MACRO.equals(methodScope)
|| checkPackageMethods && PACKAGE_MACRO.equals(methodScope);
}

/**
Expand All @@ -277,13 +292,13 @@ private boolean isCheckableMethodScope(String methodScope) {
* @return one of "public", "private", "protected", "package"
*/
private static String getVisibilityScope(DetailAST methodDefAst) {
String result = "package";
String result = PACKAGE_MACRO;
if (isInsideInterfaceDefinition(methodDefAst)) {
result = "public";
result = PUBLIC_MACRO;
}
else {
final String[] visibilityScopeModifiers = {"public", "private",
"protected", };
final String[] visibilityScopeModifiers = {PUBLIC_MACRO, PRIVATE_MACRO,
PROTECTED_MACRO, };
final Set<String> methodModifiers = getModifiers(methodDefAst);
for (final String modifier : visibilityScopeModifiers) {
if (methodModifiers.contains(modifier)) {
Expand Down
1 change: 0 additions & 1 deletion sevntu-checks/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<!-- START of legacy code, all violations will be resolved during transition to main project -->
<suppress checks="ImportControl" files="CustomDeclarationOrderCheck.java"/>
<suppress checks="CyclomaticComplexity" files="(AvoidNotShortCircuitOperatorsForBooleanCheck|CustomDeclarationOrderCheck|EitherLogOrThrowCheck|ReturnCountExtendedCheck|AvoidHidingCauseExceptionCheck|ConfusingConditionCheck|ForbidWildcardAsReturnTypeCheck|HideUtilityClassConstructorCheck|UnnecessaryParenthesesExtendedCheck|OverridableMethodInConstructorCheck|MapIterationInForEachLoopCheck).java"/>
<suppress checks="MultipleStringLiterals" files="(CustomDeclarationOrderCheck|ForbidWildcardAsReturnTypeCheck).java"/>
<suppress checks="MethodCount|NestedIfDepth" files="CustomDeclarationOrderCheck.java"/>
<suppress checks="TodoComment" files="HideUtilityClassConstructorCheck.java"/>
<!-- END of legacy code -->
Expand Down

0 comments on commit 1ebd62a

Please sign in to comment.