mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
IDEA-163991 ifPresent is not suggested when value is not used inside expression; OptionalIsPresentInspection uses CommentTracker now
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
|
||||
|
||||
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 -> Optional.empty()).orElseGet(() -> findAnnotation((AnnotatedElement) null));
|
||||
}
|
||||
|
||||
private static <A extends Annotation> Optional<A> findAnnotation(AnnotatedElement element) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
+10
-9
@@ -3,13 +3,14 @@
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public void testOptional(Optional<String> str) {
|
||||
String val;
|
||||
// line comment
|
||||
// another line comment
|
||||
//before trim
|
||||
/* block comment *//*block comment*/
|
||||
val = str.map(String::trim).orElse("");
|
||||
System.out.println(val);
|
||||
}
|
||||
public void testOptional(Optional<String> str) {
|
||||
String val;
|
||||
// line comment
|
||||
// another line comment
|
||||
/* block comment */
|
||||
/*block comment*/
|
||||
//before trim
|
||||
val = str.map(String::trim).orElse("");
|
||||
System.out.println(val);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
public void test(Optional<String> opt) {
|
||||
opt.ifPresent(s -> {
|
||||
if (s.equals("abc"))
|
||||
System.out.println(s);
|
||||
});
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public void testOptional(Optional<String> str) {
|
||||
str.ifPresent(s -> {
|
||||
System.out.println(s);
|
||||
// once again!
|
||||
System.out.println(s);
|
||||
});
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -11,7 +11,10 @@ public class Main {
|
||||
}
|
||||
|
||||
public Number testOptionalComments(Optional<MyList> strList) {
|
||||
/* optional is present *//*return something *//*too big*//* optional is absent *//* return null*/
|
||||
return strList.map(myList -> myList.size() > 1 ? myList.get(1) : 1.0).orElse(null);
|
||||
/* optional is present */
|
||||
/*return something */
|
||||
/* optional is absent */
|
||||
/* return null*/
|
||||
return strList.map(myList -> myList.size() > /*too big*/ 1 ? myList.get(1) : 1.0).orElse(null);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
|
||||
+11
-11
@@ -3,16 +3,16 @@
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public void testOptional(Optional<String> str) {
|
||||
String val;
|
||||
if (str.isPrese<caret>nt()) {
|
||||
val = // line comment
|
||||
// another line comment
|
||||
str.get()//before trim
|
||||
.trim() /* block comment *//*block comment*/;
|
||||
} else {
|
||||
val = "";
|
||||
public void testOptional(Optional<String> str) {
|
||||
String val;
|
||||
if (str.isPrese<caret>nt()) {
|
||||
val = // line comment
|
||||
// another line comment
|
||||
str.get()//before trim
|
||||
.trim() /* block comment *//*block comment*/;
|
||||
} else {
|
||||
val = "";
|
||||
}
|
||||
System.out.println(val);
|
||||
}
|
||||
System.out.println(val);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
public void test(Optional<String> opt) {
|
||||
if(opt.isPres<caret>ent()) {
|
||||
if(opt.get().equals("abc"))
|
||||
System.out.println(opt.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -6,6 +6,7 @@ public class Main {
|
||||
public void testOptional(Optional<String> str) {
|
||||
if (str.isPrese<caret>nt()) {
|
||||
System.out.println(str.get());
|
||||
// once again!
|
||||
System.out.println(str.get());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user