mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-242445 Inline variable refacting remove comment
GitOrigin-RevId: 2f95f3fd529acb19d13dfdfa35143d03502c7747
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b3e08a9279
commit
96c423456a
+9
-2
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.SideEffectChecker;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@@ -211,7 +212,7 @@ public class RemoveUnusedVariableUtil {
|
||||
deleteReferences(variable, references, deleteMode);
|
||||
}
|
||||
else if (deleteMode == RemoveMode.DELETE_ALL) {
|
||||
element.delete();
|
||||
deleteVariable(variable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -220,7 +221,7 @@ public class RemoveUnusedVariableUtil {
|
||||
if (element instanceof PsiField) {
|
||||
((PsiField)element).normalizeDeclaration();
|
||||
}
|
||||
element.delete();
|
||||
deleteVariable(variable);
|
||||
}
|
||||
return !sideEffectsFound;
|
||||
}
|
||||
@@ -230,6 +231,12 @@ public class RemoveUnusedVariableUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void deleteVariable(PsiVariable variable) {
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
tracker.markUnchanged(variable.getInitializer()); // assume that initializer is used (e.g. inlined)
|
||||
tracker.deleteAndRestoreComments(variable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static PsiElement eraseUnnecessaryOuterParentheses(@NotNull PsiElement element) {
|
||||
PsiElement parenthesizedParent = element;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.*;
|
||||
|
||||
public class UnusedReassignmentInLoop {
|
||||
|
||||
static String test(Deque<String> deque) {
|
||||
String <caret>value = deque.isEmpty() ? null : deque.peek(); // comment
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.*;
|
||||
|
||||
public class UnusedReassignmentInLoop {
|
||||
|
||||
static String test(Deque<String> deque) {
|
||||
// comment
|
||||
return deque.isEmpty() ? null : deque.peek();
|
||||
}
|
||||
}
|
||||
@@ -333,6 +333,10 @@ public class InlineLocalTest extends LightJavaCodeInsightTestCase {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testEolComment() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
private void doTest(final boolean inlineDef, String conflictMessage) {
|
||||
try {
|
||||
doTest(inlineDef);
|
||||
|
||||
Reference in New Issue
Block a user