smart enter shouldn't insert parentheses into decorator calls (PY-3209)

This commit is contained in:
Dmitry Jemerov
2011-03-31 21:49:54 +02:00
parent c4a7bdb115
commit 384a20364b
4 changed files with 30 additions and 26 deletions
@@ -8,19 +8,17 @@ import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.codeInsight.editorActions.smartEnter.PySmartEnterProcessor;
import com.jetbrains.python.psi.PyArgumentList;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyDecorator;
import com.jetbrains.python.psi.PyUtil;
/**
* Created by IntelliJ IDEA.
* Author: Alexey.Ivanov
* Date: 16.04.2010
* Time: 19:15:36
* @author Alexey.Ivanov
*/
public class PyArgumentListFixer implements PyFixer {
public void apply(Editor editor, PySmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
if (psiElement instanceof PyArgumentList) {
final PsiElement rBrace = PyUtil.getChildByFilter(psiElement, PyTokenTypes.CLOSE_BRACES, 0);
if (psiElement.getContext() instanceof PyClass) {
if (psiElement.getParent() instanceof PyClass || psiElement.getParent() instanceof PyDecorator) {
final PsiElement lBrace = PyUtil.getChildByFilter(psiElement, PyTokenTypes.OPEN_BRACES, 0);
if (lBrace != null && rBrace == null) {
final Document document = editor.getDocument();
@@ -0,0 +1,2 @@
@classmethod
def func(arg<caret>
@@ -0,0 +1,3 @@
@classmethod
def func(arg):
<caret>
@@ -11,17 +11,14 @@ import com.jetbrains.python.fixtures.PyLightFixtureTestCase;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* Author: Alexey.Ivanov
* Date: 22.04.2010
* Time: 17:00:16
* @author Alexey.Ivanov
*/
public class PySmartEnterTest extends PyLightFixtureTestCase {
protected static List<SmartEnterProcessor> getSmartProcessors(Language language) {
return SmartEnterProcessors.INSTANCE.forKey(language);
}
public void doTest() throws Exception {
public void doTest() {
myFixture.configureByFile("codeInsight/smartEnter/" + getTestName(true) + ".py");
final List<SmartEnterProcessor> processors = getSmartProcessors(PythonLanguage.getInstance());
new WriteCommandAction(myFixture.getProject()) {
@@ -36,67 +33,71 @@ public class PySmartEnterTest extends PyLightFixtureTestCase {
myFixture.checkResultByFile("codeInsight/smartEnter/" + getTestName(true) + "_after.py", true);
}
public void testIf() throws Exception {
public void testIf() {
doTest();
}
public void testWhile() throws Exception {
public void testWhile() {
doTest();
}
public void testElif() throws Exception {
public void testElif() {
doTest();
}
public void testForFirst() throws Exception {
public void testForFirst() {
doTest();
}
public void testForSecond() throws Exception {
public void testForSecond() {
doTest();
}
public void testTry() throws Exception {
public void testTry() {
doTest();
}
public void testString() throws Exception {
public void testString() {
doTest();
}
public void testDocstring() throws Exception {
public void testDocstring() {
doTest();
}
public void testDict() throws Exception {
public void testDict() {
doTest();
}
public void testParenthesized() throws Exception {
public void testParenthesized() {
doTest();
}
public void testArgumentsFirst() throws Exception {
public void testArgumentsFirst() {
doTest();
}
public void testArgumentsSecond() throws Exception {
public void testArgumentsSecond() {
doTest();
}
public void testFunc() throws Exception {
public void testFunc() {
doTest();
}
public void testClass() throws Exception {
public void testClass() {
doTest();
}
public void testComment() throws Exception {
public void testComment() {
doTest();
}
public void testPy891() throws Exception {
public void testPy891() {
doTest();
}
public void testPy3209() {
doTest();
}
}