import org.jetbrains.annotations.Nullable;
import javax.swing.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
// todo: load long lists by parts
// todo: null modifier for modify modules, class objects etc.
}
public PyDebugValue setParent(@Nullable PyDebugValue parent) {
- return new PyDebugValue(myName, myType, null, myValue, myContainer, myErrorOnEval, parent, myFrameAccessor);
+ return new PyDebugValue(myName, myType, myTypeQualifier, myValue, myContainer, myErrorOnEval, parent, myFrameAccessor);
}
public PyDebugValue getParent() {
}
public PyDebugValue setName(String newName) {
- return new PyDebugValue(newName, myType, null, myValue, myContainer, myErrorOnEval, myParent, myFrameAccessor);
+ return new PyDebugValue(newName, myType, myTypeQualifier, myValue, myContainer, myErrorOnEval, myParent, myFrameAccessor);
}
@Nullable
return true;
}
+ private static final Pattern IS_TYPE_DECLARATION = Pattern.compile("<(?:class|type)\\s*'(?<TYPE>.*?)'>");
@Override
public void computeTypeSourcePosition(@NotNull XNavigatable navigatable) {
- navigatable.setSourcePosition(myFrameAccessor.getSourcePositionForType(getQualifiedType()));
+ String lookupType = getDeclaringType();
+ navigatable.setSourcePosition(myFrameAccessor.getSourcePositionForType(lookupType));
+ }
+
+ private String getDeclaringType() {
+ String lookupType = getQualifiedType();
+ if (!Strings.isNullOrEmpty(myValue))
+ {
+ Matcher matcher = IS_TYPE_DECLARATION.matcher(myValue);
+ if (matcher.matches())
+ {
+ lookupType = matcher.group("TYPE");
+ }
+ }
+ return lookupType;
}
public String getQualifiedType() {
import com.jetbrains.python.console.PythonDebugLanguageConsoleView;
import com.jetbrains.python.console.pydev.PydevCompletionVariant;
import com.jetbrains.python.debugger.pydev.*;
-import com.jetbrains.python.psi.PyClass;
-import com.jetbrains.python.psi.PyFunction;
-import com.jetbrains.python.psi.PyImportElement;
-import com.jetbrains.python.psi.PyPsiFacade;
+import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.resolve.PyResolveUtil;
import com.jetbrains.python.psi.types.PyClassType;
+import com.jetbrains.python.psi.types.PyModuleType;
import com.jetbrains.python.psi.types.PyType;
import com.jetbrains.python.psi.types.PyTypeParser;
import org.jetbrains.annotations.NotNull;
final PsiFile file = getPsiFile(currentPosition);
- if (file == null) return null;
-
+ if (file == null || typeName == null || !(file instanceof PyFile)) return null;
+ typeName = typeName.replace("__builtin__.", "");
if (!typeName.contains(".")) {
PyType type = PyTypeParser.getTypeByName(file, typeName);
}
}
+ PyElementGenerator generator = PyElementGenerator.getInstance(getProject());
PyPsiFacade psiFacade = PyPsiFacade.getInstance(getProject());
- PyClass aClass = psiFacade.findClass(typeName);
- if (aClass != null)
- {
- return XSourcePositionImpl.createByElement(aClass);
+ PyType pyType = psiFacade.parseTypeAnnotation(typeName, generator.createDummyFile(((PyFile)file).getLanguageLevel(), ""));
+
+ if (pyType != null) {
+ final PyClassType classType = PyUtil.as(pyType, PyClassType.class);
+
+ if (classType != null) {
+ return XSourcePositionImpl.createByElement(classType.getPyClass());
+ }
+
+ final PyModuleType moduleType = PyUtil.as(pyType, PyModuleType.class);
+ if (moduleType != null) {
+ return XSourcePositionImpl.createByElement(moduleType.getModule());
+ }
}
+
+
+
return null;
}
}