mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: correct extraction with leading comment
This commit is contained in:
+1
-1
@@ -895,7 +895,7 @@ public class ExtractMethodProcessor implements MatchProvider {
|
||||
|
||||
protected PsiElement addToMethodCallLocation(PsiStatement statement) throws IncorrectOperationException {
|
||||
if (myEnclosingBlockStatement == null) {
|
||||
PsiElement containingStatement = PsiTreeUtil.getParentOfType(myExpression != null ? myExpression : myElements[0], PsiStatement.class, false);
|
||||
PsiElement containingStatement = myElements[0] instanceof PsiComment ? myElements[0] : PsiTreeUtil.getParentOfType(myExpression != null ? myExpression : myElements[0], PsiStatement.class, false);
|
||||
if (containingStatement == null) {
|
||||
containingStatement = PsiTreeUtil.getParentOfType(myExpression != null ? myExpression : myElements[0], PsiComment.class, false);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class Test {
|
||||
public void method2() {
|
||||
if (true) {
|
||||
<selection>
|
||||
// add to list2
|
||||
list2.add(true);</selection>
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
class Test {
|
||||
public void method2() {
|
||||
if (true) {
|
||||
newMethod();
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void newMethod() {
|
||||
// add to list2
|
||||
list2.add(true);
|
||||
}
|
||||
}
|
||||
@@ -482,6 +482,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExtractWithLeadingComment() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doPrepareErrorTest(final String expectedMessage) throws Exception {
|
||||
String expectedError = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user