PY-12877 Fix complains found during review (IDEA-CR-397)

This commit is contained in:
Mikhail Golubev
2014-09-08 12:43:44 +04:00
parent f7ae89dc34
commit 5de0b14903
4 changed files with 12 additions and 6 deletions

View File

@@ -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);

View File

@@ -0,0 +1 @@
with open('file.txt') as f<caret>

View File

@@ -0,0 +1,2 @@
with open('file.txt') as f:
<caret>

View File

@@ -184,4 +184,9 @@ public class PySmartEnterTest extends PyTestCase {
public void testWithExpressionMissing() {
doTest();
}
// PY-12877
public void testWithOnlyColonMissing() {
doTest();
}
}