Moved and inverted hasCustomDecorators() to PyUtil

This commit is contained in:
Andrey Vlasovskikh
2013-09-19 20:53:16 +04:00
parent f5b6204149
commit a56383ff3b
2 changed files with 16 additions and 16 deletions
@@ -44,6 +44,7 @@ import com.jetbrains.python.codeInsight.dataflow.scope.ScopeUtil;
import com.jetbrains.python.codeInsight.stdlib.PyNamedTupleType;
import com.jetbrains.python.psi.impl.PyBuiltinCache;
import com.jetbrains.python.psi.impl.PyPsiUtils;
import com.jetbrains.python.psi.impl.PyQualifiedName;
import com.jetbrains.python.psi.resolve.PyResolveContext;
import com.jetbrains.python.psi.resolve.QualifiedResolveResult;
import com.jetbrains.python.psi.types.*;
@@ -663,6 +664,20 @@ public class PyUtil {
return !isListComprehension || isAtLeast30;
}
public static boolean hasCustomDecorators(@NotNull PyDecoratable decoratable) {
PyDecoratorList decoratorList = decoratable.getDecoratorList();
if (decoratorList == null) {
return false;
}
for (PyDecorator decorator : decoratorList.getDecorators()) {
PyQualifiedName name = decorator.getQualifiedName();
if (name == null || (!PyNames.CLASSMETHOD.equals(name.toString()) && !PyNames.STATICMETHOD.equals(name.toString()))) {
return true;
}
}
return false;
}
public static class KnownDecoratorProviderHolder {
public static PyKnownDecoratorProvider[] KNOWN_DECORATOR_PROVIDERS = Extensions.getExtensions(PyKnownDecoratorProvider.EP_NAME);
@@ -48,7 +48,7 @@ public class CompletionVariantsProcessor extends VariantsProcessor {
if (!myPlainNamesOnly) {
if (!mySuppressParentheses &&
object instanceof PyFunction && ((PyFunction)object).getProperty() == null &&
hasNoCustomDecorators((PyFunction)object) &&
!PyUtil.hasCustomDecorators((PyFunction)object) &&
!isSingleArgDecoratorCall(myContext, (PyFunction)object)) {
item = item.withInsertHandler(PyFunctionInsertHandler.INSTANCE);
final TypeEvalContext context = TypeEvalContext.userInitiated(myContext != null ? myContext.getContainingFile() : null);
@@ -105,21 +105,6 @@ 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();