mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
inline variable: if def in assignment expr replace with def if not stmt
otherwise containing expression would miss a part (IDEA-152813)
This commit is contained in:
@@ -273,7 +273,7 @@ public class InlineLocalHandler extends JavaInlineActionHandler {
|
||||
|
||||
if (inlineAll.get()) {
|
||||
if (!isInliningVariableInitializer(defToInline)) {
|
||||
defToInline.getParent().delete();
|
||||
deleteInitializer(defToInline);
|
||||
} else {
|
||||
defToInline.delete();
|
||||
}
|
||||
@@ -306,6 +306,19 @@ public class InlineLocalHandler extends JavaInlineActionHandler {
|
||||
CommandProcessor.getInstance().executeCommand(project, () -> PostprocessReformattingAspect.getInstance(project).postponeFormattingInside(runnable), RefactoringBundle.message("inline.command", localName), null);
|
||||
}
|
||||
|
||||
private static void deleteInitializer(@NotNull PsiExpression defToInline) {
|
||||
PsiElement parent = defToInline.getParent();
|
||||
if (parent instanceof PsiAssignmentExpression) {
|
||||
PsiElement gParent = PsiUtil.skipParenthesizedExprUp(parent.getParent());
|
||||
if (!(gParent instanceof PsiExpressionStatement)) {
|
||||
parent.replace(defToInline);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
parent.delete();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement checkRefsInAugmentedAssignmentOrUnaryModified(final PsiElement[] refsToInline, PsiElement defToInline) {
|
||||
for (PsiElement element : refsToInline) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Test {
|
||||
{
|
||||
int i, j;
|
||||
i = j = 0;
|
||||
System.out.println(<caret>j);
|
||||
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class Test {
|
||||
{
|
||||
int i;
|
||||
i = 0;
|
||||
System.out.println(0);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -301,9 +301,8 @@ public class InlineLocalTest extends LightCodeInsightTestCase {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testLocalInsideLambdaWithNestedLambda() {
|
||||
doTest(true);
|
||||
}
|
||||
public void testLocalInsideLambdaWithNestedLambda() { doTest(true); }
|
||||
public void testDefInMultiAssignmentStatement() { doTest(true); }
|
||||
|
||||
private void doTest(final boolean inlineDef, String conflictMessage) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user