--Properly process objects which are type definitions
authorYuli Fiterman fitermay <fiterman@gmail.com>
Fri, 1 Apr 2016 18:23:59 +0000 (14:23 -0400)
committerfitermay <fiterman@gmail.com>
Wed, 13 Apr 2016 02:56:53 +0000 (22:56 -0400)
python/pydevSrc/com/jetbrains/python/debugger/PyDebugValue.java
python/src/com/jetbrains/python/debugger/PyDebugProcess.java

index ae6d982a44e7b242a3581be336391aca4939412f..afd426d05df0915de6b9c8065e60b58fb164fa26 100644 (file)
@@ -10,6 +10,8 @@ import org.jetbrains.annotations.NotNull;
 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.
@@ -73,7 +75,7 @@ public class PyDebugValue extends XNamedValue {
   }
   
   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() {
@@ -216,7 +218,7 @@ public class PyDebugValue extends XNamedValue {
   }
   
   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
@@ -269,10 +271,25 @@ public class PyDebugValue extends XNamedValue {
     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() {
index 8b50fad604b9874bce7026ccbbf0b9c2c896a73e..f95464c32d6d86efa3bab57905509c7ee81c816e 100644 (file)
@@ -60,12 +60,10 @@ import com.jetbrains.python.PythonFileType;
 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;
@@ -912,10 +910,10 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
 
     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);
 
@@ -924,13 +922,26 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
       }
     }
 
+    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;
   }
 }