Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/StreamCollector10Inlining.java
Tagir Valeev aa6829d7c1 [java-tests] IDEA-333831 Separate mock JDK and JetBrains annotations for testing
Also: avoid manual mocking of Java 10 classes in StreamCollector10Inlining test, use mockJDK11 instead
Also: rewrite SliceTestCase and its inheritors to LightJavaCodeInsightFixtureTestCase, as annotations.jar is not included into project created by DaemonAnalyzerTestCase
Also: 'mutates' attribute of @Contract annotation is resolvable now, as we can use newer jetbrains-annotations library.
Also: documentation tests now don't generate links to JetBrains annotations, which corresponds to the actual behavior in production

GitOrigin-RevId: e460826893c1277cb2b78b18aae9d5aca97d8333
2023-10-05 11:24:29 +00:00

40 lines
1.5 KiB
Java

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class StreamCollector10Inlining {
@Nullable
final String convert(String s) {
return s.isEmpty() ? null : s;
}
void testToList() {
List<String> list = Stream.of("foo", "bar", "baz").map(this::convert).collect(Collectors.toList());
list.sort(null);
}
void testToImmutableList() {
var list = Stream.of("foo", "bar", "baz")
.map(<warning descr="Function may return null, but it's not allowed here">this::convert</warning>)
.collect(Collectors.toUnmodifiableList());
list.<warning descr="Immutable object is modified">sort</warning>(null);
}
void testToImmutableSet() {
Set<String> set = Stream.of("foo", "bar", "baz")
.map(<warning descr="Function may return null, but it's not allowed here">this::convert</warning>)
.collect(Collectors.toUnmodifiableSet());
set.<warning descr="Immutable object is modified">add</warning>("qux");
}
void testToImmutableMap() {
var map = Stream.of("foo", "bar", "baz", "")
.collect(Collectors.toUnmodifiableMap(<warning descr="Function may return null, but it's not allowed here">this::convert</warning>, <warning descr="Function may return null, but it's not allowed here">this::convert</warning>));
map.<warning descr="Immutable object is modified">put</warning>("qux", "qux");
}
}