StreamToLoopInspection: preserve comments; CommentTracker: now possible to delete element first and only after that register unchanged parts.

This commit is contained in:
Tagir Valeev
2016-12-23 18:09:43 +07:00
parent cd45987619
commit c9c574e428
20 changed files with 131 additions and 112 deletions
@@ -6,7 +6,7 @@ import java.util.stream.IntStream;
public class Main {
private static IntSummaryStatistics test() {
IntSummaryStatistics stat = new IntSummaryStatistics();
for (int i : new int[]{1, 2, 3}) {
for (int i : new int[]{1,/*two*/2,/*three*/3}) {
stat.accept(i);
}
return stat;
@@ -7,9 +7,10 @@ import java.util.List;
public class Main {
public static List<String> test() {
/*limit*/
List<String> list = new ArrayList<>();
long limit = 20;
for (String x = ""; ; x = x + "a") {
for (String x = ""; ; x = x /* add "a" */ + "a") {
if (limit-- == 0) break;
list.add(x);
}
@@ -11,6 +11,7 @@ public class Main {
for (Map.Entry<String, List<String>> e : strings.entrySet()) {
if (!e.getKey().isEmpty()) {
long count = e.getValue().stream().filter(new Predicate<String>() {
// we're inside anonymous class
@Override
public boolean test(String s) {
return e.getKey().equals(s);
@@ -6,12 +6,13 @@ import java.util.stream.Collectors;
public class Main {
public static void test(List<String> strings) {
// and collect
Map<Boolean, Map<String, Integer>> map = new HashMap<>();
map.put(false, new HashMap<>());
map.put(true, new HashMap<>());
for (String string : strings) {
String s = string.trim();
if (map.get(s.length() > 2).put(((UnaryOperator<String>) x -> x).apply(s), s.length()) != null) {
String s = string/*trimming*/.trim();
if (map.get(s.length() /*too big!*/ > 2).put(((UnaryOperator<String>) /* cast is necessary here */ x -> x).apply(s), s.length()) != null) {
throw new IllegalStateException("Duplicate key");
}
}
@@ -5,9 +5,10 @@ import java.util.function.LongSupplier;
public class Main {
private static void test(List<String> list) {
// and filter!
long count1 = 0;
for (String s : list) {
if (!s.isEmpty()) {
if (!s/* comment */.isEmpty()) {
count1++;
}
}
@@ -6,7 +6,7 @@ import java.util.stream.Stream;
public class Main {
private static IntSummaryStatistics test() {
IntSummaryStatistics stat = new IntSummaryStatistics();
for (Integer i : new Integer[]{1, 2, 3}) {
for (Integer i : new Integer[] /*create array*/{1, 2, 3}) {
int i1 = i;
stat.accept(i1);
}
@@ -8,7 +8,7 @@ import java.util.stream.Stream;
public class Main {
private static IntSummaryStatistics test() {
IntSummaryStatistics stat = new IntSummaryStatistics();
for (Supplier<Integer> sup : Arrays.<Supplier<Integer>>asList(() -> 1, () -> 2, () -> 3)) {
for (Supplier<Integer> sup : Arrays.<Supplier<Integer>>asList(() -> 1, /*between*/ () /*supply 2*/ -> 2, () -> 3)) {
int i = sup.get();
stat.accept(i);
}
@@ -5,7 +5,7 @@ import java.util.stream.IntStream;
public class Main {
private static IntSummaryStatistics test() {
return IntStream.of(1,2,3).summaryStatist<caret>ics();
return IntStream.of(1,/*two*/2,/*three*/3).summaryStatist<caret>ics();
}
public static void main(String[] args) {
@@ -6,7 +6,7 @@ import java.util.List;
public class Main {
public static List<String> test() {
return Stream.iterate("", x -> x + "a").limit(20).co<caret>llect(Collectors.toList());
return Stream.iterate("", x -> x /* add "a" */ + "a").limit(/*limit*/20).co<caret>llect(Collectors.toList());
}
public static void main(String[] args) {
@@ -8,6 +8,7 @@ public class Main {
private static long test(Map<String, List<String>> strings) {
return strings.entrySet().stream().filter(s -> !s.getKey().isEmpty()).mapToLong(e -> e.getValue().stream().filter(new Predicate<String>() {
// we're inside anonymous class
@Override
public boolean test(String s) {
return e.getKey().equals(s);
@@ -8,8 +8,10 @@ import java.util.stream.Collectors;
public class Main {
public static void test(List<String> strings) {
System.out.println(strings.stream().map(x -> x.trim()).colle<caret>ct(Collectors.partitioningBy(s -> s.length() > 2,
Collectors.toMap(s -> ((UnaryOperator<String>) x -> x).apply(s), String::length))));
System.out.println(strings.stream().map(x -> x/*trimming*/.trim()) // and collect
.colle<caret>ct(Collectors.partitioningBy(s -> s.length() /*too big!*/ > 2,
Collectors.toMap(s -> ((UnaryOperator<String>) /* cast is necessary here */ x -> x).apply(s),
String::length))));
}
public static void main(String[] args) {
@@ -5,7 +5,8 @@ import java.util.function.LongSupplier;
public class Main {
private static void test(List<String> list) {
long count = list.stream().filter(s -> !s.isEmpty()).co<caret>unt();
long count = list.stream(). // and filter!
filter(s -> !s/* comment */.isEmpty()).co<caret>unt();
if(count > 10) {
LongSupplier sup = () -> count*2;
long result = sup.get();
@@ -5,7 +5,7 @@ import java.util.stream.Stream;
public class Main {
private static IntSummaryStatistics test() {
return Stream.of(new Integer[] {1,2,3}).mapToInt(i -> i).summaryStatisti<caret>cs();
return Stream.of(new Integer[] /*create array*/{1,2,3}).mapToInt(i -> i).summaryStatisti<caret>cs();
}
public static void main(String[] args) {
@@ -6,7 +6,7 @@ import java.util.stream.Stream;
public class Main {
private static IntSummaryStatistics test() {
return Stream.<Supplier<Integer>>of(() -> 1, () -> 2, () -> 3).mapToInt(sup -> sup.get()).summar<caret>yStatistics();
return Stream.<Supplier<Integer>>of(() -> 1, /*between*/ () /*supply 2*/ -> 2, () -> 3).mapToInt(sup -> sup.get()).summar<caret>yStatistics();
}
public static void main(String[] args) {