inline: do not delete call but warn when resulted expr is not a valid statement (IDEA-88886)

This commit is contained in:
anna
2012-07-16 19:20:51 +02:00
parent bea215be6b
commit 41932a9527
5 changed files with 54 additions and 4 deletions
@@ -190,6 +190,21 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
}
}
final PsiReturnStatement[] returnStatements = RefactoringUtil.findReturnStatements(myMethod);
for (PsiReturnStatement statement : returnStatements) {
PsiExpression value = statement.getReturnValue();
if (value != null && !(value instanceof PsiCallExpression)) {
for (UsageInfo info : usagesIn) {
PsiReference reference = info.getReference();
InlineUtil.TailCallType type = InlineUtil.getTailCallType(reference);
if (type == InlineUtil.TailCallType.Simple) {
conflicts.putValue(statement, "Inlined result won't be a valid statement");
break;
}
}
}
}
addInaccessibleMemberConflicts(myMethod, usagesIn, new ReferencedElementsCollector(), conflicts);
addInaccessibleSuperCallsConflicts(usagesIn, conflicts);
@@ -730,7 +745,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
if (returnValue == null) continue;
PsiStatement statement;
if (tailCallType == InlineUtil.TailCallType.Simple) {
if (returnValue instanceof PsiCallExpression) {
if (returnValue instanceof PsiExpression) {
PsiExpressionStatement exprStatement = (PsiExpressionStatement) myFactory.createStatementFromText("a;", null);
exprStatement.getExpression().replace(returnValue);
returnStatement.getParent().addBefore(exprStatement, returnStatement);