Skip to content

Commit

Permalink
Prevent ReverseOrder Refaster rule from introducing a static import
Browse files Browse the repository at this point in the history
This is a workaround for the issue resolved by google/error-prone#3584.

After application of this Refaster rule, any static imports of
`java.util.Collections.reverseOrder` are obsolete. These can be removed by
running Google Java Format or Error Prone's `RemoveUnusedImports` check.

Where possible, subsequent application of the `StaticImport` checker will
statically import `java.util.Comparator.reverseOrder`.
  • Loading branch information
Stephan202 authored and rickie committed Dec 7, 2022
1 parent bc1f204 commit f9b309f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ Comparator<T> before() {
Comparator.<T>naturalOrder().reversed());
}

// XXX: Add `@UseImportPolicy(STATIC_IMPORT_ALWAYS)` if/when
// https://github.com/google/error-prone/pull/3584 is merged and released.
@AfterTemplate
@UseImportPolicy(STATIC_IMPORT_ALWAYS)
Comparator<T> after() {
return reverseOrder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ ImmutableSet<Comparator<String>> testNaturalOrder() {
}

ImmutableSet<Comparator<String>> testReverseOrder() {
return ImmutableSet.of(reverseOrder(), reverseOrder(), reverseOrder());
return ImmutableSet.of(
Comparator.reverseOrder(), Comparator.reverseOrder(), Comparator.reverseOrder());
}

ImmutableSet<Comparator<String>> testCustomComparator() {
Expand Down

0 comments on commit f9b309f

Please sign in to comment.