StreamApiMigration: add parentheses if necessary when .stream() can be omitted (fix for EA-93812).

This commit is contained in:
Tagir Valeev
2017-01-10 09:42:03 +06:00
parent a9b8f9c7f4
commit 3738e54fee
3 changed files with 22 additions and 2 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -447,7 +447,7 @@ class TerminalBlock {
String generate(boolean noStreamForEmpty) {
if(noStreamForEmpty && myOperations.length == 1 && myOperations[0] instanceof CollectionStream) {
return myOperations[0].getExpression().getText();
return ParenthesesUtils.getText(myOperations[0].getExpression(), ParenthesesUtils.POSTFIX_PRECEDENCE);
}
return StreamEx.of(myOperations).map(Operation::createReplacement).joining();
}
@@ -0,0 +1,9 @@
// "Replace with forEach" "true"
import java.util.Collection;
public class Test {
void test(Object obj) {
((Collection<String>) obj).forEach(System.out::println);
}
}
@@ -0,0 +1,11 @@
// "Replace with forEach" "true"
import java.util.Collection;
public class Test {
void test(Object obj) {
for(String str : (Collection<String>)<caret>obj) {
System.out.println(str);
}
}
}