don't insert parentheses when completing a function call if the function has any custom decorators (PY-4859)

This commit is contained in:
Dmitry Jemerov
2012-08-15 12:58:21 +02:00
parent d2bd505e37
commit 116a4e2ff5
@@ -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();