Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceWithTrivialLambda/afterMethodRef.java
Tagir Valeev a53282bc9a [java-dfa] Introduce DfaAnchor
Avoid dependency on PsiExpression or PsiExpression+range; more flexible anchoring for values

GitOrigin-RevId: be671152c5a11aed4f0474094a4d193e9849ed93
2021-04-29 11:25:06 +00:00

29 lines
826 B
Java

// "Fix all 'Constant conditions & exceptions' problems in file" "true"
import org.jetbrains.annotations.*;
import java.util.*;
import java.util.stream.Stream;
public class MethodReferenceConstantValue {
@Contract(value = "!null -> false", pure = true)
public boolean strangeMethod(String s) {
return s == null ? new Random().nextBoolean() : false;
}
public void test(Optional<String> opt) {
X x = MethodReferenceConstantValue::strangeMethod;
Boolean aBoolean = opt.map(s -> false)
.map(o1 -> true)
.map(o -> false)
.orElse(new Random().nextBoolean());
if (opt.isPresent()) {
Stream.generate(() -> true)
.limit(10)
.forEach(System.out::println);
}
}
interface X {
boolean action(@Nullable MethodReferenceConstantValue a, @NotNull String b);
}
}