Java: Prevent extracting method from empty parentheses (IDEA-182482)

This commit is contained in:
Pavel Dolgov
2017-11-22 17:06:25 +03:00
parent c382ddb00b
commit 23fdeba082
3 changed files with 10 additions and 0 deletions

View File

@@ -200,6 +200,7 @@ public class ExtractMethodProcessor implements MatchProvider {
* Invoked in atomic action
*/
public boolean prepare(@Nullable Pass<ExtractMethodProcessor> pass) throws PrepareFailedException {
if (myElements.length == 0) return false;
myExpression = null;
if (myElements.length == 1 && myElements[0] instanceof PsiExpression) {
final PsiExpression expression = (PsiExpression)myElements[0];

View File

@@ -0,0 +1,5 @@
class ExtractEmptyBlock {
void foo() {
<selection>{}</selection>
}
}

View File

@@ -1217,6 +1217,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doDuplicatesTest();
}
public void testEmptyBlockStatement() throws Exception {
doExitPointsTest(false);
}
private void doTestDisabledParam() throws PrepareFailedException {
final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
settings.ELSE_ON_NEW_LINE = true;