StreamToLoop: do not trim trailing whitespace for block lambdas

Fixes trailing line comment handling
This commit is contained in:
Tagir Valeev
2018-06-26 12:35:26 +07:00
parent c640bd904f
commit 1a38128af4
3 changed files with 33 additions and 1 deletions

View File

@@ -619,7 +619,9 @@ abstract class FunctionHelper {
String getStatementText() {
PsiElement[] children = myBody.getChildren();
// Keep everything except braces
return StreamEx.of(children, 1, children.length - 1).map(PsiElement::getText).joining().trim();
return StreamEx.of(children, 1, children.length - 1)
.dropWhile(e -> e instanceof PsiWhiteSpace)
.map(PsiElement::getText).joining();
}
void transform(StreamToLoopReplacementContext context, String... argumentValues) {

View File

@@ -0,0 +1,15 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.io.File;
import java.util.Arrays;
class X {
void x(File[] files) {
for (File s: files) {
File dest = new File(s.getAbsolutePath());
System.out.println("unable to rename " + s + " to " + dest); //comment
}
}
}

View File

@@ -0,0 +1,15 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.io.File;
import java.util.Arrays;
class X {
void x(File[] files) {
Arrays.stream(files).forEachOrdered(s -> {
File dest = new File(s.getAbsolutePath());<caret>
System.out.println("unable to rename " + s + " to " + dest); //comment
});
}
}