mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inline: do not delete call but warn when resulted expr is not a valid statement (IDEA-88886)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
class AAA {
|
||||
void fff(Project myProject) {
|
||||
ensureFilesWritable(myProject, new String[1]);
|
||||
}
|
||||
|
||||
private boolean ensu<caret>reFilesWritable(final Project project, final String... strings) {
|
||||
return !ensureFilesWritable(strings).hasReadonlyFiles();
|
||||
}
|
||||
|
||||
private Status ensureFilesWritable(final String[] strings) {
|
||||
return new Status(strings);
|
||||
}
|
||||
|
||||
class Status {
|
||||
public Status(final String[] strings) {
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
boolean hasReadonlyFiles() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Project {
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,6 @@ class A {
|
||||
}
|
||||
|
||||
public String method(boolean b) {
|
||||
<caret>toInline(b);
|
||||
return <caret>toInline(b);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@ class A {
|
||||
|
||||
public String method(boolean b) {
|
||||
if (b) {
|
||||
return;
|
||||
return "b";
|
||||
}
|
||||
return "a";
|
||||
}
|
||||
}
|
||||
@@ -185,12 +185,20 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
public void testMethodUsedInJavadoc() throws Exception {
|
||||
doTestConflict("Inlined method is used in javadoc");
|
||||
}
|
||||
|
||||
public void testNotAStatement() throws Exception {
|
||||
doTestConflict("Inlined result won't be a valid statement");
|
||||
}
|
||||
|
||||
private void doTestConflict(final String conflict) throws Exception {
|
||||
try {
|
||||
doTest();
|
||||
fail("Conflict was not detected");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
assertEquals("Inlined method is used in javadoc", e.getMessage());
|
||||
assertEquals(conflict, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user