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 Mar 31, 2022
1 parent 793a70c commit 1dd72a3
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ private ImmutableListMultimapTemplates() {}
/**
* Prefer {@link ImmutableListMultimap#builder()} over the associated constructor on constructions
* that produce a less-specific type.
*
* <p>Picnic's Error Prone fork supports inlining of method arguments in the `@AfterTemplate`.
* Without using the fork, the expression in the `@AfterTemplate` can result in non-compilable
* code.
*
* <p>See: https://github.com/google/error-prone/pull/2706.
*/
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
static final class ImmutableListMultimapBuilder<K, V> {
@BeforeTemplate
ImmutableMultimap.Builder<K, V> before() {
Expand All @@ -46,7 +50,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 @@ -26,9 +26,15 @@
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?
/**
* Prefer {@link ImmutableList#builder()} over the associated constructor.
*
* <p>Picnic's Error Prone fork supports inlining of method arguments in the `@AfterTemplate`.
* Without using the fork, the expression in the `@AfterTemplate` can result in non-compilable
* code.
*
* <p>See: https://github.com/google/error-prone/pull/2706.
*/
static final class ImmutableListBuilder<T> {
@BeforeTemplate
ImmutableList.Builder<T> before() {
Expand All @@ -37,7 +43,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 @@ -25,9 +25,15 @@
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?
/**
* Prefer {@link ImmutableMap#builder()} over the associated constructor.
*
* <p>Picnic's Error Prone fork supports inlining of method arguments in the `@AfterTemplate`.
* Without using the fork, the expression in the `@AfterTemplate` can result in non-compilable
* code.
*
* <p>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 +42,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 @@ -20,9 +20,15 @@
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?
/**
* Prefer {@link ImmutableMultiset#builder()} over the associated constructor.
*
* <p>Picnic's Error Prone fork supports inlining of method arguments in the `@AfterTemplate`.
* Without using the fork, the expression in the `@AfterTemplate` can result in non-compilable
* code.
*
* <p>See: https://github.com/google/error-prone/pull/2706.
*/
static final class ImmutableMultisetBuilder<T> {
@BeforeTemplate
ImmutableMultiset.Builder<T> before() {
Expand All @@ -31,7 +37,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 @@ -26,9 +26,15 @@
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?
/**
* Prefer {@link ImmutableSetMultimap#builder()} over the associated constructor.
*
* <p>Picnic's Error Prone fork supports inlining of method arguments in the `@AfterTemplate`.
* Without using the fork, the expression in the `@AfterTemplate` can result in non-compilable
* code.
*
* <p>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 +43,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 @@ -24,9 +24,15 @@
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?
/**
* Prefer {@link ImmutableSet#builder()} over the associated constructor.
*
* <p>Picnic's Error Prone fork supports inlining of method arguments in the `@AfterTemplate`.
* Without using the fork, the expression in the `@AfterTemplate` can result in non-compilable
* code.
*
* <p>See: https://github.com/google/error-prone/pull/2706.
*/
static final class ImmutableSetBuilder<T> {
@BeforeTemplate
ImmutableSet.Builder<T> before() {
Expand All @@ -35,7 +41,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 @@ -34,9 +34,13 @@ ImmutableSortedMap.Builder<K, V> after(Comparator<K> cmp) {
/**
* Prefer {@link ImmutableSortedMap#naturalOrder()} over the alternative that requires explicitly
* providing the {@link Comparator}.
*
* <p>Picnic's Error Prone fork supports inlining of method arguments in the `@AfterTemplate`.
* Without using the fork, the expression in the `@AfterTemplate` can result in non-compilable
* code.
*
* <p>See: https://github.com/google/error-prone/pull/2706.
*/
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
static final class ImmutableSortedMapNaturalOrderBuilder<K extends Comparable<? super K>, V> {
@BeforeTemplate
ImmutableSortedMap.Builder<K, V> before() {
Expand All @@ -45,16 +49,20 @@ 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}.
*
* <p>Picnic's Error Prone fork supports inlining of method arguments in the `@AfterTemplate`.
* Without using the fork, the expression in the `@AfterTemplate` can result in non-compilable
* code.
*
* <p>See: https://github.com/google/error-prone/pull/2706.
*/
// XXX: This drops generic type information, sometimes leading to non-compilable code. Anything
// we can do about that?
static final class ImmutableSortedMapReverseOrderBuilder<K extends Comparable<? super K>, V> {
@BeforeTemplate
ImmutableSortedMap.Builder<K, V> before() {
Expand All @@ -63,7 +71,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 1dd72a3

Please sign in to comment.