Skip to content

Commit

Permalink
Address comments: Exclude serialVersionUID field name by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsamehsalah committed Sep 23, 2023
1 parent 5db9649 commit f6bb469
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.errorprone.BugPattern;
import com.google.errorprone.ErrorProneFlags;
import com.google.errorprone.VisitorState;
Expand Down Expand Up @@ -61,10 +62,12 @@ public final class CanonicalConstantFieldName extends BugChecker implements Vari
private static final Matcher<Tree> IS_CONSTANT =
allOf(hasModifier(Modifier.STATIC), hasModifier(Modifier.FINAL));
private static final Pattern TO_SNAKE_CASE = Pattern.compile("([a-z])([A-Z])");
private static final ImmutableSet<String> DEFAULT_EXCLUDED_CONSTANT_FIELD_NAMES =
ImmutableSet.of("serialVersionUID");
private static final String EXCLUDED_CONSTANT_FIELD_NAMES =
"CanonicalConstantFieldName:ExcludedConstantFliedNames";

private final ImmutableList<String> excludedConstantFliedNames;
private final ImmutableList<String> optionalExcludedConstantFliedNames;

/** Instantiates a default {@link CanonicalConstantFieldName} instance. */
public CanonicalConstantFieldName() {
Expand All @@ -78,7 +81,7 @@ public CanonicalConstantFieldName() {
*/
@Inject
CanonicalConstantFieldName(ErrorProneFlags flags) {
excludedConstantFliedNames = getCanonicalizedLoggerName(flags);
optionalExcludedConstantFliedNames = getCanonicalizedLoggerName(flags);
}

@Override
Expand All @@ -103,7 +106,8 @@ private static boolean isVariableUpperSnakeCase(String variableName) {
}

private boolean isVariableNameExcluded(String variableName) {
return excludedConstantFliedNames.contains(variableName);
return optionalExcludedConstantFliedNames.contains(variableName)
|| DEFAULT_EXCLUDED_CONSTANT_FIELD_NAMES.contains(variableName);
}

private static String toUpperSnakeCase(String variableName) {
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,6 @@
readable than the alternative. -->
-Xep:YodaCondition:OFF
-XepOpt:CheckReturnValue:CheckAllConstructors=true
-XepOpt:CanonicalConstantFieldName:ExcludedConstantFliedNames=serialVersionUID
<!-- XXX: Enable once there are fewer
false-positives.
-XepOpt:CheckReturnValue:CheckAllMethods=true -->
Expand Down

0 comments on commit f6bb469

Please sign in to comment.