Commit 498e5b72 authored by Anna Kozlova's avatar Anna Kozlova
Browse files

keep comments on introduce variable (IDEA-136027)

parent 8c43bb8b
Branches unavailable Tags unavailable
No related merge requests found
Showing with 38 additions and 1 deletion
+38 -1
......@@ -58,6 +58,7 @@ import com.intellij.util.IncorrectOperationException;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.MultiMap;
import com.siyeh.ig.psiutils.CommentTracker;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
......@@ -924,7 +925,9 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
if (lastChild instanceof PsiComment) { // keep trailing comment
declaration.addBefore(lastChild, null);
}
statement.delete();
CommentTracker commentTracker = new CommentTracker();
commentTracker.markUnchanged(initializer);
commentTracker.deleteAndRestoreComments(statement);
if (editor != null) {
LogicalPosition pos = new LogicalPosition(line, col);
editor.getCaretModel().moveToLogicalPosition(pos);
......
import java.util.Arrays;
import java.util.List;
class Main {
private static void foo(String... src){
String m = Arrays.asList(src)
//c-2
.toArray()//c-1
.toString();//c1
//c2
}
}
\ No newline at end of file
import java.util.Arrays;
import java.util.List;
class Main {
private static void foo(String... src){
<selection>Arrays.asList(src)
//c-2
.toArray()//c-1
.toString()</selection>
//c1
//c2
;
}
}
\ No newline at end of file
......@@ -539,6 +539,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
doTest(new MockIntroduceVariableHandler("m", false, false, false, "A<? extends A<? extends java.lang.Object>>"));
}
public void testKeepComments() {
doTest(new MockIntroduceVariableHandler("m", false, false, false, CommonClassNames.JAVA_LANG_STRING));
}
public void testDenotableType2() {
doTest(new MockIntroduceVariableHandler("m", false, false, false, "I<? extends I<?>>"));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment