extract method: correct extraction with leading comment

This commit is contained in:
anna
2011-03-11 16:53:04 +01:00
parent bacfc555ec
commit 409d5b026b
4 changed files with 33 additions and 1 deletions
@@ -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 {
}
}
}
@@ -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 {