From c1ed100ca8f83c48c7d84c16744a65ab07c8bf50 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Mon, 20 Apr 2015 21:58:48 +0300 Subject: [PATCH] PY-15640 Ignore smart enter fixers in case of empty PyFunction created only to wrap list of decorators --- .../smartEnter/fixers/PyFunctionFixer.java | 6 +++++- .../smartEnter/fixers/PyParameterListFixer.java | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyFunctionFixer.java b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyFunctionFixer.java index b55f668d30e6..e5ef3a5083b2 100644 --- a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyFunctionFixer.java +++ b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyFunctionFixer.java @@ -41,10 +41,14 @@ public class PyFunctionFixer extends PyFixer { public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyFunction function) throws IncorrectOperationException { final PsiElement colon = PyUtil.getFirstChildOfType(function, PyTokenTypes.COLON); - if (colon == null) { + if (!isFakeFunction(function) && colon == null) { final PyParameterList parameterList = function.getParameterList(); final Document document = editor.getDocument(); document.insertString(parameterList.getTextRange().getEndOffset(), ":"); } } + + private static boolean isFakeFunction(PyFunction function) { + return function.getNode().findChildByType(PyTokenTypes.DEF_KEYWORD) == null; + } } diff --git a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyParameterListFixer.java b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyParameterListFixer.java index 481e19b05e3e..ceaab100c59a 100644 --- a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyParameterListFixer.java +++ b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyParameterListFixer.java @@ -21,10 +21,13 @@ import com.intellij.psi.PsiElement; import com.intellij.util.IncorrectOperationException; import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.codeInsight.editorActions.smartEnter.PySmartEnterProcessor; +import com.jetbrains.python.psi.PyFunction; import com.jetbrains.python.psi.PyParameterList; import com.jetbrains.python.psi.PyUtil; import org.jetbrains.annotations.NotNull; +import static com.jetbrains.python.psi.PyUtil.as; + /** * Created by IntelliJ IDEA. * Author: Alexey.Ivanov @@ -40,7 +43,7 @@ public class PyParameterListFixer extends PyFixer { public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyParameterList psiElement) throws IncorrectOperationException { final PsiElement lBrace = PyUtil.getChildByFilter(psiElement, PyTokenTypes.OPEN_BRACES, 0); final PsiElement rBrace = PyUtil.getChildByFilter(psiElement, PyTokenTypes.CLOSE_BRACES, 0); - if (lBrace == null || rBrace == null) { + if (!isFakeParameterList(psiElement) && (lBrace == null || rBrace == null)) { final Document document = editor.getDocument(); if (lBrace == null) { document.insertString(psiElement.getTextRange().getStartOffset(), "("); @@ -50,4 +53,9 @@ public class PyParameterListFixer extends PyFixer { } } } + + private static boolean isFakeParameterList(@NotNull PyParameterList parameterList) { + final PyFunction pyFunction = as(parameterList.getParent(), PyFunction.class); + return pyFunction != null && pyFunction.getNode().findChildByType(PyTokenTypes.DEF_KEYWORD) == null; + } }