summaryrefslogtreecommitdiff
path: root/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java')
-rw-r--r--python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java84
1 files changed, 41 insertions, 43 deletions
diff --git a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java
index 86f84abb7fb6..2c1842f3337f 100644
--- a/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java
+++ b/python/src/com/jetbrains/python/psi/impl/PyFunctionImpl.java
@@ -16,6 +16,7 @@
package com.jetbrains.python.psi.impl;
import com.intellij.lang.ASTNode;
+import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
@@ -54,6 +55,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.*;
+import static com.intellij.openapi.util.text.StringUtil.notNullize;
import static com.jetbrains.python.psi.PyFunction.Modifier.CLASSMETHOD;
import static com.jetbrains.python.psi.PyFunction.Modifier.STATICMETHOD;
import static com.jetbrains.python.psi.impl.PyCallExpressionHelper.interpretAsModifierWrappingCall;
@@ -61,7 +63,7 @@ import static com.jetbrains.python.psi.impl.PyCallExpressionHelper.interpretAsMo
/**
* Implements PyFunction.
*/
-public class PyFunctionImpl extends PyPresentableElementImpl<PyFunctionStub> implements PyFunction {
+public class PyFunctionImpl extends PyBaseElementImpl<PyFunctionStub> implements PyFunction {
public PyFunctionImpl(ASTNode astNode) {
super(astNode);
@@ -259,6 +261,17 @@ public class PyFunctionImpl extends PyPresentableElementImpl<PyFunctionStub> imp
return type;
}
+ @Override
+ public ItemPresentation getPresentation() {
+ return new PyElementPresentation(this) {
+ @Nullable
+ @Override
+ public String getPresentableText() {
+ return notNullize(getName(), PyNames.UNNAMED_ELEMENT) + getParameterList().getPresentableText(true);
+ }
+ };
+ }
+
@Nullable
private PyType replaceSelf(@Nullable PyType returnType, @Nullable PyExpression receiver, @NotNull TypeEvalContext context) {
if (receiver != null) {
@@ -292,32 +305,30 @@ public class PyFunctionImpl extends PyPresentableElementImpl<PyFunctionStub> imp
final PyBuiltinCache cache = PyBuiltinCache.getInstance(this);
final PyStatementList statements = getStatementList();
final Set<PyType> types = new LinkedHashSet<PyType>();
- if (statements != null) {
- statements.accept(new PyRecursiveElementVisitor() {
- @Override
- public void visitPyYieldExpression(PyYieldExpression node) {
- final PyType type = context.getType(node);
- if (node.isDelegating() && type instanceof PyCollectionType) {
- final PyCollectionType collectionType = (PyCollectionType)type;
- types.add(collectionType.getElementType(context));
- }
- else {
- types.add(type);
- }
+ statements.accept(new PyRecursiveElementVisitor() {
+ @Override
+ public void visitPyYieldExpression(PyYieldExpression node) {
+ final PyType type = context.getType(node);
+ if (node.isDelegating() && type instanceof PyCollectionType) {
+ final PyCollectionType collectionType = (PyCollectionType)type;
+ types.add(collectionType.getElementType(context));
}
-
- @Override
- public void visitPyFunction(PyFunction node) {
- // Ignore nested functions
+ else {
+ types.add(type);
}
- });
- final int n = types.size();
- if (n == 1) {
- elementType = Ref.create(types.iterator().next());
}
- else if (n > 0) {
- elementType = Ref.create(PyUnionType.union(types));
+
+ @Override
+ public void visitPyFunction(PyFunction node) {
+ // Ignore nested functions
}
+ });
+ final int n = types.size();
+ if (n == 1) {
+ elementType = Ref.create(types.iterator().next());
+ }
+ else if (n > 0) {
+ elementType = Ref.create(PyUnionType.union(types));
}
if (elementType != null) {
final PyClass generator = cache.getClass(PyNames.FAKE_GENERATOR);
@@ -335,14 +346,12 @@ public class PyFunctionImpl extends PyPresentableElementImpl<PyFunctionStub> imp
public PyType getReturnStatementType(TypeEvalContext typeEvalContext) {
ReturnVisitor visitor = new ReturnVisitor(this, typeEvalContext);
final PyStatementList statements = getStatementList();
- if (statements != null) {
- statements.accept(visitor);
- if (isGeneratedStub() && !visitor.myHasReturns) {
- if (PyNames.INIT.equals(getName())) {
- return PyNoneType.INSTANCE;
- }
- return null;
+ statements.accept(visitor);
+ if (isGeneratedStub() && !visitor.myHasReturns) {
+ if (PyNames.INIT.equals(getName())) {
+ return PyNoneType.INSTANCE;
}
+ return null;
}
return visitor.result();
}
@@ -376,9 +385,6 @@ public class PyFunctionImpl extends PyPresentableElementImpl<PyFunctionStub> imp
@Nullable
public String extractDeprecationMessage() {
PyStatementList statementList = getStatementList();
- if (statementList == null) {
- return null;
- }
return extractDeprecationMessage(Arrays.asList(statementList.getStatements()));
}
@@ -430,7 +436,7 @@ public class PyFunctionImpl extends PyPresentableElementImpl<PyFunctionStub> imp
@Nullable
@Override
public StructuredDocString getStructuredDocString() {
- return CachedValuesManager.getManager(getProject()).getCachedValue(this, myCachedStructuredDocStringProvider);
+ return CachedValuesManager.getCachedValue(this, myCachedStructuredDocStringProvider);
}
private boolean isGeneratedStub() {
@@ -527,15 +533,7 @@ public class PyFunctionImpl extends PyPresentableElementImpl<PyFunctionStub> imp
public PyStringLiteralExpression getDocStringExpression() {
final PyStatementList stmtList = getStatementList();
- return stmtList != null ? DocStringUtil.findDocStringExpression(stmtList) : null;
- }
-
- protected String getElementLocation() {
- final PyClass containingClass = getContainingClass();
- if (containingClass != null) {
- return "(" + containingClass.getName() + " in " + getPackageForFile(getContainingFile()) + ")";
- }
- return super.getElementLocation();
+ return DocStringUtil.findDocStringExpression(stmtList);
}
@NotNull