Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve naming of assorted Refaster templates and associated tests #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ static final class AssertThatMultisetsAreEqual<S, T extends S> {
// Map
//

static final class AssertThatMapIsEmpty<K, V> {
static final class AbstractMapAssertIsEmpty<K, V> {
@BeforeTemplate
@SuppressWarnings("unchecked")
void before(AbstractMapAssert<?, ?, K, V> mapAssert) {
Expand Down Expand Up @@ -615,8 +615,7 @@ void after(AbstractMapAssert<?, ?, K, V> mapAssert) {
}
}

// XXX: Find a better name.
static final class AssertThatMapIsEmpty2<K, V> {
static final class AssertThatMapIsEmpty<K, V> {
@BeforeTemplate
void before(Map<K, V> map) {
Refaster.anyOf(
Expand All @@ -638,7 +637,7 @@ void after(Map<K, V> map) {
}
}

static final class AssertThatMapIsNotEmpty<K, V> {
static final class AbstractMapAssertIsNotEmpty<K, V> {
@BeforeTemplate
AbstractMapAssert<?, ?, K, V> before(AbstractMapAssert<?, ?, K, V> mapAssert) {
return mapAssert.isNotEqualTo(
Expand All @@ -657,8 +656,7 @@ static final class AssertThatMapIsNotEmpty<K, V> {
}
}

// XXX: Find a better name.
static final class AssertThatMapIsNotEmpty2<K, V> {
static final class AssertThatMapIsNotEmpty<K, V> {
@BeforeTemplate
AbstractAssert<?, ?> before(Map<K, V> map) {
return Refaster.anyOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ OptionalDouble after(DoubleStream stream) {
}

/** Prefer {@link DoubleStream#noneMatch(DoublePredicate)} over more contrived alternatives. */
static final class DoubleStreamNoneMatch {
static final class DoubleStreamNoneMatchDoublePredicate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below: I wonder whether in this case the original naming is more natural, since the lambda expression below also represents a DoublePredicate. (Or maybe we can do something more creative 🤔.)

@BeforeTemplate
boolean before(DoubleStream stream, DoublePredicate predicate) {
return Refaster.anyOf(
Expand All @@ -201,7 +201,7 @@ boolean after(DoubleStream stream, DoublePredicate predicate) {
}
}

abstract static class DoubleStreamNoneMatch2 {
abstract static class DoubleStreamNoneMatch {
@Placeholder
abstract boolean test(@MayOptionallyUse double element);

Expand Down Expand Up @@ -230,7 +230,7 @@ boolean after(DoubleStream stream, DoublePredicate predicate) {
}
}

static final class DoubleStreamAllMatch {
static final class DoubleStreamAllMatchDoublePredicate {
@BeforeTemplate
boolean before(DoubleStream stream, DoublePredicate predicate) {
return stream.noneMatch(predicate.negate());
Expand All @@ -242,7 +242,7 @@ boolean after(DoubleStream stream, DoublePredicate predicate) {
}
}

abstract static class DoubleStreamAllMatch2 {
abstract static class DoubleStreamAllMatch {
@Placeholder
abstract boolean test(@MayOptionallyUse double element);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ ImmutableListMultimap<K, V> after(
* Prefer creating an immutable copy of the result of {@link Multimaps#transformValues(Multimap,
* com.google.common.base.Function)} over creating and directly collecting a stream.
*/
abstract static class TransformMultimapValuesToImmutableListMultimap<K, V1, V2> {
abstract static class ImmutableListMultimapCopyOfMultimapsTransformValues<K, V1, V2> {
@Placeholder(allowsIdentity = true)
abstract V2 valueTransformation(@MayOptionallyUse V1 value);

Expand All @@ -227,7 +227,7 @@ ImmutableListMultimap<K, V2> after(Multimap<K, V1> multimap) {
* Prefer creating an immutable copy of the result of {@link Multimaps#transformValues(Multimap,
* com.google.common.base.Function)} over creating and directly collecting a stream.
*/
static final class TransformMultimapValuesToImmutableListMultimap2<K, V1, V2> {
static final class ImmutableListMultimapCopyOfMultimapsTransformValuesTransformation<K, V1, V2> {
// XXX: Drop the `Refaster.anyOf` if we decide to rewrite one to the other.
@BeforeTemplate
ImmutableListMultimap<K, V2> before(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ImmutableSetMultimap<K, V> after(
* Don't map a a stream's elements to map entries, only to subsequently collect them into an
* {@link ImmutableSetMultimap}. The collection can be performed directly.
*/
abstract static class StreamOfMapEntriesToImmutableSetMultimap<E, K, V> {
abstract static class StreamCollectToImmutableSetMultimap<E, K, V> {
@Placeholder(allowsIdentity = true)
abstract K keyFunction(@MayOptionallyUse E element);

Expand All @@ -148,7 +148,7 @@ ImmutableSetMultimap<K, V> after(Stream<E> stream) {
* Prefer creating an immutable copy of the result of {@link Multimaps#transformValues(Multimap,
* com.google.common.base.Function)} over creating and directly collecting a stream.
*/
abstract static class TransformMultimapValuesToImmutableSetMultimap<K, V1, V2> {
abstract static class ImmutableSetMultimapCopyOfMultimapsTransformValues<K, V1, V2> {
@Placeholder(allowsIdentity = true)
abstract V2 valueTransformation(@MayOptionallyUse V1 value);

Expand All @@ -170,7 +170,7 @@ ImmutableSetMultimap<K, V2> after(Multimap<K, V1> multimap) {
* Prefer creating an immutable copy of the result of {@link Multimaps#transformValues(Multimap,
* com.google.common.base.Function)} over creating and directly collecting a stream.
*/
static final class TransformMultimapValuesToImmutableSetMultimap2<K, V1, V2> {
static final class ImmutableSetMultimapCopyOfMultimapsTransformValuesTransformation<K, V1, V2> {
// XXX: Drop the `Refaster.anyOf` if we decide to rewrite one to the other.
@BeforeTemplate
ImmutableSetMultimap<K, V2> before(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ OptionalInt after(IntStream stream) {
}

/** Prefer {@link IntStream#noneMatch(IntPredicate)} over more contrived alternatives. */
static final class IntStreamNoneMatch {
static final class IntStreamNoneMatchIntPredicate {
@BeforeTemplate
boolean before(IntStream stream, IntPredicate predicate) {
return Refaster.anyOf(
Expand All @@ -214,7 +214,7 @@ boolean after(IntStream stream, IntPredicate predicate) {
}
}

abstract static class IntStreamNoneMatch2 {
abstract static class IntStreamNoneMatch {
@Placeholder
abstract boolean test(@MayOptionallyUse int element);

Expand Down Expand Up @@ -243,7 +243,7 @@ boolean after(IntStream stream, IntPredicate predicate) {
}
}

static final class IntStreamAllMatch {
static final class IntStreamAllMatchIntPredicate {
@BeforeTemplate
boolean before(IntStream stream, IntPredicate predicate) {
return stream.noneMatch(predicate.negate());
Expand All @@ -255,7 +255,7 @@ boolean after(IntStream stream, IntPredicate predicate) {
}
}

abstract static class IntStreamAllMatch2 {
abstract static class IntStreamAllMatch {
@Placeholder
abstract boolean test(@MayOptionallyUse int element);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ OptionalLong after(LongStream stream) {
}

/** Prefer {@link LongStream#noneMatch(LongPredicate)} over more contrived alternatives. */
static final class LongStreamNoneMatch {
static final class LongStreamNoneMatchLongPredicate {
@BeforeTemplate
boolean before(LongStream stream, LongPredicate predicate) {
return Refaster.anyOf(
Expand All @@ -214,7 +214,7 @@ boolean after(LongStream stream, LongPredicate predicate) {
}
}

abstract static class LongStreamNoneMatch2 {
abstract static class LongStreamNoneMatch {
@Placeholder
abstract boolean test(@MayOptionallyUse long element);

Expand Down Expand Up @@ -243,7 +243,7 @@ boolean after(LongStream stream, LongPredicate predicate) {
}
}

static final class LongStreamAllMatch {
static final class LongStreamAllMatchLongPredicate {
@BeforeTemplate
boolean before(LongStream stream, LongPredicate predicate) {
return stream.noneMatch(predicate.negate());
Expand All @@ -255,7 +255,7 @@ boolean after(LongStream stream, LongPredicate predicate) {
}
}

abstract static class LongStreamAllMatch2 {
abstract static class LongStreamAllMatch {
@Placeholder
abstract boolean test(@MayOptionallyUse long element);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Optional<T> after(Stream<T> stream) {
}

/** Prefer {@link Stream#noneMatch(Predicate)} over more contrived alternatives. */
static final class StreamNoneMatch<T> {
static final class StreamNoneMatchPredicate<T> {
@BeforeTemplate
boolean before(Stream<T> stream, Predicate<? super T> predicate) {
return Refaster.anyOf(
Expand All @@ -284,7 +284,7 @@ boolean after(Stream<T> stream, Predicate<? super T> predicate) {
}
}

abstract static class StreamNoneMatch2<T> {
abstract static class StreamNoneMatch<T> {
@Placeholder(allowsIdentity = true)
abstract boolean test(@MayOptionallyUse T element);

Expand Down Expand Up @@ -313,7 +313,7 @@ boolean after(Stream<T> stream, Predicate<? super T> predicate) {
}
}

static final class StreamAllMatch<T> {
static final class StreamAllMatchPredicate<T> {
@BeforeTemplate
boolean before(Stream<T> stream, Predicate<? super T> predicate) {
return stream.noneMatch(Refaster.anyOf(not(predicate), predicate.negate()));
Expand All @@ -325,7 +325,7 @@ boolean after(Stream<T> stream, Predicate<? super T> predicate) {
}
}

abstract static class StreamAllMatch2<T> {
abstract static class StreamAllMatch<T> {
@Placeholder(allowsIdentity = true)
abstract boolean test(@MayOptionallyUse T element);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.google.common.collect.Iterables;
import org.assertj.core.api.EnumerableAssert;

final class AssertJEnumableTemplatesTest implements RefasterTemplateTestCase {
final class AssertJEnumerableTemplatesTest implements RefasterTemplateTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(Iterables.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.google.common.collect.Iterables;
import org.assertj.core.api.EnumerableAssert;

final class AssertJEnumableTemplatesTest implements RefasterTemplateTestCase {
final class AssertJEnumerableTemplatesTest implements RefasterTemplateTestCase {
@Override
public ImmutableSet<?> elidedTypesAndStaticImports() {
return ImmutableSet.of(Iterables.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ OptionalDouble testDoubleStreamMin() {
return DoubleStream.of(1).sorted().findFirst();
}

ImmutableSet<Boolean> testDoubleStreamNoneMatch() {
ImmutableSet<Boolean> testDoubleStreamNoneMatchDoublePredicate() {
DoublePredicate pred = i -> i > 0;
return ImmutableSet.of(
!DoubleStream.of(1).anyMatch(n -> n > 1),
DoubleStream.of(2).allMatch(pred.negate()),
DoubleStream.of(3).filter(pred).findAny().isEmpty());
}

boolean testDoubleStreamNoneMatch2() {
boolean testDoubleStreamNoneMatch() {
return DoubleStream.of(1).allMatch(n -> !(n > 1));
}

Expand All @@ -83,12 +83,12 @@ ImmutableSet<Boolean> testDoubleStreamAnyMatch() {
DoubleStream.of(2).filter(n -> n > 2).findAny().isPresent());
}

boolean testDoubleStreamAllMatch() {
boolean testDoubleStreamAllMatchDoublePredicate() {
DoublePredicate pred = i -> i > 0;
return DoubleStream.of(1).noneMatch(pred.negate());
}

boolean testDoubleStreamAllMatch2() {
boolean testDoubleStreamAllMatch() {
return DoubleStream.of(1).noneMatch(n -> !(n > 1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ OptionalDouble testDoubleStreamMin() {
return DoubleStream.of(1).min();
}

ImmutableSet<Boolean> testDoubleStreamNoneMatch() {
ImmutableSet<Boolean> testDoubleStreamNoneMatchDoublePredicate() {
DoublePredicate pred = i -> i > 0;
return ImmutableSet.of(
DoubleStream.of(1).noneMatch(n -> n > 1),
DoubleStream.of(2).noneMatch(pred),
DoubleStream.of(3).noneMatch(pred));
}

boolean testDoubleStreamNoneMatch2() {
boolean testDoubleStreamNoneMatch() {
return DoubleStream.of(1).noneMatch(n -> n > 1);
}

Expand All @@ -82,12 +82,12 @@ ImmutableSet<Boolean> testDoubleStreamAnyMatch() {
DoubleStream.of(1).anyMatch(n -> n > 1), DoubleStream.of(2).anyMatch(n -> n > 2));
}

boolean testDoubleStreamAllMatch() {
boolean testDoubleStreamAllMatchDoublePredicate() {
DoublePredicate pred = i -> i > 0;
return DoubleStream.of(1).allMatch(pred);
}

boolean testDoubleStreamAllMatch2() {
boolean testDoubleStreamAllMatch() {
return DoubleStream.of(1).allMatch(n -> n > 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ ImmutableSet<ImmutableListMultimap<Integer, Integer>> testIndexIterableToImmutab
.collect(toImmutableListMultimap(n -> n.intValue(), identity())));
}

ImmutableListMultimap<String, Integer> testTransformMultimapValuesToImmutableListMultimap() {
ImmutableListMultimap<String, Integer> testImmutableListMultimapCopyOfMultimapsTransformValues() {
return ImmutableListMultimap.of("foo", 1L).entries().stream()
.collect(toImmutableListMultimap(Map.Entry::getKey, e -> Math.toIntExact(e.getValue())));
}

ImmutableSet<ImmutableListMultimap<String, Integer>>
testTransformMultimapValuesToImmutableListMultimap2() {
testImmutableListMultimapCopyOfMultimapsTransformValuesTransformation() {
return ImmutableSet.of(
ImmutableSetMultimap.of("foo", 1L).asMap().entrySet().stream()
.collect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ ImmutableSet<ImmutableListMultimap<Integer, Integer>> testIndexIterableToImmutab
Multimaps.index(ImmutableList.of(3).iterator(), n -> n.intValue()));
}

ImmutableListMultimap<String, Integer> testTransformMultimapValuesToImmutableListMultimap() {
ImmutableListMultimap<String, Integer> testImmutableListMultimapCopyOfMultimapsTransformValues() {
return ImmutableListMultimap.copyOf(
Multimaps.transformValues(ImmutableListMultimap.of("foo", 1L), v -> Math.toIntExact(v)));
}

ImmutableSet<ImmutableListMultimap<String, Integer>>
testTransformMultimapValuesToImmutableListMultimap2() {
testImmutableListMultimapCopyOfMultimapsTransformValuesTransformation() {
return ImmutableSet.of(
ImmutableListMultimap.copyOf(
Multimaps.transformValues(ImmutableSetMultimap.of("foo", 1L), Math::toIntExact)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ ImmutableSet<ImmutableSetMultimap<String, Integer>> testIterableToImmutableSetMu
.collect(toImmutableSetMultimap(Map.Entry::getKey, Map.Entry::getValue)));
}

ImmutableSetMultimap<Integer, String> testStreamOfMapEntriesToImmutableSetMultimap() {
ImmutableSetMultimap<Integer, String> testStreamCollectToImmutableSetMultimap() {
return Stream.of(1, 2, 3)
.map(n -> Map.entry(n, n.toString()))
.collect(toImmutableSetMultimap(Map.Entry::getKey, Map.Entry::getValue));
}

ImmutableSetMultimap<String, Integer> testTransformMultimapValuesToImmutableSetMultimap() {
ImmutableSetMultimap<String, Integer> testImmutableSetMultimapCopyOfMultimapsTransformValues() {
return ImmutableSetMultimap.of("foo", 1L).entries().stream()
.collect(toImmutableSetMultimap(Map.Entry::getKey, e -> Math.toIntExact(e.getValue())));
}

ImmutableSet<ImmutableSetMultimap<String, Integer>>
testTransformMultimapValuesToImmutableSetMultimap2() {
testImmutableSetMultimapCopyOfMultimapsTransformValuesTransformation() {
return ImmutableSet.of(
ImmutableSetMultimap.of("foo", 1L).asMap().entrySet().stream()
.collect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ ImmutableSet<ImmutableSetMultimap<String, Integer>> testIterableToImmutableSetMu
ImmutableSetMultimap.copyOf(Iterables.cycle(Map.entry("foo", 1))));
}

ImmutableSetMultimap<Integer, String> testStreamOfMapEntriesToImmutableSetMultimap() {
ImmutableSetMultimap<Integer, String> testStreamCollectToImmutableSetMultimap() {
return Stream.of(1, 2, 3).collect(toImmutableSetMultimap(n -> n, n -> n.toString()));
}

ImmutableSetMultimap<String, Integer> testTransformMultimapValuesToImmutableSetMultimap() {
ImmutableSetMultimap<String, Integer> testImmutableSetMultimapCopyOfMultimapsTransformValues() {
return ImmutableSetMultimap.copyOf(
Multimaps.transformValues(ImmutableSetMultimap.of("foo", 1L), e -> Math.toIntExact(e)));
}

ImmutableSet<ImmutableSetMultimap<String, Integer>>
testTransformMultimapValuesToImmutableSetMultimap2() {
testImmutableSetMultimapCopyOfMultimapsTransformValuesTransformation() {
return ImmutableSet.of(
ImmutableSetMultimap.copyOf(
Multimaps.transformValues(ImmutableSetMultimap.of("foo", 1L), Math::toIntExact)),
Expand Down
Loading