InlineUtil#surroundWithCast: support variables w/o type element

Review: IDEA-CR-23062
This commit is contained in:
Tagir Valeev
2017-07-19 16:46:43 +07:00
parent 9187ea4f11
commit f91a610b85
2 changed files with 7 additions and 4 deletions
@@ -148,10 +148,15 @@ public class InlineUtil {
}
private static PsiExpression surroundWithCast(PsiVariable variable, PsiExpression expr) {
PsiTypeCastExpression cast = (PsiTypeCastExpression)JavaPsiFacade.getElementFactory(expr.getProject()).createExpressionFromText("(t)a", null);
PsiElementFactory factory = JavaPsiFacade.getElementFactory(expr.getProject());
PsiTypeCastExpression cast = (PsiTypeCastExpression)factory.createExpressionFromText("(t)a", null);
PsiTypeElement castTypeElement = cast.getCastType();
assert castTypeElement != null;
castTypeElement.replace(variable.getTypeElement());
PsiTypeElement typeElement = variable.getTypeElement();
if (typeElement == null) {
typeElement = factory.createTypeElement(variable.getType());
}
castTypeElement.replace(typeElement);
final PsiExpression operand = cast.getOperand();
assert operand != null;
operand.replace(expr);
@@ -213,7 +213,6 @@ public class TrivialFunctionalExpressionUsageInspection extends BaseJavaBatchLoc
private static void replaceExpression(PsiMethodCallExpression callExpression, PsiLambdaExpression element) {
PsiExpression expression;
final CommentTracker ct = new CommentTracker();
LambdaRefactoringUtil.specifyLambdaParameterTypes(element);
inlineCallArguments(callExpression, element, ct);
// body could be invalidated after inlining
expression = LambdaUtil.extractSingleExpressionFromBody(element.getBody());
@@ -228,7 +227,6 @@ public class TrivialFunctionalExpressionUsageInspection extends BaseJavaBatchLoc
PsiMethodCallExpression callExpression = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
if (callExpression == null) return;
final CommentTracker ct = new CommentTracker();
LambdaRefactoringUtil.specifyLambdaParameterTypes(element);
inlineCallArguments(callExpression, element, ct);
body = element.getBody();
final PsiElement parent = callExpression.getParent();