From 384a20364b67d209c61bc71e651994cadfd93e0b Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 31 Mar 2011 21:49:54 +0200 Subject: [PATCH] smart enter shouldn't insert parentheses into decorator calls (PY-3209) --- .../fixers/PyArgumentListFixer.java | 8 ++-- .../testData/codeInsight/smartEnter/py3209.py | 2 + .../codeInsight/smartEnter/py3209_after.py | 3 ++ .../jetbrains/python/PySmartEnterTest.java | 43 ++++++++++--------- 4 files changed, 30 insertions(+), 26 deletions(-) create mode 100644 python/testData/codeInsight/smartEnter/py3209.py create mode 100644 python/testData/codeInsight/smartEnter/py3209_after.py diff --git a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyArgumentListFixer.java b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyArgumentListFixer.java index 0d64f7154ea3..74c8e649b6a3 100644 --- a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyArgumentListFixer.java +++ b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyArgumentListFixer.java @@ -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(); diff --git a/python/testData/codeInsight/smartEnter/py3209.py b/python/testData/codeInsight/smartEnter/py3209.py new file mode 100644 index 000000000000..2b98fe47375d --- /dev/null +++ b/python/testData/codeInsight/smartEnter/py3209.py @@ -0,0 +1,2 @@ +@classmethod +def func(arg \ No newline at end of file diff --git a/python/testData/codeInsight/smartEnter/py3209_after.py b/python/testData/codeInsight/smartEnter/py3209_after.py new file mode 100644 index 000000000000..57ebe4ffce7f --- /dev/null +++ b/python/testData/codeInsight/smartEnter/py3209_after.py @@ -0,0 +1,3 @@ +@classmethod +def func(arg): + \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PySmartEnterTest.java b/python/testSrc/com/jetbrains/python/PySmartEnterTest.java index 0ce6a87605c7..7b534612dd8f 100644 --- a/python/testSrc/com/jetbrains/python/PySmartEnterTest.java +++ b/python/testSrc/com/jetbrains/python/PySmartEnterTest.java @@ -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 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 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(); } }