OptionalToIfInspection: cr fixes (IDEA-CR-51167)

1. add new line before and after code block braces when wrapping user code
2. add example in inspection description
3. remove OptionalToIfInspectionTest#runSingle
4. remove duplicates from operation names list
5. remove unnecessary whitespaces from strings with converted operations
6. support final variables and local variables with implicit type
7. honor operation precedence when merging two if checks during simplification
8. StringUtil#join instead of Collectors#joining
9. remove code after throw during simplification

GitOrigin-RevId: cd3273072ad3bdba21aa5b28a6fd13dc325e93ad
This commit is contained in:
Artemiy Sartakov
2020-04-21 08:19:27 +00:00
committed by intellij-monorepo-bot
parent 1c030d1129
commit db85d0d62b
17 changed files with 172 additions and 68 deletions
@@ -0,0 +1,34 @@
// "Fix all 'Optional can be replaced with sequence of if statements' problems in file" "true"
import java.util.*;
class Test {
boolean isPresent(String in) {
if (in == null) throw new NullPointerException();
String s = in.substring(3);
if (s.startsWith("1")) return true;
return false;
}
boolean isPresentFinalVariable(String in) {
String result = false;
if (in != null) result = true;
@Deprecated final String isPresent = result;
Runnable r = () -> System.out.println(isPresent);
}
boolean isPresentCanBeNonFinalVariable(String in) {
var isPresent = false;
if (in != null) isPresent = true;
System.out.println(isPresent);
}
boolean isEmpty(String in) {
if (in == null) throw new NullPointerException();
String s = in.substring(3);
if (s.startsWith("1")) return false;
return true;
}
}