Skip to content

Commit

Permalink
Add type arguments in @AfterTemplates for builders
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Apr 7, 2022
1 parent 793a70c commit 4f28ecb
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ private ImmutableListMultimapTemplates() {}
* Prefer {@link ImmutableListMultimap#builder()} over the associated constructor on constructions
* that produce a less-specific type.
*/
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
// XXX: Picnic's Error Prone fork supports method invocation type argument inlining in the
// `@AfterTemplate`. Without using the fork, the expression in the `@AfterTemplate` can result in
// non-compilable code. See: https://github.com/google/error-prone/pull/2706.
static final class ImmutableListMultimapBuilder<K, V> {
@BeforeTemplate
ImmutableMultimap.Builder<K, V> before() {
Expand All @@ -46,7 +47,7 @@ ImmutableMultimap.Builder<K, V> before() {

@AfterTemplate
ImmutableListMultimap.Builder<K, V> after() {
return ImmutableListMultimap.builder();
return ImmutableListMultimap.<K, V>builder();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ final class ImmutableListTemplates {
private ImmutableListTemplates() {}

/** Prefer {@link ImmutableList#builder()} over the associated constructor. */
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
// XXX: Picnic's Error Prone fork supports method invocation type argument inlining in the
// `@AfterTemplate`. Without using the fork, the expression in the `@AfterTemplate` can result in
// non-compilable code. See: https://github.com/google/error-prone/pull/2706.
static final class ImmutableListBuilder<T> {
@BeforeTemplate
ImmutableList.Builder<T> before() {
Expand All @@ -37,7 +38,7 @@ ImmutableList.Builder<T> before() {

@AfterTemplate
ImmutableList.Builder<T> after() {
return ImmutableList.builder();
return ImmutableList.<T>builder();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ final class ImmutableMapTemplates {
private ImmutableMapTemplates() {}

/** Prefer {@link ImmutableMap#builder()} over the associated constructor. */
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
// XXX: Picnic's Error Prone fork supports method invocation type argument inlining in the
// `@AfterTemplate`. Without using the fork, the expression in the `@AfterTemplate` can result in
// non-compilable code. See: https://github.com/google/error-prone/pull/2706.
static final class ImmutableMapBuilder<K, V> {
@BeforeTemplate
ImmutableMap.Builder<K, V> before() {
Expand All @@ -36,7 +37,7 @@ ImmutableMap.Builder<K, V> before() {

@AfterTemplate
ImmutableMap.Builder<K, V> after() {
return ImmutableMap.builder();
return ImmutableMap.<K, V>builder();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ final class ImmutableMultisetTemplates {
private ImmutableMultisetTemplates() {}

/** Prefer {@link ImmutableMultiset#builder()} over the associated constructor. */
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
// XXX: Picnic's Error Prone fork supports method invocation type argument inlining in the
// `@AfterTemplate`. Without using the fork, the expression in the `@AfterTemplate` can result in
// non-compilable code. See: https://github.com/google/error-prone/pull/2706.
static final class ImmutableMultisetBuilder<T> {
@BeforeTemplate
ImmutableMultiset.Builder<T> before() {
Expand All @@ -31,7 +32,7 @@ ImmutableMultiset.Builder<T> before() {

@AfterTemplate
ImmutableMultiset.Builder<T> after() {
return ImmutableMultiset.builder();
return ImmutableMultiset.<T>builder();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ final class ImmutableSetMultimapTemplates {
private ImmutableSetMultimapTemplates() {}

/** Prefer {@link ImmutableSetMultimap#builder()} over the associated constructor. */
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
// XXX: Picnic's Error Prone fork supports method invocation type argument inlining in the
// `@AfterTemplate`. Without using the fork, the expression in the `@AfterTemplate` can result in
// non-compilable code. See: https://github.com/google/error-prone/pull/2706.
static final class ImmutableSetMultimapBuilder<K, V> {
@BeforeTemplate
ImmutableSetMultimap.Builder<K, V> before() {
Expand All @@ -37,7 +38,7 @@ ImmutableSetMultimap.Builder<K, V> before() {

@AfterTemplate
ImmutableSetMultimap.Builder<K, V> after() {
return ImmutableSetMultimap.builder();
return ImmutableSetMultimap.<K, V>builder();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ final class ImmutableSetTemplates {
private ImmutableSetTemplates() {}

/** Prefer {@link ImmutableSet#builder()} over the associated constructor. */
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
// XXX: Picnic's Error Prone fork supports method invocation type argument inlining in the
// `@AfterTemplate`. Without using the fork, the expression in the `@AfterTemplate` can result in
// non-compilable code. See: https://github.com/google/error-prone/pull/2706.
static final class ImmutableSetBuilder<T> {
@BeforeTemplate
ImmutableSet.Builder<T> before() {
Expand All @@ -35,7 +36,7 @@ ImmutableSet.Builder<T> before() {

@AfterTemplate
ImmutableSet.Builder<T> after() {
return ImmutableSet.builder();
return ImmutableSet.<T>builder();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ ImmutableSortedMap.Builder<K, V> after(Comparator<K> cmp) {
* Prefer {@link ImmutableSortedMap#naturalOrder()} over the alternative that requires explicitly
* providing the {@link Comparator}.
*/
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
// XXX: Picnic's Error Prone fork supports method invocation type argument inlining in the
// `@AfterTemplate`. Without using the fork, the expression in the `@AfterTemplate` can result in
// non-compilable code. See: https://github.com/google/error-prone/pull/2706.
static final class ImmutableSortedMapNaturalOrderBuilder<K extends Comparable<? super K>, V> {
@BeforeTemplate
ImmutableSortedMap.Builder<K, V> before() {
Expand All @@ -45,16 +46,17 @@ ImmutableSortedMap.Builder<K, V> before() {

@AfterTemplate
ImmutableSortedMap.Builder<K, V> after() {
return ImmutableSortedMap.naturalOrder();
return ImmutableSortedMap.<K, V>naturalOrder();
}
}

/**
* Prefer {@link ImmutableSortedMap#reverseOrder()} over the alternative that requires explicitly
* providing the {@link Comparator}.
*/
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
// XXX: Picnic's Error Prone fork supports method invocation type argument inlining in the
// `@AfterTemplate`. Without using the fork, the expression in the `@AfterTemplate` can result in
// non-compilable code. See: https://github.com/google/error-prone/pull/2706.
static final class ImmutableSortedMapReverseOrderBuilder<K extends Comparable<? super K>, V> {
@BeforeTemplate
ImmutableSortedMap.Builder<K, V> before() {
Expand All @@ -63,7 +65,7 @@ ImmutableSortedMap.Builder<K, V> before() {

@AfterTemplate
ImmutableSortedMap.Builder<K, V> after() {
return ImmutableSortedMap.reverseOrder();
return ImmutableSortedMap.<K, V>reverseOrder();
}
}

Expand Down

0 comments on commit 4f28ecb

Please sign in to comment.