Skip to content

Commit 43d34de

Browse files
klueverError Prone Team
authored and
Error Prone Team
committed
Add ReadableInstant.getMillis() and ReadableDuration.getMillis() to ReturnValueIgnored checker.
#checkreturnvalue PiperOrigin-RevId: 391812370
1 parent 1511398 commit 43d34de

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/ReturnValueIgnored.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,19 @@ private static boolean functionalMethod(ExpressionTree tree, VisitorState state)
281281
private static final Matcher<ExpressionTree> TIME_UNIT_METHODS =
282282
anyMethod().onClass("java.util.concurrent.TimeUnit");
283283

284+
/** APIs to check on {@code JodaTime} types. */
285+
// TODO(kak): there's a ton more we could do here
286+
private static final Matcher<ExpressionTree> JODA_TIME_METHODS =
287+
anyOf(
288+
instanceMethod()
289+
.onDescendantOf("org.joda.time.ReadableInstant")
290+
.named("getMillis")
291+
.withNoParameters(),
292+
instanceMethod()
293+
.onDescendantOf("org.joda.time.ReadableDuration")
294+
.named("getMillis")
295+
.withNoParameters());
296+
284297
private static final String PROTO_MESSAGE = "com.google.protobuf.MessageLite";
285298

286299
/**
@@ -328,12 +341,14 @@ public ReturnValueIgnored(ErrorProneFlags flags) {
328341
boolean checkOptionalMethods = flags.getBoolean("ReturnValueIgnored:MoreOptional").orElse(true);
329342
boolean checkObjectMethods = flags.getBoolean("ReturnValueIgnored:ObjectMethods").orElse(true);
330343
boolean checkMapEntryMethods = flags.getBoolean("ReturnValueIgnored:MapEntry").orElse(true);
344+
boolean checkJodaTimeMethods = flags.getBoolean("ReturnValueIgnored:JodaTime").orElse(true);
331345

332346
this.matcher =
333347
anyOf(
334348
SPECIALIZED_MATCHER,
335349
checkOptionalMethods ? MORE_OPTIONAL_METHODS : nothing(),
336350
checkObjectMethods ? OBJECT_METHODS : nothing(),
351+
checkJodaTimeMethods ? JODA_TIME_METHODS : nothing(),
337352
checkMapEntryMethods ? MAP_ENTRY_METHODS : nothing());
338353
}
339354

0 commit comments

Comments
 (0)