Skip to content

Commit

Permalink
For Java 9+, flag usages of Streams.stream(Optional*)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 authored and gaul committed Jan 25, 2019
1 parent e3c8cf2 commit 9af8ee0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<version>27.0.1-jre</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
24 changes: 24 additions & 0 deletions src/main/resources/modernizer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1044,4 +1044,28 @@ violation names use the same format that javap emits.
<comment>Prefer java.util.Scanner(ReadableByteChannel, Charset)</comment>
</violation>

<violation>
<name>com/google/common/collect/Streams.stream:(Ljava/util/Optional;)Ljava/util/stream/Stream;</name>
<version>1.9</version>
<comment>Prefer java.util.Optional.stream()</comment>
</violation>

<violation>
<name>com/google/common/collect/Streams.stream:(Ljava/util/OptionalInt;)Ljava/util/stream/IntStream;</name>
<version>1.9</version>
<comment>Prefer java.util.OptionalInt.stream()</comment>
</violation>

<violation>
<name>com/google/common/collect/Streams.stream:(Ljava/util/OptionalLong;)Ljava/util/stream/LongStream;</name>
<version>1.9</version>
<comment>Prefer java.util.OptionalLong.stream()</comment>
</violation>

<violation>
<name>com/google/common/collect/Streams.stream:(Ljava/util/OptionalDouble;)Ljava/util/stream/DoubleStream;</name>
<version>1.9</version>
<comment>Prefer java.util.OptionalDouble.stream()</comment>
</violation>

</modernizer>
13 changes: 13 additions & 0 deletions src/test/java/org/gaul/modernizer_maven_plugin/ModernizerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.Scanner;
import java.util.Set;
import java.util.SortedMap;
Expand All @@ -63,6 +66,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import com.google.common.io.BaseEncoding;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
Expand Down Expand Up @@ -483,6 +487,11 @@ private static class VoidPredicate implements Predicate<Void> {
public boolean apply(Void input) {
return true;
}

@Override
public boolean test(Void input) {
return true;
}
}

private static class VoidSupplier implements Supplier<Void> {
Expand Down Expand Up @@ -645,6 +654,10 @@ private static void method() throws Exception {
object = Collections.EMPTY_LIST;
object = Collections.EMPTY_MAP;
object = Collections.EMPTY_SET;
Streams.stream(java.util.Optional.empty());
Streams.stream(OptionalInt.empty());
Streams.stream(OptionalLong.empty());
Streams.stream(OptionalDouble.empty());
}
}

Expand Down

0 comments on commit 9af8ee0

Please sign in to comment.