Skip to content

Commit

Permalink
Add ReadableInstant.getMillis() and ReadableDuration.getMillis()
Browse files Browse the repository at this point in the history
…to `ReturnValueIgnored` checker.

#checkreturnvalue

PiperOrigin-RevId: 391812370
  • Loading branch information
kluever authored and Error Prone Team committed Aug 19, 2021
1 parent 1511398 commit 43d34de
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@ private static boolean functionalMethod(ExpressionTree tree, VisitorState state)
private static final Matcher<ExpressionTree> TIME_UNIT_METHODS =
anyMethod().onClass("java.util.concurrent.TimeUnit");

/** APIs to check on {@code JodaTime} types. */
// TODO(kak): there's a ton more we could do here
private static final Matcher<ExpressionTree> JODA_TIME_METHODS =
anyOf(
instanceMethod()
.onDescendantOf("org.joda.time.ReadableInstant")
.named("getMillis")
.withNoParameters(),
instanceMethod()
.onDescendantOf("org.joda.time.ReadableDuration")
.named("getMillis")
.withNoParameters());

private static final String PROTO_MESSAGE = "com.google.protobuf.MessageLite";

/**
Expand Down Expand Up @@ -328,12 +341,14 @@ public ReturnValueIgnored(ErrorProneFlags flags) {
boolean checkOptionalMethods = flags.getBoolean("ReturnValueIgnored:MoreOptional").orElse(true);
boolean checkObjectMethods = flags.getBoolean("ReturnValueIgnored:ObjectMethods").orElse(true);
boolean checkMapEntryMethods = flags.getBoolean("ReturnValueIgnored:MapEntry").orElse(true);
boolean checkJodaTimeMethods = flags.getBoolean("ReturnValueIgnored:JodaTime").orElse(true);

this.matcher =
anyOf(
SPECIALIZED_MATCHER,
checkOptionalMethods ? MORE_OPTIONAL_METHODS : nothing(),
checkObjectMethods ? OBJECT_METHODS : nothing(),
checkJodaTimeMethods ? JODA_TIME_METHODS : nothing(),
checkMapEntryMethods ? MAP_ENTRY_METHODS : nothing());
}

Expand Down

0 comments on commit 43d34de

Please sign in to comment.