extracted magic variables to separate debug value
authorliana.bakradze <liana.bakradze@jetbrains.com>
Sun, 26 Jul 2015 18:17:32 +0000 (21:17 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Sun, 26 Jul 2015 18:17:32 +0000 (21:17 +0300)
python/edu/src/META-INF/PyCharmEduPlugin.xml
python/edu/src/com/jetbrains/python/edu/PyDebugCurrentFileAction.java
python/edu/src/com/jetbrains/python/edu/debugger/PyEduDebugExecutor.java [moved from python/edu/src/com/jetbrains/python/edu/PyEduDebugExecutor.java with 93% similarity]
python/edu/src/com/jetbrains/python/edu/debugger/PyEduDebugRunner.java [moved from python/edu/src/com/jetbrains/python/edu/PyEduDebugRunner.java with 97% similarity]
python/edu/src/com/jetbrains/python/edu/debugger/PyEduDebugTransformer.java [new file with mode: 0644]
python/edu/src/com/jetbrains/python/edu/debugger/PyEduMagicDebugValue.java [new file with mode: 0644]
python/src/META-INF/python-core.xml
python/src/com/jetbrains/python/debugger/PyDebugValueTransformer.java [new file with mode: 0644]
python/src/com/jetbrains/python/debugger/PyStackFrame.java

index 38415ba90f2d527bb7af639a53feeb9501f55a7b..749418f21e8b0862540699bc411e67850512b5a3 100644 (file)
   <extensions defaultExtensionNs="com.intellij">
       <codeInsight.lineMarkerProvider language="Python" implementationClass="com.jetbrains.python.edu.PyDebugFileLineMarkerProvider"/>
       <codeInsight.lineMarkerProvider language="Python" implementationClass="com.jetbrains.python.edu.PyExecuteFileLineMarkerProvider"/>
-      <programRunner implementation="com.jetbrains.python.edu.PyEduDebugRunner"/>
-      <executor implementation="com.jetbrains.python.edu.PyEduDebugExecutor" order="first,after run"/>
+      <programRunner implementation="com.jetbrains.python.edu.debugger.PyEduDebugRunner"/>
+      <executor implementation="com.jetbrains.python.edu.debugger.PyEduDebugExecutor" order="first,after run"/>>
+  </extensions>
+
+  <extensions defaultExtensionNs="Pythonid">
+    <pyDebugValueTransformer implementation="com.jetbrains.python.edu.debugger.PyEduDebugTransformer"/>
   </extensions>
 
   <actions>
index 8e1f394e19c184bfefc0862b458e9f352437f654..bd9373f0057dcad81132c870c58f527ac4d59244 100644 (file)
@@ -3,6 +3,7 @@ package com.jetbrains.python.edu;
 import com.intellij.execution.RunnerAndConfigurationSettings;
 import com.intellij.execution.runners.ExecutionUtil;
 import com.intellij.icons.AllIcons;
+import com.jetbrains.python.edu.debugger.PyEduDebugExecutor;
 
 public class PyDebugCurrentFileAction extends PyRunConfigurationForFileAction {
 
similarity index 93%
rename from python/edu/src/com/jetbrains/python/edu/PyEduDebugExecutor.java
rename to python/edu/src/com/jetbrains/python/edu/debugger/PyEduDebugExecutor.java
index 69c39f6fa12c538d98bfa8d6f222d1f7d6c1409b..3bf50fa25b1816bbb8a0ab1dc00669599f7ec5c3 100644 (file)
@@ -1,4 +1,4 @@
-package com.jetbrains.python.edu;
+package com.jetbrains.python.edu.debugger;
 
 import com.intellij.execution.Executor;
 import com.intellij.execution.ExecutorRegistry;
similarity index 97%
rename from python/edu/src/com/jetbrains/python/edu/PyEduDebugRunner.java
rename to python/edu/src/com/jetbrains/python/edu/debugger/PyEduDebugRunner.java
index 32e8fbb38fa98965547a5ae327fa643fb1966e07..23a5068df1c946a1cc774c909306b67639567053 100644 (file)
@@ -1,4 +1,4 @@
-package com.jetbrains.python.edu;
+package com.jetbrains.python.edu.debugger;
 
 import com.intellij.codeInsight.daemon.impl.CollectHighlightsUtil;
 import com.intellij.execution.configurations.RunProfile;
@@ -20,6 +20,7 @@ import com.jetbrains.python.debugger.PyDebugRunner;
 import com.jetbrains.python.debugger.PyLineBreakpointType;
 import com.jetbrains.python.debugger.PySourcePosition;
 import com.jetbrains.python.documentation.DocStringUtil;
+import com.jetbrains.python.edu.PyEduUtils;
 import com.jetbrains.python.psi.PyExpression;
 import com.jetbrains.python.psi.PyExpressionStatement;
 import com.jetbrains.python.psi.PyImportStatement;
diff --git a/python/edu/src/com/jetbrains/python/edu/debugger/PyEduDebugTransformer.java b/python/edu/src/com/jetbrains/python/edu/debugger/PyEduDebugTransformer.java
new file mode 100644 (file)
index 0000000..a4ce044
--- /dev/null
@@ -0,0 +1,31 @@
+package com.jetbrains.python.edu.debugger;
+
+import com.intellij.util.containers.hash.HashMap;
+import com.intellij.xdebugger.frame.XValue;
+import com.intellij.xdebugger.frame.XValueChildrenList;
+import com.jetbrains.python.debugger.PyDebugValueTransformer;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Map;
+
+public class PyEduDebugTransformer implements PyDebugValueTransformer {
+  @Override
+  public XValueChildrenList getTransformedChildren(@NotNull XValueChildrenList children) {
+    XValueChildrenList list = new XValueChildrenList();
+    Map<String, XValue> magicValues = new HashMap<String, XValue>();
+    for (int i = 0; i < children.size(); i++) {
+      String name = children.getName(i);
+      XValue value = children.getValue(i);
+      if (name.startsWith("__") && name.endsWith("__")) {
+        magicValues.put(name, value);
+      }
+      else {
+        list.add(name, value);
+      }
+    }
+    if (!magicValues.isEmpty()) {
+      list.add(new PyEduMagicDebugValue("magic variables", magicValues));
+    }
+    return list;
+  }
+}
diff --git a/python/edu/src/com/jetbrains/python/edu/debugger/PyEduMagicDebugValue.java b/python/edu/src/com/jetbrains/python/edu/debugger/PyEduMagicDebugValue.java
new file mode 100644 (file)
index 0000000..eebf370
--- /dev/null
@@ -0,0 +1,45 @@
+package com.jetbrains.python.edu.debugger;
+
+
+import com.intellij.icons.AllIcons;
+import com.intellij.xdebugger.frame.*;
+import com.intellij.xdebugger.frame.presentation.XValuePresentation;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Map;
+
+public class PyEduMagicDebugValue extends XNamedValue {
+
+  private final Map<String, XValue> myValues;
+
+  protected PyEduMagicDebugValue(@NotNull String name, Map<String, XValue> values) {
+    super(name);
+    myValues = values;
+  }
+
+  @Override
+  public void computePresentation(@NotNull XValueNode node, @NotNull XValuePlace place) {
+    node.setPresentation(AllIcons.Nodes.Artifact, new XValuePresentation() {
+
+      @Override
+      public void renderValue(@NotNull XValueTextRenderer renderer) {
+        renderer.renderComment("{Python Pro Only}");
+      }
+
+      @NotNull
+      @Override
+      public String getSeparator() {
+        return " ";
+      }
+    }, true);
+  }
+
+  @Override
+  public void computeChildren(@NotNull XCompositeNode node) {
+    XValueChildrenList children = new XValueChildrenList();
+    for (Map.Entry<String, XValue> entry : myValues.entrySet()) {
+      children.add(entry.getKey(), entry.getValue());
+    }
+    node.addChildren(children, true);
+  }
+}
\ No newline at end of file
index 476948f3a9bc75bb85a2c5bcf1c6ce0587b2b046..a4d701bb8528d6bff01ff01dc35f87b3230eab6d 100644 (file)
     <extensionPoint qualifiedName="Pythonid.breakpointHandler" interface="com.jetbrains.python.debugger.PyBreakpointHandlerFactory"/>
     <extensionPoint qualifiedName="Pythonid.consoleOptionsProvider" interface="com.jetbrains.python.console.PyConsoleOptionsProvider"/>
     <extensionPoint qualifiedName="Pythonid.pyRootTypeProvider" interface="com.jetbrains.python.module.PyRootTypeProvider"/>
+    <extensionPoint qualifiedName="Pythonid.pyDebugValueTransformer" interface="com.jetbrains.python.debugger.PyDebugValueTransformer"/>
   </extensionPoints>
 
   <extensions defaultExtensionNs="Pythonid">
diff --git a/python/src/com/jetbrains/python/debugger/PyDebugValueTransformer.java b/python/src/com/jetbrains/python/debugger/PyDebugValueTransformer.java
new file mode 100644 (file)
index 0000000..b928029
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2000-2015 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.debugger;
+
+import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.xdebugger.frame.XValueChildrenList;
+import org.jetbrains.annotations.NotNull;
+
+public interface PyDebugValueTransformer {
+  ExtensionPointName<PyDebugValueTransformer> EP_NAME = ExtensionPointName.create("Pythonid.pyDebugValueTransformer");
+
+  /**
+   * This method is used in python debugger to modify content and presentation of stack frame nodes
+   * @param children
+   * @return modified children list
+   */
+  XValueChildrenList getTransformedChildren(@NotNull final XValueChildrenList children);
+}
index 9f1f0234694c12a36e4ae1032bb5855042c9ac74..3d2d3326c7079ac40507873ef155317af0e8a2d7 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.icons.AllIcons;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Document;
+import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.ProjectRootManager;
@@ -108,9 +109,16 @@ public class PyStackFrame extends XStackFrame {
       @Override
       public void run() {
         try {
-          final XValueChildrenList values = myDebugProcess.loadFrame();
+          XValueChildrenList values = myDebugProcess.loadFrame();
           if (!node.isObsolete()) {
-            node.addChildren(values != null ? values : XValueChildrenList.EMPTY, true);
+            if (values == null) {
+              node.addChildren(XValueChildrenList.EMPTY, true);
+              return;
+            }
+            for (PyDebugValueTransformer transformer : Extensions.getExtensions(PyDebugValueTransformer.EP_NAME)) {
+              values = transformer.getTransformedChildren(values);
+            }
+            node.addChildren(values, true);
           }
         }
         catch (PyDebuggerException e) {