mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inline: remove side effect free unused after inline return (IDEA-169056)
This commit is contained in:
@@ -233,7 +233,8 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
final PsiReturnStatement[] returnStatements = PsiUtil.findReturnStatements(myMethod);
|
||||
for (PsiReturnStatement statement : returnStatements) {
|
||||
PsiExpression value = statement.getReturnValue();
|
||||
if (value != null && !(value instanceof PsiCallExpression)) {
|
||||
if (value != null && !(value instanceof PsiCallExpression) &&
|
||||
RemoveUnusedVariableUtil.checkSideEffects(value, null, new ArrayList<>())) {
|
||||
for (UsageInfo info : usagesIn) {
|
||||
PsiReference reference = info.getReference();
|
||||
if (reference != null) {
|
||||
@@ -894,7 +895,8 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
if (returnValue == null) continue;
|
||||
PsiStatement statement;
|
||||
if (tailCallType == InlineUtil.TailCallType.Simple) {
|
||||
if (returnValue instanceof PsiExpression && returnStatement.getNextSibling() == myMethodCopy.getBody().getLastBodyElement()) {
|
||||
if (returnStatement.getNextSibling() == myMethodCopy.getBody().getLastBodyElement() &&
|
||||
RemoveUnusedVariableUtil.checkSideEffects(returnValue, null, new ArrayList<>())) {
|
||||
PsiExpressionStatement exprStatement = (PsiExpressionStatement) myFactory.createStatementFromText("a;", null);
|
||||
exprStatement.getExpression().replace(returnValue);
|
||||
returnStatement.getParent().addBefore(exprStatement, returnStatement);
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
class InlineMethod {
|
||||
void test() {
|
||||
oth<caret>er();
|
||||
}
|
||||
|
||||
InlineMethod other() {
|
||||
System.out.println("");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
class InlineMethod {
|
||||
void test() {
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
InlineMethod other() {
|
||||
System.out.println("");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -359,6 +359,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
doTestInlineThisOnly();
|
||||
}
|
||||
|
||||
public void testRemoveReturnForTailTypeSimpleWhenNoSideEffectsPossible() {
|
||||
doTestInlineThisOnly();
|
||||
}
|
||||
|
||||
public void testDeleteOverrideAnnotations() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user