Java: Preserve comments when extracting method with duplicates (IDEA-194463)

This commit is contained in:
Pavel Dolgov
2018-07-09 13:13:03 +03:00
parent c52ec5d8d6
commit ff958e1fdd
4 changed files with 36 additions and 2 deletions
@@ -57,8 +57,8 @@ public class ParametrizedDuplicates {
private ParametrizedDuplicates(@NotNull PsiElement[] pattern,
@NotNull ExtractMethodProcessor originalProcessor) {
pattern = getFilteredElements(pattern);
PsiElement firstElement = pattern.length != 0 ? pattern[0] : null;
PsiElement[] filteredPattern = getFilteredElements(pattern);
PsiElement firstElement = filteredPattern.length != 0 ? filteredPattern[0] : null;
if (firstElement instanceof PsiStatement) {
PsiElement[] copy = copyElements(pattern);
myElements = wrapWithCodeBlock(copy, originalProcessor.getInputVariables());
@@ -0,0 +1,13 @@
class C {
void foo() {
<selection>/*a*/ // b
System.out.println(1);
/*c*/ // d</selection>
}
void bar() {
/*x*/
System.out.println(1);
/*z*/
}
}
@@ -0,0 +1,17 @@
class C {
void foo() {
newMethod();
}
private void newMethod() {
/*a*/ // b
System.out.println(1);
/*c*/ // d
}
void bar() {
/*x*/
newMethod();
/*z*/
}
}
@@ -1287,6 +1287,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doDuplicatesTest();
}
public void testDuplicatePreserveComments() throws Exception {
doDuplicatesTest();
}
public void testBeforeCommentAfterSelectedFragment() throws Exception {
doTest();
}