IDEA-182623 Replace with collect swallows comments

This commit is contained in:
Tagir Valeev
2017-11-27 15:20:21 +07:00
parent 5b8f3b2bfe
commit 5b36191d2c
29 changed files with 306 additions and 263 deletions

View File

@@ -4,6 +4,12 @@ import java.util.stream.Collectors;
public class Main {
public void test(List<Set<String>> nested) {
List<String> result = nested.stream().filter(Objects::nonNull).flatMap(Collection::stream).filter(str -> str.startsWith("xyz")).map(String::trim).collect(Collectors.toList());
/*non-equal*//*empty*/
List<String> result = nested.stream().filter(Objects::nonNull).flatMap(Collection::stream).filter(str -> str./*startswith*/startsWith("xyz")).map(String::trim).collect(Collectors.toList());
// 1
/*target is here*/
// 2
// 3
// 4
}
}

View File

@@ -6,15 +6,15 @@ import java.util.Set;
public class Main {
public void test(List<Set<String>> nested) {
List<String> result = new ArrayList<>();
for (Set<String> element : nes<caret>ted) {
if (element != null) {
for (Set<String> element : nes<caret>ted) { // 1
if (element /*non-equal*/!= null) {
for (String str : element) {
if (str.startsWith("xyz")) {
String target = str.trim();
result.add(target);
}
}
}
if (str./*startswith*/startsWith("xyz")) {
String target = str.trim(/*empty*/);
result.add(/*target is here*/target);
} // 2
} // 3
} // 4
}
}
}

View File

@@ -6,8 +6,8 @@ import java.util.List;
public class Main {
public static String find(List<List<String>> list) {
/*
Block comment
*/
Block comment
*/
return list.stream().flatMap(Collection::stream).filter(string -> string.startsWith("ABC")).findFirst().map(string -> string.substring(3)).orElse("");
}
}

View File

@@ -6,8 +6,8 @@ import java.util.List;
public class Main {
public static boolean find(List<List<String>> list) {
/*
Block comment
*/
Block comment
*/
return list.stream().flatMap(Collection::stream).filter(string -> string.startsWith("ABC")).findFirst().filter(string -> string.substring(3).equals("xyz")).isPresent();
}
}

View File

@@ -8,6 +8,7 @@ import java.util.Optional;
public class Main {
private static String test(List<String> list) {
Optional<String> found = list.stream().filter(Objects::nonNull).findFirst();
// optional!
return found.orElse(null);
}

View File

@@ -4,6 +4,7 @@ import java.util.List;
public class Main {
public int testPrimitiveMap(List<String> data) {
return data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).filter(len -> len > 10).findFirst().orElse(0);
/*ten*/
return data.stream().filter(str -> str.startsWith("xyz")).mapToInt(String::length).filter(len -> len /*bigger*/ > 10).findFirst().orElse(0);
}
}

View File

@@ -5,10 +5,10 @@ import java.util.Map;
public class Main {
public void testMap(Map<String, List<String>> map) throws Exception {
int bigSize = 0;
int bigSize = 0; // initial
for(List<String> list : map.valu<caret>es()) {
int size = list.size();
if(size > 10) {
int size = list.size(); // size
if(size/*bigger*/ > 10) {
bigSize = size*2;
break;
}

View File

@@ -10,7 +10,7 @@ public class Main {
Optional<String> found = Optional.empty();
for (String s : li<caret>st) {
if (Objects.nonNull(s)) {
found = Optional.of(s);
found = Optional.of(s); // optional!
break;
}
}

View File

@@ -7,7 +7,7 @@ public class Main {
for(String str : dat<caret>a) {
if(str.startsWith("xyz")) {
int len = str.length();
if(len > 10) {
if(len /*bigger*/> 10 /*ten*/) {
return len;
}
}

View File

@@ -6,6 +6,9 @@ import java.util.stream.Collectors;
public class Test {
private static String work2(List<String> strs) {
String sb = strs.stream().collect(Collectors.joining(",", "{", "}"));
// before
// after
// inside
return sb;
}
}

View File

@@ -5,14 +5,14 @@ import java.util.List;
public class Test {
private static String work2(List<String> strs) {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("{"); // before
String separator = "";
for <caret> (String str : strs) {
sb.append(separator);
sb.append(separator); // inside
sb.append(str);
separator = ",";
}
sb.append("}");
sb.append("}"); // after
return sb.toString();
}
}

View File

@@ -27,7 +27,9 @@ public class Main {
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = personList.stream().filter(p -> p.getAge() > 13).max(Comparator.comparingInt(Person::getAge)).orElse(null);
/*age*/
Person maxPerson = personList.stream().filter(p -> p.getAge() > /*thirteen*/ 13).max(Comparator.comparingInt(Person::getAge)).orElse(null);
// max!
return maxPerson;
}

View File

@@ -29,9 +29,9 @@ public class Main {
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null || p.getAge() > maxPerson.getAge()) {
maxPerson = p;
if(p.getAge() > /*thirteen*/ 13) {
if (maxPerson == null || p./*age*/getAge() > maxPerson.getAge()) {
maxPerson = p; // max!
}
}
}