mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
PY-12877 Fix complains found during review (IDEA-CR-397)
This commit is contained in:
@@ -18,6 +18,7 @@ package com.jetbrains.python.codeInsight.editorActions.smartEnter.fixers;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.codeInsight.editorActions.smartEnter.PySmartEnterProcessor;
|
||||
@@ -27,8 +28,6 @@ import com.jetbrains.python.psi.PyWithItem;
|
||||
import com.jetbrains.python.psi.PyWithStatement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.jetbrains.python.psi.PyUtil.sure;
|
||||
|
||||
/**
|
||||
* @author Mikhail Golubev
|
||||
*/
|
||||
@@ -42,11 +41,10 @@ public class PyWithFixer extends PyFixer<PyWithStatement> {
|
||||
final PsiElement colonToken = PyUtil.getFirstChildOfType(withStatement, PyTokenTypes.COLON);
|
||||
final PsiElement withToken = PyUtil.getFirstChildOfType(withStatement, PyTokenTypes.WITH_KEYWORD);
|
||||
final Document document = editor.getDocument();
|
||||
if (colonToken == null) {
|
||||
int insertAt = sure(withToken).getTextRange().getEndOffset();
|
||||
if (colonToken == null && withToken != null) {
|
||||
int insertAt = withToken.getTextRange().getEndOffset();
|
||||
String textToInsert = ":";
|
||||
final PyWithItem[] withItems = withStatement.getWithItems();
|
||||
final PyWithItem lastItem = withItems.length != 0 ? withItems[withItems.length - 1] : null;
|
||||
final PyWithItem lastItem = ArrayUtil.getLastElement(withStatement.getWithItems());
|
||||
if (lastItem == null || lastItem.getExpression() == null) {
|
||||
textToInsert = " :";
|
||||
processor.registerUnresolvedError(insertAt + 1);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
with open('file.txt') as f<caret>
|
||||
@@ -0,0 +1,2 @@
|
||||
with open('file.txt') as f:
|
||||
<caret>
|
||||
@@ -184,4 +184,9 @@ public class PySmartEnterTest extends PyTestCase {
|
||||
public void testWithExpressionMissing() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-12877
|
||||
public void testWithOnlyColonMissing() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user