From 4d1ca37c016787729849277d6801da09e16ce344 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 20 Jan 2014 17:26:17 +0100 Subject: [PATCH] Merge PyKeywords with PyNames --- .../src/com/jetbrains/python/PyNames.java | 153 +++++++++++------- .../python/codeInsight/PyKeywords.java | 64 -------- .../PyUnindentingInsertHandler.java | 15 +- .../PyKeywordCompletionContributor.java | 53 +++--- .../PyCallingNonCallableInspection.java | 7 +- .../PyMissingConstructorInspection.java | 2 +- .../src/com/jetbrains/python/psi/PyUtil.java | 4 +- .../psi/impl/PyCallExpressionHelper.java | 2 +- 8 files changed, 138 insertions(+), 162 deletions(-) delete mode 100644 python/src/com/jetbrains/python/codeInsight/PyKeywords.java diff --git a/python/psi-api/src/com/jetbrains/python/PyNames.java b/python/psi-api/src/com/jetbrains/python/PyNames.java index 81c05df64174..ba5c5b10b2c9 100644 --- a/python/psi-api/src/com/jetbrains/python/PyNames.java +++ b/python/psi-api/src/com/jetbrains/python/PyNames.java @@ -45,7 +45,7 @@ public class PyNames { public static final String NEW = "__new__"; public static final String GETATTR = "__getattr__"; public static final String GETATTRIBUTE = "__getattribute__"; - public static final String CLASS = "__class__"; + public static final String __CLASS__ = "__class__"; public static final String DUNDER_METACLASS = "__metaclass__"; public static final String METACLASS = "metaclass"; public static final String TYPE = "type"; @@ -136,7 +136,7 @@ public class PyNames { public static final String COLLECTIONS_NAMEDTUPLE = COLLECTIONS + "." + NAMEDTUPLE; public static final String FORMAT = "format"; - + public static final String ABSTRACTMETHOD = "abc.abstractmethod"; public static final String ABSTRACTPROPERTY = "abc.abstractproperty"; @@ -156,7 +156,7 @@ public class PyNames { public static final String TEST_CASE = "TestCase"; - public static final String PYCACHE = "__pycache__"; + public static final String PYCACHE = "__pycache__"; public static final String NOT_IMPLEMENTED_ERROR = "NotImplementedError"; @@ -166,7 +166,7 @@ public class PyNames { * Contains all known predefined names of "__foo__" form. */ public static ImmutableSet UnderscoredAttributes = ImmutableSet.of( - "__all__", + "__all__", "__author__", "__bases__", "__defaults__", @@ -227,38 +227,38 @@ public class PyNames { .put("__abs__", _only_self_descr) .put("__add__", _self_other_descr) .put("__and__", _self_other_descr) - //_BuiltinMethods.put("__all__", _only_self_descr); - //_BuiltinMethods.put("__author__", _only_self_descr); - //_BuiltinMethods.put("__bases__", _only_self_descr); + //_BuiltinMethods.put("__all__", _only_self_descr); + //_BuiltinMethods.put("__author__", _only_self_descr); + //_BuiltinMethods.put("__bases__", _only_self_descr); .put("__call__", new BuiltinDescription("(self, *args, **kwargs)")) - //_BuiltinMethods.put("__class__", _only_self_descr); + //_BuiltinMethods.put("__class__", _only_self_descr); .put("__cmp__", _self_other_descr) .put("__coerce__", _self_other_descr) .put("__complex__", _only_self_descr) .put("__contains__", _self_item_descr) - //_BuiltinMethods.put("__debug__", _only_self_descr); + //_BuiltinMethods.put("__debug__", _only_self_descr); .put("__del__", _only_self_descr) .put("__delete__", new BuiltinDescription("(self, instance)")) .put("__delattr__", _self_item_descr) .put("__delitem__", _self_key_descr) .put("__delslice__", new BuiltinDescription("(self, i, j)")) - //_BuiltinMethods.put("__dict__", _only_self_descr); + //_BuiltinMethods.put("__dict__", _only_self_descr); .put("__divmod__", _self_other_descr) - //_BuiltinMethods.put("__doc__", _only_self_descr); - //_BuiltinMethods.put("__docformat__", _only_self_descr); + //_BuiltinMethods.put("__doc__", _only_self_descr); + //_BuiltinMethods.put("__docformat__", _only_self_descr); .put("__enter__", _only_self_descr) .put("__exit__", new BuiltinDescription("(self, exc_type, exc_val, exc_tb)")) .put("__eq__", _self_other_descr) - //_BuiltinMethods.put("__file__", _only_self_descr); + //_BuiltinMethods.put("__file__", _only_self_descr); .put("__float__", _only_self_descr) .put("__floordiv__", _self_other_descr) - //_BuiltinMethods.put("__future__", _only_self_descr); + //_BuiltinMethods.put("__future__", _only_self_descr); .put("__ge__", _self_other_descr) .put("__get__", new BuiltinDescription("(self, instance, owner)")) .put("__getattr__", _self_item_descr) .put("__getattribute__", _self_item_descr) .put("__getitem__", _self_item_descr) - //_BuiltinMethods.put("__getslice__", new BuiltinDescription("(self, i, j)")); + //_BuiltinMethods.put("__getslice__", new BuiltinDescription("(self, i, j)")); .put("__gt__", _self_other_descr) .put("__hash__", _only_self_descr) .put("__hex__", _only_self_descr) @@ -266,7 +266,7 @@ public class PyNames { .put("__iand__", _self_other_descr) .put("__idiv__", _self_other_descr) .put("__ifloordiv__", _self_other_descr) - //_BuiltinMethods.put("__import__", _only_self_descr); + //_BuiltinMethods.put("__import__", _only_self_descr); .put("__ilshift__", _self_other_descr) .put("__imod__", _self_other_descr) .put("__imul__", _self_other_descr) @@ -286,18 +286,18 @@ public class PyNames { .put("__long__", _only_self_descr) .put("__lshift__", _self_other_descr) .put("__lt__", _self_other_descr) - //_BuiltinMethods.put("__members__", _only_self_descr); - //_BuiltinMethods.put("__metaclass__", _only_self_descr); + //_BuiltinMethods.put("__members__", _only_self_descr); + //_BuiltinMethods.put("__metaclass__", _only_self_descr); .put("__mod__", _self_other_descr) - //_BuiltinMethods.put("__mro__", _only_self_descr); + //_BuiltinMethods.put("__mro__", _only_self_descr); .put("__mul__", _self_other_descr) - //_BuiltinMethods.put("__name__", _only_self_descr); + //_BuiltinMethods.put("__name__", _only_self_descr); .put("__ne__", _self_other_descr) .put("__neg__", _only_self_descr) .put(NEW, new BuiltinDescription("(cls, *args, **kwargs)")) .put("__oct__", _only_self_descr) .put("__or__", _self_other_descr) - //_BuiltinMethods.put("__path__", _only_self_descr); + //_BuiltinMethods.put("__path__", _only_self_descr); .put("__pos__", _only_self_descr) .put("__pow__", new BuiltinDescription("(self, power, modulo=None)")) .put("__radd__", _self_other_descr) @@ -322,13 +322,13 @@ public class PyNames { .put("__setattr__", new BuiltinDescription("(self, key, value)")) .put("__setitem__", new BuiltinDescription("(self, key, value)")) .put("__setslice__", new BuiltinDescription("(self, i, j, sequence)")) - //_BuiltinMethods.put("__self__", _only_self_descr); - //_BuiltinMethods.put("__slots__", _only_self_descr); + //_BuiltinMethods.put("__self__", _only_self_descr); + //_BuiltinMethods.put("__slots__", _only_self_descr); .put("__str__", _only_self_descr) .put("__sub__", _self_other_descr) .put("__truediv__", _self_other_descr) .put("__unicode__", _only_self_descr) - //_BuiltinMethods.put("__version__", _only_self_descr); + //_BuiltinMethods.put("__version__", _only_self_descr); .put("__xor__", _self_other_descr) .build(); @@ -355,53 +355,89 @@ public class PyNames { public static final String CANONICAL_CLS = "cls"; public static final String BASESTRING = "basestring"; + /* + Python keywords + */ + + public static final String CLASS = "class"; + public static final String DEF = "def"; + public static final String IF = "if"; + public static final String ELSE = "else"; + public static final String ELIF = "elif"; + public static final String TRY = "try"; + public static final String EXCEPT = "except"; + public static final String FINALLY = "finally"; + public static final String WHILE = "while"; + public static final String FOR = "for"; + public static final String WITH = "with"; + public static final String AS = "as"; + public static final String ASSERT = "assert"; + public static final String DEL = "del"; + public static final String EXEC = "exec"; + public static final String FROM = "from"; + public static final String IMPORT = "import"; + public static final String RAISE = "raise"; + public static final String PRINT = "print"; + public static final String BREAK = "break"; + public static final String CONTINUE = "continue"; + public static final String GLOBAL = "global"; + public static final String RETURN = "return"; + public static final String YIELD = "yield"; + public static final String NONLOCAL = "nonlocal"; + public static final String AND = "and"; + public static final String OR = "or"; + public static final String IS = "is"; + public static final String IN = "in"; + public static final String NOT = "not"; + public static final String LAMBDA = "lambda"; + /** * Contains keywords as of CPython 2.5. */ public static ImmutableSet Keywords = ImmutableSet.of( - "and", - "del", - "from", - "not", - "while", - "as", - "elif", - "global", - "or", - "with", - "assert", - "else", - "if", - "pass", - "yield", - "break", - "except", - "import", - "print", - "class", - "exec", - "in", - "raise", - "continue", - "finally", - "is", - "return", - "def", - "for", - "lambda", - "try" + AND, + DEL, + FROM, + NOT, + WHILE, + AS, + ELIF, + GLOBAL, + OR, + WITH, + ASSERT, + ELSE, + IF, + PASS, + YIELD, + BREAK, + EXCEPT, + IMPORT, + PRINT, + __CLASS__, + EXEC, + IN, + RAISE, + CONTINUE, + FINALLY, + IS, + RETURN, + DEF, + FOR, + LAMBDA, + TRY ); public static Set BuiltinInterfaces = ImmutableSet.of( - CALLABLE, HASHABLE, ITERABLE, ITERATOR, SIZED, CONTAINER, SEQUENCE, MAPPING, ABC_COMPLEX, ABC_REAL, ABC_RATIONAL, ABC_INTEGRAL, - ABC_NUMBER + CALLABLE, HASHABLE, ITERABLE, ITERATOR, SIZED, CONTAINER, SEQUENCE, MAPPING, ABC_COMPLEX, ABC_REAL, ABC_RATIONAL, ABC_INTEGRAL, + ABC_NUMBER ); /** * TODO: dependency on language level. + * * @param name what to check * @return true iff the name is either a keyword or a reserved name, like None. - * */ public static boolean isReserved(@NonNls String name) { return Keywords.contains(name) || NONE.equals(name) || "as".equals(name) || "with".equals(name); @@ -412,6 +448,7 @@ public class PyNames { /** * TODO: dependency on language level. + * * @param name what to check * @return true iff name is not reserved and is a well-formed identifier. */ diff --git a/python/src/com/jetbrains/python/codeInsight/PyKeywords.java b/python/src/com/jetbrains/python/codeInsight/PyKeywords.java deleted file mode 100644 index 458715fbf6c4..000000000000 --- a/python/src/com/jetbrains/python/codeInsight/PyKeywords.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.jetbrains.python.codeInsight; - -/** - * @author traff - */ -public class PyKeywords { - public static final String DEF = "def"; - public static final String CLASS = "class"; - - public static final String IF = "if"; - public static final String ELSE = "else"; - public static final String ELIF = "elif"; - - public static final String TRY = "try"; - public static final String EXCEPT = "except"; - public static final String FINALLY = "finally"; - - public static final String WHILE = "while"; - - public static final String FOR = "for"; - public static final String WITH = "with"; - public static final String AS = "as"; - - public static final String ASSERT = "assert"; - public static final String DEL = "del"; - public static final String EXEC = "exec"; - public static final String FROM = "from"; - public static final String IMPORT = "import"; - public static final String RAISE = "raise"; - public static final String PRINT = "print"; - public static final String BREAK = "break"; - public static final String CONTINUE = "continue"; - public static final String GLOBAL = "global"; - public static final String RETURN = "return"; - public static final String YIELD = "yield"; - public static final String NONLOCAL = "nonlocal"; - - public static final String AND = "and"; - public static final String OR = "or"; - public static final String IS = "is"; - public static final String IN = "in"; - public static final String NOT = "not"; - - public static final String LAMBDA = "lambda"; - - public static final String TRUE = "True"; - public static final String FALSE = "False"; - public static final String NONE = "None"; -} diff --git a/python/src/com/jetbrains/python/codeInsight/PyUnindentingInsertHandler.java b/python/src/com/jetbrains/python/codeInsight/PyUnindentingInsertHandler.java index c6a69d72e275..d932d71f9629 100644 --- a/python/src/com/jetbrains/python/codeInsight/PyUnindentingInsertHandler.java +++ b/python/src/com/jetbrains/python/codeInsight/PyUnindentingInsertHandler.java @@ -25,6 +25,7 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; +import com.jetbrains.python.PyNames; import com.jetbrains.python.codeInsight.completion.PythonLookupElement; import com.jetbrains.python.psi.PyStatementWithElse; import com.jetbrains.python.psi.PyTryExceptStatement; @@ -67,28 +68,28 @@ public class PyUnindentingInsertHandler implements InsertHandler parentClass = null; - int last_offset = nonspace_offset + PyKeywords.FINALLY.length(); // the longest of all + int last_offset = nonspace_offset + PyNames.FINALLY.length(); // the longest of all if (last_offset > offset) last_offset = offset; int local_length = last_offset - nonspace_offset + 1; if (local_length > 0) { String piece = text.subSequence(nonspace_offset, last_offset + 1).toString(); - final int else_len = PyKeywords.ELSE.length(); + final int else_len = PyNames.ELSE.length(); if (local_length >= else_len) { - if ((piece.startsWith(PyKeywords.ELSE) || piece.startsWith(PyKeywords.ELIF)) && + if ((piece.startsWith(PyNames.ELSE) || piece.startsWith(PyNames.ELIF)) && (else_len == piece.length() || piece.charAt(else_len) < 'a' || piece.charAt(else_len) > 'z')) { parentClass = PyStatementWithElse.class; } } - final int except_len = PyKeywords.EXCEPT.length(); + final int except_len = PyNames.EXCEPT.length(); if (local_length >= except_len) { - if (piece.startsWith(PyKeywords.EXCEPT) && + if (piece.startsWith(PyNames.EXCEPT) && (except_len == piece.length() || piece.charAt(except_len) < 'a' || piece.charAt(except_len) > 'z')) { parentClass = PyTryExceptStatement.class; } } - final int finally_len = PyKeywords.FINALLY.length(); + final int finally_len = PyNames.FINALLY.length(); if (local_length >= finally_len) { - if (piece.startsWith(PyKeywords.FINALLY) && + if (piece.startsWith(PyNames.FINALLY) && (finally_len == piece.length() || piece.charAt(finally_len) < 'a' || piece.charAt(finally_len) > 'z')) { parentClass = PyTryExceptStatement.class; } diff --git a/python/src/com/jetbrains/python/codeInsight/completion/PyKeywordCompletionContributor.java b/python/src/com/jetbrains/python/codeInsight/completion/PyKeywordCompletionContributor.java index 6d7202457e83..f8698d06fbdb 100644 --- a/python/src/com/jetbrains/python/codeInsight/completion/PyKeywordCompletionContributor.java +++ b/python/src/com/jetbrains/python/codeInsight/completion/PyKeywordCompletionContributor.java @@ -33,7 +33,6 @@ import com.intellij.util.ProcessingContext; import com.jetbrains.python.PyNames; import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.PythonLanguage; -import com.jetbrains.python.codeInsight.PyKeywords; import com.jetbrains.python.codeInsight.PyUnindentingInsertHandler; import com.jetbrains.python.documentation.doctest.PyDocstringFile; import com.jetbrains.python.psi.*; @@ -287,9 +286,9 @@ public class PyKeywordCompletionContributor extends CompletionContributor { psiElement() .inside(PyConditionalStatementPart.class) .andOr( - psiElement().afterLeaf(psiElement().withText(PyKeywords.IF)), - psiElement().afterLeaf(psiElement().withText(PyKeywords.ELIF)), - psiElement().afterLeaf(psiElement().withText(PyKeywords.WHILE)) + psiElement().afterLeaf(psiElement().withText(PyNames.IF)), + psiElement().afterLeaf(psiElement().withText(PyNames.ELIF)), + psiElement().afterLeaf(psiElement().withText(PyNames.WHILE)) ); private static final PsiElementPattern.Capture IN_IMPORT_STMT = @@ -379,8 +378,8 @@ public class PyKeywordCompletionContributor extends CompletionContributor { protected void addCompletions( @NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result ) { - putKeywords(result, TailType.NONE, PyKeywords.DEF, PyKeywords.CLASS, PyKeywords.FOR, PyKeywords.IF, PyKeywords.WHILE, PyKeywords.WITH); - putKeywords(result, TailType.CASE_COLON, PyKeywords.TRY); + putKeywords(result, TailType.NONE, PyNames.DEF, PyNames.CLASS, PyNames.FOR, PyNames.IF, PyNames.WHILE, PyNames.WITH); + putKeywords(result, TailType.CASE_COLON, PyNames.TRY); } } ); @@ -403,13 +402,13 @@ public class PyKeywordCompletionContributor extends CompletionContributor { protected void addCompletions( @NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result ) { - putKeywords(result, TailType.SPACE, PyKeywords.ASSERT, PyKeywords.DEL, PyKeywords.EXEC, PyKeywords.FROM, PyKeywords.IMPORT, PyKeywords.RAISE); + putKeywords(result, TailType.SPACE, PyNames.ASSERT, PyNames.DEL, PyNames.EXEC, PyNames.FROM, PyNames.IMPORT, PyNames.RAISE); putKeywords(result, TailType.NONE, PyNames.PASS); } } ); - extend(CompletionType.BASIC, inStatement.andNot(PY3K), new PyKeywordCompletionProvider(TailType.SPACE, PyKeywords.PRINT)); + extend(CompletionType.BASIC, inStatement.andNot(PY3K), new PyKeywordCompletionProvider(TailType.SPACE, PyNames.PRINT)); } private void addBreak() { @@ -422,7 +421,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .andNot(IN_ARG_LIST) .and(IN_LOOP) , - new PyKeywordCompletionProvider(TailType.NONE, PyKeywords.BREAK) + new PyKeywordCompletionProvider(TailType.NONE, PyNames.BREAK) ); } @@ -437,7 +436,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .andNot(IN_FINALLY_NO_LOOP) .and(IN_LOOP) , - new PyKeywordCompletionProvider(TailType.NONE, PyKeywords.CONTINUE) + new PyKeywordCompletionProvider(TailType.NONE, PyNames.CONTINUE) ); } @@ -449,7 +448,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .and(IN_BEGIN_STMT) .andNot(AFTER_QUALIFIER) , - new PyKeywordCompletionProvider(PyKeywords.GLOBAL, PyKeywords.RETURN, PyKeywords.YIELD) + new PyKeywordCompletionProvider(PyNames.GLOBAL, PyNames.RETURN, PyNames.YIELD) ); extend( @@ -460,7 +459,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .and(PY3K) .andNot(AFTER_QUALIFIER) , - new PyKeywordCompletionProvider(PyKeywords.NONLOCAL) + new PyKeywordCompletionProvider(PyNames.NONLOCAL) ); } @@ -472,7 +471,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .andOr(IN_IF_BODY, AFTER_IF) .andNot(AFTER_QUALIFIER).andNot(IN_STRING_LITERAL) , - new PyKeywordCompletionProvider(TailType.NONE, PyUnindentingInsertHandler.INSTANCE, PyKeywords.ELIF)); + new PyKeywordCompletionProvider(TailType.NONE, PyUnindentingInsertHandler.INSTANCE, PyNames.ELIF)); } private void addWithinTry() { @@ -488,8 +487,8 @@ public class PyKeywordCompletionContributor extends CompletionContributor { protected void addCompletions( @NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result ) { - putKeyword(PyKeywords.EXCEPT, PyUnindentingInsertHandler.INSTANCE, TailType.NONE, result); - putKeyword(PyKeywords.FINALLY, PyUnindentingInsertHandler.INSTANCE, TailType.CASE_COLON, result); + putKeyword(PyNames.EXCEPT, PyUnindentingInsertHandler.INSTANCE, TailType.NONE, result); + putKeyword(PyNames.FINALLY, PyUnindentingInsertHandler.INSTANCE, TailType.CASE_COLON, result); } } ); @@ -503,7 +502,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .andOr(IN_COND_STMT, IN_EXCEPT_BODY, AFTER_COND_STMT_NO_ELSE, AFTER_LOOP_NO_ELSE, AFTER_EXCEPT) .andNot(AFTER_QUALIFIER).andNot(IN_STRING_LITERAL) , - new PyKeywordCompletionProvider(TailType.CASE_COLON, PyUnindentingInsertHandler.INSTANCE, PyKeywords.ELSE)); + new PyKeywordCompletionProvider(TailType.CASE_COLON, PyUnindentingInsertHandler.INSTANCE, PyNames.ELSE)); } private void addInfixOperators() { @@ -517,7 +516,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .andNot(AFTER_QUALIFIER). andNot(IN_STRING_LITERAL).and(IN_BEGIN_STMT) , - new PyKeywordCompletionProvider(PyKeywords.AND, PyKeywords.OR, PyKeywords.IS, PyKeywords.IN) + new PyKeywordCompletionProvider(PyNames.AND, PyNames.OR, PyNames.IS, PyNames.IN) ); } @@ -531,7 +530,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .andNot(IN_FUNCTION_HEADER) .andNot(AFTER_QUALIFIER).andNot(IN_STRING_LITERAL) , - new PyKeywordCompletionProvider(PyKeywords.NOT, PyKeywords.LAMBDA) + new PyKeywordCompletionProvider(PyNames.NOT, PyNames.LAMBDA) ); } @@ -546,7 +545,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .andNot(AFTER_QUALIFIER) .andNot(IN_FUNCTION_HEADER) , - new PyKeywordCompletionProvider(TailType.NONE, PyKeywords.TRUE, PyKeywords.FALSE, PyKeywords.NONE) + new PyKeywordCompletionProvider(TailType.NONE, PyNames.TRUE, PyNames.FALSE, PyNames.NONE) ); } @@ -557,7 +556,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .andOr(IN_IMPORT_AFTER_REF, IN_WITH_AFTER_REF, IN_EXCEPT_AFTER_REF) .andNot(AFTER_QUALIFIER) , - new PyKeywordCompletionProvider(PyKeywords.AS) + new PyKeywordCompletionProvider(PyNames.AS) ); } @@ -568,7 +567,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .and(IN_FROM_IMPORT_AFTER_REF) .andNot(AFTER_QUALIFIER) , - new PyKeywordCompletionProvider(PyKeywords.IMPORT) + new PyKeywordCompletionProvider(PyNames.IMPORT) ); } @@ -604,9 +603,9 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .withLanguage(PythonLanguage.getInstance()) .afterLeafSkipping(psiElement().whitespace(), psiElement().inside(psiElement(PyConditionalExpression.class)) - .and(psiElement().afterLeaf(PyKeywords.IF))) + .and(psiElement().afterLeaf(PyNames.IF))) , - new PyKeywordCompletionProvider(TailType.SPACE, PyKeywords.ELSE)); + new PyKeywordCompletionProvider(TailType.SPACE, PyNames.ELSE)); } private void addRaiseFrom() { @@ -615,7 +614,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .withLanguage(PythonLanguage.getInstance()) .and(PY3K) .afterLeaf(psiElement().inside(PyRaiseStatement.class)), - new PyKeywordCompletionProvider(PyKeywords.FROM)); + new PyKeywordCompletionProvider(PyNames.FROM)); } private void addYieldFrom() { @@ -624,7 +623,7 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .withLanguage(PythonLanguage.getInstance()) .and(PY3K) .afterLeaf(psiElement().withElementType(PyTokenTypes.YIELD_KEYWORD)), - new PyKeywordCompletionProvider(PyKeywords.FROM)); + new PyKeywordCompletionProvider(PyNames.FROM)); } public PyKeywordCompletionContributor() { @@ -655,14 +654,14 @@ public class PyKeywordCompletionContributor extends CompletionContributor { .withLanguage(PythonLanguage.getInstance()) .inside(psiElement(PySequenceExpression.class)) .andNot(psiElement().afterLeaf(or(psiElement(PyTokenTypes.LBRACE), psiElement(PyTokenTypes.LBRACKET), psiElement(PyTokenTypes.LPAR)))), - new PyKeywordCompletionProvider(PyKeywords.FOR)); + new PyKeywordCompletionProvider(PyNames.FOR)); } private void addInToFor() { extend(CompletionType.BASIC, psiElement() .withLanguage(PythonLanguage.getInstance()) - .and(psiElement()).afterLeaf(psiElement().afterLeaf(PyKeywords.FOR)), + .and(psiElement()).afterLeaf(psiElement().afterLeaf(PyNames.FOR)), new PyKeywordCompletionProvider("in")); } diff --git a/python/src/com/jetbrains/python/inspections/PyCallingNonCallableInspection.java b/python/src/com/jetbrains/python/inspections/PyCallingNonCallableInspection.java index 47f55a483292..4af6767fbcb2 100644 --- a/python/src/com/jetbrains/python/inspections/PyCallingNonCallableInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyCallingNonCallableInspection.java @@ -20,7 +20,10 @@ import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiElementVisitor; import com.jetbrains.python.PyNames; import com.jetbrains.python.psi.*; -import com.jetbrains.python.psi.types.*; +import com.jetbrains.python.psi.types.PyClassType; +import com.jetbrains.python.psi.types.PyType; +import com.jetbrains.python.psi.types.PyTypeChecker; +import com.jetbrains.python.psi.types.TypeEvalContext; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -89,7 +92,7 @@ public class PyCallingNonCallableInspection extends PyInspection { @Nullable private static Boolean isCallable(@NotNull PyExpression element, @NotNull TypeEvalContext context) { - if (element instanceof PyQualifiedExpression && PyNames.CLASS.equals(element.getName())) { + if (element instanceof PyQualifiedExpression && PyNames.__CLASS__.equals(element.getName())) { return true; } return PyTypeChecker.isCallable(context.getType(element)); diff --git a/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java b/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java index 0a4c3625ff57..90871800c2bc 100644 --- a/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyMissingConstructorInspection.java @@ -139,7 +139,7 @@ public class PyMissingConstructorInspection extends PyInspection { if (args.length > 0) { String firstArg = args[0].getText(); final String qualifiedName = cl.getQualifiedName(); - if (firstArg.equals(cl.getName()) || firstArg.equals(CANONICAL_SELF+"."+ CLASS) || + if (firstArg.equals(cl.getName()) || firstArg.equals(CANONICAL_SELF+"."+ __CLASS__) || (qualifiedName != null && qualifiedName.endsWith(firstArg))) return true; for (PyClass s : cl.getAncestorClasses(myTypeEvalContext)) { diff --git a/python/src/com/jetbrains/python/psi/PyUtil.java b/python/src/com/jetbrains/python/psi/PyUtil.java index 0cd299422694..2fce2d0d3110 100644 --- a/python/src/com/jetbrains/python/psi/PyUtil.java +++ b/python/src/com/jetbrains/python/psi/PyUtil.java @@ -415,7 +415,7 @@ public class PyUtil { PyExpression qualifier = ref.getQualifier(); if (qualifier != null) { String attr_name = ref.getReferencedName(); - if (PyNames.CLASS.equals(attr_name)) { + if (PyNames.__CLASS__.equals(attr_name)) { PyType qualifierType = context.getType(qualifier); if (qualifierType instanceof PyClassType) { return new PyClassTypeImpl(((PyClassType)qualifierType).getPyClass(), true); // always as class, never instance @@ -1114,7 +1114,7 @@ public class PyUtil { PyExpression[] args = node.getArguments(); if (args.length > 0) { String firstArg = args[0].getText(); - if (firstArg.equals(klass.getName()) || firstArg.equals(PyNames.CANONICAL_SELF + "." + PyNames.CLASS)) { + if (firstArg.equals(klass.getName()) || firstArg.equals(PyNames.CANONICAL_SELF + "." + PyNames.__CLASS__)) { return true; } for (PyClass s : klass.getAncestorClasses()) { diff --git a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java index 506fdb0071ce..bd33be42b4af 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java +++ b/python/src/com/jetbrains/python/psi/impl/PyCallExpressionHelper.java @@ -490,7 +490,7 @@ public class PyCallExpressionHelper { if (first_arg instanceof PyReferenceExpression) { final PyReferenceExpression firstArgRef = (PyReferenceExpression)first_arg; final PyExpression qualifier = firstArgRef.getQualifier(); - if (qualifier != null && PyNames.CLASS.equals(firstArgRef.getReferencedName())) { + if (qualifier != null && PyNames.__CLASS__.equals(firstArgRef.getReferencedName())) { final PsiReference qRef = qualifier.getReference(); final PsiElement element = qRef == null ? null : qRef.resolve(); if (element instanceof PyParameter) {