OptionalUtil#getMapTypeArgument: support PsiEmptyExpressionImpl input

Fixes EA-125157 - IOE: PsiJavaParserFacadeImpl.createExpressionFromText
This commit is contained in:
Tagir Valeev
2018-07-26 17:41:49 +07:00
parent ea7ac9eec7
commit ab3c5b7e5a
3 changed files with 28 additions and 2 deletions
@@ -228,8 +228,10 @@ public class OptionalUtil {
@NotNull
private static String getMapTypeArgument(PsiExpression expression, PsiType type, PsiExpression falseExpression) {
if (!(type instanceof PsiClassType)) return "";
PsiExpression copy =
JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(expression.getText(), expression);
String text = expression.getText();
// PsiEmptyExpressionImpl might be passed here
if (text.isEmpty()) return "";
PsiExpression copy = JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(text, expression);
PsiType exprType = copy.getType();
if (exprType != null &&
!exprType.equals(PsiType.NULL) &&
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
void test(List<String> list) {
List<String> result = list.stream().map(s ->).collect(Collectors.toList());
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
void test(List<String> list) {
List<String> result = new ArrayList<>();
f<caret>or (String s : list) {
result.add(;
}
}
}