summaryrefslogtreecommitdiff
path: root/python/src/com/jetbrains/python/codeInsight
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/com/jetbrains/python/codeInsight')
-rw-r--r--python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java2
-rw-r--r--python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java4
-rw-r--r--python/src/com/jetbrains/python/codeInsight/completion/PyClassNameCompletionContributor.java3
-rw-r--r--python/src/com/jetbrains/python/codeInsight/completion/PyMetaClassCompletionContributor.java92
-rw-r--r--python/src/com/jetbrains/python/codeInsight/completion/PySpecialMethodNamesCompletionContributor.java2
-rw-r--r--python/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java2
-rw-r--r--python/src/com/jetbrains/python/codeInsight/stdlib/PyNamedTupleType.java2
-rw-r--r--python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibCanonicalPathProvider.java4
-rw-r--r--python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibTypeProvider.java2
9 files changed, 105 insertions, 8 deletions
diff --git a/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java b/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java
index 15b29c1c584a..dd9d3ef9dc00 100644
--- a/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java
+++ b/python/src/com/jetbrains/python/codeInsight/PyMethodNameTypedHandler.java
@@ -82,7 +82,7 @@ public class PyMethodNameTypedHandler extends TypedHandlerDelegate {
if (caretOffset == chars.length() || chars.charAt(caretOffset) != ':') {
textToType += ':';
}
- EditorModificationUtil.typeInStringAtCaretHonorMultipleCarets(editor, textToType, true, 1 + pname.length()); // right after param name
+ EditorModificationUtil.insertStringAtCaret(editor, textToType, true, 1 + pname.length()); // right after param name
return Result.STOP;
}
}
diff --git a/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java b/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java
index 3be84bfdc170..5b0221d0c6ff 100644
--- a/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java
+++ b/python/src/com/jetbrains/python/codeInsight/PyStdReferenceContributor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -31,7 +31,7 @@ import static com.intellij.patterns.PlatformPatterns.psiElement;
*/
public class PyStdReferenceContributor extends PsiReferenceContributor {
@Override
- public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
+ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registerClassAttributeReference(registrar, PyNames.ALL, new PsiReferenceProvider() {
@NotNull
@Override
diff --git a/python/src/com/jetbrains/python/codeInsight/completion/PyClassNameCompletionContributor.java b/python/src/com/jetbrains/python/codeInsight/completion/PyClassNameCompletionContributor.java
index 24318f85ad04..3b2e8283cee5 100644
--- a/python/src/com/jetbrains/python/codeInsight/completion/PyClassNameCompletionContributor.java
+++ b/python/src/com/jetbrains/python/codeInsight/completion/PyClassNameCompletionContributor.java
@@ -41,6 +41,7 @@ import com.jetbrains.python.psi.stubs.PyClassNameIndex;
import com.jetbrains.python.psi.stubs.PyFunctionNameIndex;
import com.jetbrains.python.psi.stubs.PyVariableNameIndex;
import com.jetbrains.python.psi.types.PyModuleType;
+import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@@ -50,7 +51,7 @@ import java.util.Collection;
public class PyClassNameCompletionContributor extends CompletionContributor {
@Override
- public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
+ public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
if (parameters.isExtendedCompletion()) {
final PsiElement element = parameters.getPosition();
final PsiElement parent = element.getParent();
diff --git a/python/src/com/jetbrains/python/codeInsight/completion/PyMetaClassCompletionContributor.java b/python/src/com/jetbrains/python/codeInsight/completion/PyMetaClassCompletionContributor.java
new file mode 100644
index 000000000000..bac27082b23f
--- /dev/null
+++ b/python/src/com/jetbrains/python/codeInsight/completion/PyMetaClassCompletionContributor.java
@@ -0,0 +1,92 @@
+/*
+ * 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.completion;
+
+import com.intellij.codeInsight.completion.*;
+import com.intellij.codeInsight.lookup.LookupElementBuilder;
+import com.intellij.patterns.PlatformPatterns;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.filters.ElementFilter;
+import com.intellij.psi.filters.position.FilterPattern;
+import com.intellij.util.ProcessingContext;
+import com.intellij.util.Processor;
+import com.jetbrains.python.PythonLanguage;
+import com.jetbrains.python.psi.*;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author vlan
+ */
+public class PyMetaClassCompletionContributor extends CompletionContributor {
+ public PyMetaClassCompletionContributor() {
+ extend(CompletionType.BASIC,
+ PlatformPatterns
+ .psiElement()
+ .withLanguage(PythonLanguage.getInstance())
+ .withParents(PyReferenceExpression.class, PyExpressionStatement.class, PyStatementList.class, PyClass.class)
+ .and(hasLanguageLevel(new Processor<LanguageLevel>() {
+ @Override
+ public boolean process(LanguageLevel level) {
+ return level.isOlderThan(LanguageLevel.PYTHON30);
+ }
+ })),
+ new CompletionProvider<CompletionParameters>() {
+ @Override
+ protected void addCompletions(@NotNull CompletionParameters parameters,
+ ProcessingContext context,
+ @NotNull CompletionResultSet result) {
+ result.addElement(LookupElementBuilder.create("__metaclass__ = "));
+ }
+ });
+ extend(CompletionType.BASIC,
+ PlatformPatterns
+ .psiElement()
+ .withLanguage(PythonLanguage.getInstance())
+ .withParents(PyReferenceExpression.class, PyArgumentList.class, PyClass.class)
+ .and(hasLanguageLevel(new Processor<LanguageLevel>() {
+ @Override
+ public boolean process(LanguageLevel level) {
+ return level.isAtLeast(LanguageLevel.PYTHON30);
+ }
+ })),
+ new CompletionProvider<CompletionParameters>() {
+ @Override
+ protected void addCompletions(@NotNull CompletionParameters parameters,
+ ProcessingContext context,
+ @NotNull CompletionResultSet result) {
+ result.addElement(LookupElementBuilder.create("metaclass="));
+ }
+ });
+ }
+
+ public static FilterPattern hasLanguageLevel(@NotNull final Processor<LanguageLevel> processor) {
+ return new FilterPattern(new ElementFilter() {
+ @Override
+ public boolean isAcceptable(Object element, @Nullable PsiElement context) {
+ if (element instanceof PsiElement) {
+ return processor.process(LanguageLevel.forElement((PsiElement)element));
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isClassAcceptable(Class hintClass) {
+ return true;
+ }
+ });
+ }
+}
diff --git a/python/src/com/jetbrains/python/codeInsight/completion/PySpecialMethodNamesCompletionContributor.java b/python/src/com/jetbrains/python/codeInsight/completion/PySpecialMethodNamesCompletionContributor.java
index db0e4537db38..bc3de2d28cfe 100644
--- a/python/src/com/jetbrains/python/codeInsight/completion/PySpecialMethodNamesCompletionContributor.java
+++ b/python/src/com/jetbrains/python/codeInsight/completion/PySpecialMethodNamesCompletionContributor.java
@@ -40,7 +40,7 @@ import static com.intellij.patterns.PlatformPatterns.psiElement;
*/
public class PySpecialMethodNamesCompletionContributor extends CompletionContributor {
@Override
- public AutoCompletionDecision handleAutoCompletionPossibility(AutoCompletionContext context) {
+ public AutoCompletionDecision handleAutoCompletionPossibility(@NotNull AutoCompletionContext context) {
// auto-insert the obvious only case; else show other cases.
final LookupElement[] items = context.getItems();
if (items.length == 1) {
diff --git a/python/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java b/python/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java
index 168a3fe8121f..1cdba261017f 100644
--- a/python/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java
+++ b/python/src/com/jetbrains/python/codeInsight/controlflow/PyTypeAssertionEvaluator.java
@@ -84,7 +84,7 @@ public class PyTypeAssertionEvaluator extends PyRecursiveElementVisitor {
@Override
public PyType getType(TypeEvalContext context, PsiElement anchor) {
final List<PyType> types = new ArrayList<PyType>();
- types.add(PyTypeParser.getTypeByName(target, PyNames.CALLABLE));
+ types.add(PyTypeParser.getTypeByName(target, "collections." + PyNames.CALLABLE));
return createAssertionType(context.getType(target), types, positive, context);
}
});
diff --git a/python/src/com/jetbrains/python/codeInsight/stdlib/PyNamedTupleType.java b/python/src/com/jetbrains/python/codeInsight/stdlib/PyNamedTupleType.java
index ad1d6a24bdc1..bcad2c1a105c 100644
--- a/python/src/com/jetbrains/python/codeInsight/stdlib/PyNamedTupleType.java
+++ b/python/src/com/jetbrains/python/codeInsight/stdlib/PyNamedTupleType.java
@@ -95,7 +95,7 @@ public class PyNamedTupleType extends PyClassTypeImpl implements PyCallableType
@Nullable
@Override
- public PyType getCallType(@NotNull TypeEvalContext context, @NotNull PyQualifiedExpression callSite) {
+ public PyType getCallType(@NotNull TypeEvalContext context, @NotNull PyCallSiteExpression callSite) {
if (myDefinitionLevel > 0) {
return new PyNamedTupleType(myClass, myDeclaration, myName, myFields, myDefinitionLevel-1);
}
diff --git a/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibCanonicalPathProvider.java b/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibCanonicalPathProvider.java
index 1a097263c24a..8a0b9ebe7050 100644
--- a/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibCanonicalPathProvider.java
+++ b/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibCanonicalPathProvider.java
@@ -73,6 +73,10 @@ public class PyStdlibCanonicalPathProvider implements PyCanonicalPathProvider {
components.set(0, "sqlite3");
return QualifiedName.fromComponents(components);
}
+ else if (head.equals("_pickle")) {
+ components.set(0, "pickle");
+ return QualifiedName.fromComponents(components);
+ }
}
return null;
}
diff --git a/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibTypeProvider.java b/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibTypeProvider.java
index d7678c2cd871..346d40f3273e 100644
--- a/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibTypeProvider.java
+++ b/python/src/com/jetbrains/python/codeInsight/stdlib/PyStdlibTypeProvider.java
@@ -120,7 +120,7 @@ public class PyStdlibTypeProvider extends PyTypeProviderBase {
@Nullable
@Override
- public PyType getCallType(@NotNull PyFunction function, @Nullable PyQualifiedExpression callSite, @NotNull TypeEvalContext context) {
+ public PyType getCallType(@NotNull PyFunction function, @Nullable PyCallSiteExpression callSite, @NotNull TypeEvalContext context) {
final String qname = getQualifiedName(function, callSite);
if (qname != null) {
if (OPEN_FUNCTIONS.contains(qname) && callSite != null) {