From a16af3a991bb0c44ed9feaa47b8b0118d7386439 Mon Sep 17 00:00:00 2001 From: Andrey Vlasovskikh Date: Wed, 31 Jul 2013 15:57:39 +0400 Subject: [PATCH] Extracted constant for unknown type --- python/psi-api/src/com/jetbrains/python/PyNames.java | 1 + .../com/jetbrains/python/debugger/PySignatureUtil.java | 3 ++- .../python/documentation/PyTypeModelBuilder.java | 9 ++++----- .../jetbrains/python/psi/types/PyCallableTypeImpl.java | 5 +++-- .../python/psi/types/PyDynamicallyEvaluatedType.java | 3 ++- .../src/com/jetbrains/python/psi/types/PyTupleType.java | 2 +- .../src/com/jetbrains/python/psi/types/PyTypeParser.java | 2 +- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/python/psi-api/src/com/jetbrains/python/PyNames.java b/python/psi-api/src/com/jetbrains/python/PyNames.java index 49111f5391db..531a9fdf0289 100644 --- a/python/psi-api/src/com/jetbrains/python/PyNames.java +++ b/python/psi-api/src/com/jetbrains/python/PyNames.java @@ -134,6 +134,7 @@ public class PyNames { public static final String NOT_IMPLEMENTED_ERROR = "NotImplementedError"; + public static final String UNKNOWN_TYPE = "unknown"; /** * Contains all known predefined names of "__foo__" form. diff --git a/python/src/com/jetbrains/python/debugger/PySignatureUtil.java b/python/src/com/jetbrains/python/debugger/PySignatureUtil.java index e44b0573b0f6..fbacc612ef07 100644 --- a/python/src/com/jetbrains/python/debugger/PySignatureUtil.java +++ b/python/src/com/jetbrains/python/debugger/PySignatureUtil.java @@ -4,6 +4,7 @@ import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElement; +import com.jetbrains.python.PyNames; import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.psi.PyFunction; import com.jetbrains.python.psi.types.PyClassType; @@ -49,7 +50,7 @@ public class PySignatureUtil { return type.getName(); } else { - return "unknown"; + return PyNames.UNKNOWN_TYPE; } } diff --git a/python/src/com/jetbrains/python/documentation/PyTypeModelBuilder.java b/python/src/com/jetbrains/python/documentation/PyTypeModelBuilder.java index 1f9983514e9d..9399b75f9201 100644 --- a/python/src/com/jetbrains/python/documentation/PyTypeModelBuilder.java +++ b/python/src/com/jetbrains/python/documentation/PyTypeModelBuilder.java @@ -5,12 +5,12 @@ import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.intellij.psi.PsiElement; +import com.jetbrains.python.PyNames; import com.jetbrains.python.psi.PyFunction; import com.jetbrains.python.psi.PyNamedParameter; import com.jetbrains.python.psi.PyParameter; import com.jetbrains.python.psi.types.*; import com.jetbrains.python.toolbox.ChainIterable; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,7 +26,6 @@ import static com.jetbrains.python.documentation.DocumentationBuilderKit.combUp; * @author traff */ public class PyTypeModelBuilder { - @NonNls static final String UNKNOWN = "unknown"; private final Map myVisited = Maps.newHashMap(); private final TypeEvalContext myContext; @@ -139,7 +138,7 @@ public class PyTypeModelBuilder { return evaluated; } if (myVisited.containsKey(type)) { //already evaluating? - return type != null ? _(type.getName()) : _(UNKNOWN); + return type != null ? _(type.getName()) : _(PyNames.UNKNOWN_TYPE); } myVisited.put(type, null); //mark as evaluating @@ -177,7 +176,7 @@ public class PyTypeModelBuilder { } } if (result == null) { - result = type != null ? _(type.getName()) : _(UNKNOWN); + result = type != null ? _(type.getName()) : _(PyNames.UNKNOWN_TYPE); } myVisited.put(type, result); return result; @@ -193,7 +192,7 @@ public class PyTypeModelBuilder { final PyNamedParameter np = p.getAsNamed(); if (np != null) { TypeModel paramType = - _(UNKNOWN); + _(PyNames.UNKNOWN_TYPE); final PyType t = myContext.getType(np); if (t != null) { paramType = build(t, true); diff --git a/python/src/com/jetbrains/python/psi/types/PyCallableTypeImpl.java b/python/src/com/jetbrains/python/psi/types/PyCallableTypeImpl.java index e1c51ed92ef8..9a2359ed2f70 100644 --- a/python/src/com/jetbrains/python/psi/types/PyCallableTypeImpl.java +++ b/python/src/com/jetbrains/python/psi/types/PyCallableTypeImpl.java @@ -3,6 +3,7 @@ package com.jetbrains.python.psi.types; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Function; import com.intellij.util.ProcessingContext; +import com.jetbrains.python.PyNames; import com.jetbrains.python.psi.AccessDirection; import com.jetbrains.python.psi.PyExpression; import com.jetbrains.python.psi.PyQualifiedExpression; @@ -64,11 +65,11 @@ public class PyCallableTypeImpl implements PyCallableType { new Function() { @Override public String fun(PyType type) { - return type != null ? type.getName() : "unknown"; + return type != null ? type.getName() : PyNames.UNKNOWN_TYPE; } }, ", "), - myReturnType != null ? myReturnType.getName() : "unknown"); + myReturnType != null ? myReturnType.getName() : PyNames.UNKNOWN_TYPE); } @Override diff --git a/python/src/com/jetbrains/python/psi/types/PyDynamicallyEvaluatedType.java b/python/src/com/jetbrains/python/psi/types/PyDynamicallyEvaluatedType.java index 837a861be096..a8b83501373f 100644 --- a/python/src/com/jetbrains/python/psi/types/PyDynamicallyEvaluatedType.java +++ b/python/src/com/jetbrains/python/psi/types/PyDynamicallyEvaluatedType.java @@ -1,5 +1,6 @@ package com.jetbrains.python.psi.types; +import com.jetbrains.python.PyNames; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -34,6 +35,6 @@ public class PyDynamicallyEvaluatedType extends PyUnionType { @Override public String getName() { PyType res = excludeNull(); - return res != null ? res.getName() : "unknown"; + return res != null ? res.getName() : PyNames.UNKNOWN_TYPE; } } diff --git a/python/src/com/jetbrains/python/psi/types/PyTupleType.java b/python/src/com/jetbrains/python/psi/types/PyTupleType.java index c4157f1d3ce4..715cb5262f71 100644 --- a/python/src/com/jetbrains/python/psi/types/PyTupleType.java +++ b/python/src/com/jetbrains/python/psi/types/PyTupleType.java @@ -42,7 +42,7 @@ public class PyTupleType extends PyClassTypeImpl implements PySubscriptableType return "(" + StringUtil.join(myElementTypes, new Function() { @Nullable public String fun(PyType pyType) { - return pyType == null ? "unknown" : pyType.getName(); + return pyType == null ? PyNames.UNKNOWN_TYPE : pyType.getName(); } }, ",") + ")"; } diff --git a/python/src/com/jetbrains/python/psi/types/PyTypeParser.java b/python/src/com/jetbrains/python/psi/types/PyTypeParser.java index 8af0776f1825..1e57982053b9 100644 --- a/python/src/com/jetbrains/python/psi/types/PyTypeParser.java +++ b/python/src/com/jetbrains/python/psi/types/PyTypeParser.java @@ -449,7 +449,7 @@ public class PyTypeParser { final String name = token.getText().toString(); final TextRange range = token.getRange(); - if ("unknown".equals(name)) { + if (PyNames.UNKNOWN_TYPE.equals(name)) { return EMPTY_RESULT; } else if (PyNames.NONE.equals(name)) {