From d508a6d17e88ddd4438b7cddf59253e0614b08ad Mon Sep 17 00:00:00 2001 From: "Liana.Bakradze" Date: Wed, 8 Feb 2017 10:50:55 +0300 Subject: [PATCH] extend PyFrameAccessor to avoid instanceof (PY-22535) --- .../python/debugger/PyFrameAccessor.java | 3 ++ .../console/PydevConsoleCommunication.java | 15 +++++++++ .../python/debugger/PyDebugProcess.java | 10 ++++++ .../containerview/PyDataViewerPanel.java | 32 +++---------------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java b/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java index 5c752effc965..28b10a3c4c2f 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/PyFrameAccessor.java @@ -2,6 +2,7 @@ package com.jetbrains.python.debugger; import com.intellij.xdebugger.XSourcePosition; import com.intellij.xdebugger.frame.XValueChildrenList; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -31,4 +32,6 @@ public interface PyFrameAccessor { XSourcePosition getSourcePositionForType(String type); default void showNumericContainer(PyDebugValue value) {} + + default void setDataChangedCallback(@NotNull Runnable runnable) {} } diff --git a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java index 45c17e998821..4a39d4da021c 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java @@ -692,4 +692,19 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl public void showNumericContainer(PyDebugValue value) { PyViewNumericContainerAction.showNumericViewer(myProject, value); } + + @Override + public void setDataChangedCallback(@NotNull Runnable runnable) { + addCommunicationListener(new ConsoleCommunicationListener() { + @Override + public void commandExecuted(boolean more) { + runnable.run(); + } + + @Override + public void inputRequested() { + + } + }); + } } diff --git a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java index 2bb3a98e1dc5..4c53823770f6 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java @@ -1149,6 +1149,16 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr PyViewNumericContainerAction.showNumericViewer(getProject(), value); } + @Override + public void setDataChangedCallback(@NotNull Runnable runnable) { + getSession().addSessionListener(new XDebugSessionListener() { + @Override + public void stackFrameChanged() { + runnable.run(); + } + }); + } + @Nullable private static XSourcePosition typeToPosition(PyType pyType) { final PyClassType classType = PyUtil.as(pyType, PyClassType.class); diff --git a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.java b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.java index e34aed069ac8..21003577c907 100644 --- a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.java +++ b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.java @@ -30,14 +30,13 @@ import com.intellij.ui.components.JBLabel; import com.intellij.ui.table.JBTable; import com.intellij.util.TextFieldCompletionProvider; import com.intellij.util.ui.UIUtil; -import com.intellij.xdebugger.XDebugSession; -import com.intellij.xdebugger.XDebugSessionListener; import com.intellij.xdebugger.frame.XNamedValue; import com.intellij.xdebugger.frame.XValueChildrenList; import com.jetbrains.python.PythonFileType; -import com.jetbrains.python.console.PydevConsoleCommunication; -import com.jetbrains.python.console.pydev.ConsoleCommunicationListener; -import com.jetbrains.python.debugger.*; +import com.jetbrains.python.debugger.ArrayChunk; +import com.jetbrains.python.debugger.PyDebugValue; +import com.jetbrains.python.debugger.PyDebuggerException; +import com.jetbrains.python.debugger.PyFrameAccessor; import com.jetbrains.python.debugger.array.AsyncArrayTableModel; import com.jetbrains.python.debugger.array.JBTableWithRowHeaders; import org.jetbrains.annotations.NotNull; @@ -83,28 +82,7 @@ public class PyDataViewerPanel extends JPanel { } private void setupChangeListener() { - if (myFrameAccessor instanceof PyDebugProcess) { - XDebugSession session = ((PyDebugProcess)myFrameAccessor).getSession(); - session.addSessionListener(new XDebugSessionListener() { - @Override - public void stackFrameChanged() { - updateModel(); - } - }); - } - if (myFrameAccessor instanceof PydevConsoleCommunication) { - ((PydevConsoleCommunication)myFrameAccessor).addCommunicationListener(new ConsoleCommunicationListener() { - @Override - public void commandExecuted(boolean more) { - ApplicationManager.getApplication().invokeLater(() -> updateModel()); - } - - @Override - public void inputRequested() { - - } - }); - } + myFrameAccessor.setDataChangedCallback(() -> ApplicationManager.getApplication().invokeLater(() -> updateModel())); } private void updateModel() {