IDEA-163764 "Replace Optional.isPresent() checks with functional-style expressions" create uncompilable code

IDEA-163463 Stream API migration: type argument before map appears sometimes when it's unnecessary
This commit is contained in:
Tagir Valeev
2016-11-11 11:28:44 +07:00
parent 67c4dfb483
commit 7e574d661c
16 changed files with 190 additions and 16 deletions
@@ -0,0 +1,15 @@
// "Replace Optional.isPresent() condition with functional style expression" "true"
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Optional;
public class Main<T> {
public static <A extends Annotation> Optional<A> findAnnotation(Optional<? extends AnnotatedElement> element) {
return element.<Optional<A>>map(annotatedElement -> annotatedElement.getAnnotations().length == 0 ? Optional.empty() : null).orElseGet(() -> findAnnotation((AnnotatedElement) null));
}
private static <A extends Annotation> Optional<A> findAnnotation(AnnotatedElement element) {
return Optional.empty();
}
}
@@ -0,0 +1,9 @@
// "Replace Optional.isPresent() condition with functional style expression" "true"
import java.util.*;
public class Main {
public static Runnable get(Optional<String> s) {
return s.<Runnable>map(s1 -> s1::trim).orElse(null);
}
}
@@ -0,0 +1,18 @@
// "Replace Optional.isPresent() condition with functional style expression" "true"
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Optional;
public class Main<T> {
public static <A extends Annotation> Optional<A> findAnnotation(Optional<? extends AnnotatedElement> element) {
if (element.isPre<caret>sent()) {
return element.get().getAnnotations().length == 0 ? Optional.empty() : null;
}
return findAnnotation((AnnotatedElement)null);
}
private static <A extends Annotation> Optional<A> findAnnotation(AnnotatedElement element) {
return Optional.empty();
}
}
@@ -0,0 +1,18 @@
// "Replace Optional.isPresent() condition with functional style expression" "false"
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.Optional;
public class Main<T> {
public static <A extends Annotation> Optional<A> findAnnotation(Optional<? extends AnnotatedElement> element) {
if (element.isPre<caret>sent()) {
return Optional.empty();
}
return findAnnotation((AnnotatedElement)null);
}
private static <A extends Annotation> Optional<A> findAnnotation(AnnotatedElement element) {
return Optional.empty();
}
}
@@ -0,0 +1,12 @@
// "Replace Optional.isPresent() condition with functional style expression" "true"
import java.util.*;
public class Main {
public static Runnable get(Optional<String> s) {
if(s.isPres<caret>ent()) {
return s.get()::trim;
}
return null;
}
}