mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
disable surround with () for void expressions (IDEA-175462)
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ public class JavaWithCastSurrounder extends JavaExpressionSurrounder {
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(PsiExpression expr) {
|
||||
return true;
|
||||
return !PsiType.VOID.equals(expr.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
public class JavaWithParenthesesSurrounder extends JavaExpressionSurrounder{
|
||||
@Override
|
||||
public boolean isApplicable(PsiExpression expr) {
|
||||
return true;
|
||||
return !PsiType.VOID.equals(expr.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+17
@@ -31,7 +31,9 @@ import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.refactoring.introduceVariable.IntroduceVariableBase;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -258,4 +260,19 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase {
|
||||
return text != null && text.contains("while");
|
||||
}));
|
||||
}
|
||||
|
||||
public void testExcludeVoidExpressions() {
|
||||
configureFromFileText("a.java",
|
||||
"class Foo {\n" +
|
||||
" void bar() {\n" +
|
||||
" <selection>System.out.println();</selection>\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
SelectionModel model = myEditor.getSelectionModel();
|
||||
PsiExpression expr =
|
||||
IntroduceVariableBase.getSelectedExpression(myFile.getProject(), myFile, model.getSelectionStart(), model.getSelectionEnd());
|
||||
assertNotNull(expr);
|
||||
assertFalse(new JavaWithParenthesesSurrounder().isApplicable(expr));
|
||||
assertFalse(new JavaWithCastSurrounder().isApplicable(expr));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user