From 116a4e2ff51dd044c1fa5ea8fd67fa356672ddbd Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 15 Aug 2012 12:58:21 +0200 Subject: [PATCH] don't insert parentheses when completing a function call if the function has any custom decorators (PY-4859) --- .../psi/resolve/CompletionVariantsProcessor.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/python/src/com/jetbrains/python/psi/resolve/CompletionVariantsProcessor.java b/python/src/com/jetbrains/python/psi/resolve/CompletionVariantsProcessor.java index 3e86952c9989..894fe51f622e 100644 --- a/python/src/com/jetbrains/python/psi/resolve/CompletionVariantsProcessor.java +++ b/python/src/com/jetbrains/python/psi/resolve/CompletionVariantsProcessor.java @@ -47,6 +47,7 @@ public class CompletionVariantsProcessor extends VariantsProcessor { if (!myPlainNamesOnly) { if (!mySuppressParentheses && object instanceof PyFunction && ((PyFunction)object).getProperty() == null && + hasNoCustomDecorators((PyFunction)object) && !isSingleArgDecoratorCall(myContext, (PyFunction)object)) { item = item.withInsertHandler(PyFunctionInsertHandler.INSTANCE); final PyParameterList parameterList = ((PyFunction)object).getParameterList(); @@ -102,6 +103,21 @@ public class CompletionVariantsProcessor extends VariantsProcessor { return item; } + private static boolean hasNoCustomDecorators(PyFunction function) { + PyDecoratorList decoratorList = function.getDecoratorList(); + if (decoratorList == null) { + return true; + } + for (PyDecorator decorator : decoratorList.getDecorators()) { + PyQualifiedName name = decorator.getQualifiedName(); + if (name == null || (!PyNames.CLASSMETHOD.equals(name.toString()) && !PyNames.STATICMETHOD.equals(name.toString()))) { + return false; + } + } + + return true; + } + private static boolean isSingleArgDecoratorCall(PsiElement elementInCall, PyFunction callee) { // special case hack to avoid the need of patching generator3.py PyClass containingClass = callee.getContainingClass();