Fix warnings and remove unused code

GitOrigin-RevId: d0b352165d64ed2b1d0508e22061b1bd3a0cd4ba
This commit is contained in:
Elizaveta Shashkova
2019-11-21 09:37:12 +00:00
committed by intellij-monorepo-bot
parent eb489aed8e
commit e244d07de6
13 changed files with 45 additions and 56 deletions
@@ -9,7 +9,6 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.xdebugger.frame.*;
import com.intellij.xdebugger.frame.presentation.XRegularValuePresentation;
import com.jetbrains.python.debugger.pydev.PyDebugCallback;
import com.jetbrains.python.debugger.pydev.PyVariableLocator;
import com.jetbrains.python.debugger.render.PyNodeRenderer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -23,7 +22,6 @@ import java.util.regex.Pattern;
import static com.jetbrains.python.debugger.PyDebugValueGroupsKt.*;
// todo: null modifier for modify modules, class objects etc.
public class PyDebugValue extends XNamedValue {
private static final Logger LOG = Logger.getInstance(PyDebugValue.class);
private static final String DATA_FRAME = "DataFrame";
@@ -47,7 +45,6 @@ public class PyDebugValue extends XNamedValue {
private @Nullable String myId = null;
private ValuesPolicy myLoadValuePolicy;
private @NotNull PyFrameAccessor myFrameAccessor;
private @Nullable PyVariableLocator myVariableLocator;
private volatile @Nullable XValueNode myLastNode = null;
private final boolean myErrorOnEval;
private int myOffset;
@@ -117,7 +114,7 @@ public class PyDebugValue extends XNamedValue {
myParent = parent;
myFrameAccessor = frameAccessor;
myLoadValuePolicy = ValuesPolicy.SYNC;
if (POLICY_DEFAULT_VALUES.keySet().contains(myValue)) {
if (POLICY_DEFAULT_VALUES.containsKey(myValue)) {
myLoadValuePolicy = POLICY_DEFAULT_VALUES.get(myValue);
setValue(" ");
}
@@ -535,15 +532,6 @@ public class PyDebugValue extends XNamedValue {
myFrameAccessor = frameAccessor;
}
@Nullable
public PyVariableLocator getVariableLocator() {
return myVariableLocator;
}
public void setVariableLocator(@Nullable PyVariableLocator variableLocator) {
myVariableLocator = variableLocator;
}
@Nullable
public String getId() {
return myId;
@@ -20,11 +20,12 @@ import com.intellij.xdebugger.frame.XCompositeNode;
import com.intellij.xdebugger.frame.XValueChildrenList;
import com.jetbrains.python.debugger.pydev.PyDebugCallback;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PyReferringObjectsValue extends PyDebugValue {
private static final Logger LOG = Logger.getInstance(PyReferringObjectsValue.class);
private final @NotNull PyReferrersLoader myReferrersLoader;
private final @Nullable PyReferrersLoader myReferrersLoader;
public PyReferringObjectsValue(@NotNull String name,
String type,
@@ -52,7 +53,10 @@ public class PyReferringObjectsValue extends PyDebugValue {
@Override
public void computeChildren(@NotNull final XCompositeNode node) {
if (node.isObsolete()) return;
if (myReferrersLoader == null) {
LOG.error("Failed to load Referring Objects. Frame accessor: " + getFrameAccessor());
return;
}
myReferrersLoader.loadReferrers(this, new PyDebugCallback<XValueChildrenList>() {
@Override
public void ok(XValueChildrenList value) {
@@ -72,6 +76,6 @@ public class PyReferringObjectsValue extends PyDebugValue {
}
public boolean isField() {
return false; //TODO
return false;
}
}
@@ -17,7 +17,7 @@ public abstract class PySourcePosition {
@Nullable
protected String normalize(@Nullable String file) {
if (file == null) {
return file;
return null;
}
return FileUtil.toSystemIndependentName(file);
@@ -23,7 +23,7 @@ import java.util.List;
*/
public class PydevXmlUtils {
static SAXParserFactory parserFactory = SAXParserFactory.newInstance();
private static final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
private PydevXmlUtils() {
}
@@ -298,6 +298,7 @@ public class ClientModeMultiProcessDebugger implements ProcessDebugger {
if (!isDebuggersEmpty()) {
//here we add process id to thread name in case there are more then one process
return Collections.unmodifiableCollection(Collections2.transform(threads, t -> {
if (t == null) return null;
String threadName = ThreadRegistry.threadName(t.getName(), t.getId());
PyThreadInfo newThread =
new PyThreadInfo(t.getId(), threadName, t.getFrames(),
@@ -9,8 +9,6 @@ import org.jetbrains.annotations.NotNull;
* @author amarch
*/
public class GetArrayCommand extends GetFrameCommand {
private final PyDebugValue myParent;
private final String myVariableName;
private final int myRowOffset;
private final int myColOffset;
@@ -27,7 +25,6 @@ public class GetArrayCommand extends GetFrameCommand {
myRows = rows;
myColumns = cols;
myFormat = format;
myParent = var;
}
@Override
@@ -38,10 +35,7 @@ public class GetArrayCommand extends GetFrameCommand {
payload.add(myColumns);
payload.add(myFormat);
if (myParent.getVariableLocator() != null) {
payload.add(myParent.getVariableLocator().getThreadId()).add(myParent.getVariableLocator().getPyDBLocation());
}
else if (myVariableName.contains(GetVariableCommand.BY_ID)) {
if (myVariableName.contains(GetVariableCommand.BY_ID)) {
//id instead of frame_id
payload.add(getThreadId()).add(myVariableName);
}
@@ -48,10 +48,7 @@ public class GetVariableCommand extends GetFrameCommand {
@Override
protected void buildPayload(Payload payload) {
if (myParent.getVariableLocator() != null) {
payload.add(myParent.getVariableLocator().getThreadId()).add(myParent.getVariableLocator().getPyDBLocation());
}
else if (myVariableName.contains(BY_ID)) {
if (myVariableName.contains(BY_ID)) {
//id instead of frame_id
payload.add(getThreadId()).add(myVariableName);
}
@@ -49,10 +49,7 @@ public class LoadFullValueCommand extends AbstractFrameCommand {
private String buildPayloadForVar(@NotNull PyDebugValue var) {
StringBuilder sb = new StringBuilder();
String varName = GetVariableCommand.composeName(var);
if (var.getVariableLocator() != null) {
sb.append(var.getVariableLocator().getThreadId()).append(var.getVariableLocator().getPyDBLocation());
}
else if (varName.contains(GetVariableCommand.BY_ID)) {
if (varName.contains(GetVariableCommand.BY_ID)) {
sb.append(getThreadId()).append(varName);
}
else {
@@ -53,6 +53,7 @@ public class MultiProcessDebugger implements ProcessDebugger {
myDebugServerSocket = createServerSocket();
}
catch (ExecutionException e) {
LOG.error("Failed to start debugger:", e);
}
myMainDebugger = new RemoteDebugger(myDebugProcess, myDebugServerSocket, myTimeoutInMillis);
}
@@ -85,18 +86,25 @@ public class MultiProcessDebugger implements ProcessDebugger {
ApplicationManager.getApplication().executeOnPooledThread(myDebugProcessAcceptor);
}
private static void sendDebuggerPort(Socket socket, ServerSocket serverSocket, IPyDebugProcess processHandler) throws IOException {
private static void sendDebuggerPort(@NotNull Socket socket, @NotNull ServerSocket serverSocket, @NotNull IPyDebugProcess processHandler)
throws IOException {
int port = processHandler.handleDebugPort(serverSocket.getLocalPort());
PrintWriter writer = new PrintWriter(socket.getOutputStream());
writer.println(99 + "\t" + -1 + "\t" + port);
writer.flush();
socket.close();
try {
writer.println(99 + "\t" + -1 + "\t" + port);
writer.flush();
}
finally {
socket.close();
writer.close();
}
}
@NotNull
private static ServerSocket createServerSocket() throws ExecutionException {
final ServerSocket serverSocket;
try {
//noinspection SocketOpenedButNotSafelyClosed
//noinspection IOResourceOpenedButNotSafelyClosed,SocketOpenedButNotSafelyClosed
serverSocket = new ServerSocket(0);
}
catch (IOException e) {
@@ -263,6 +271,7 @@ public class MultiProcessDebugger implements ProcessDebugger {
if (myOtherDebuggers.size() > 0) {
//here we add process id to thread name in case there are more then one process
return Collections.unmodifiableCollection(Collections2.transform(threads, t -> {
if (t == null) return null;
String threadName = ThreadRegistry.threadName(t.getName(), t.getId());
PyThreadInfo newThread =
new PyThreadInfo(t.getId(), threadName, t.getFrames(),
@@ -77,7 +77,7 @@ class RecurrentTaskExecutor<out T>(threadsName: String,
init {
val threadFactory = ConcurrencyUtil.newNamedThreadFactory(threadsName)
executorService = Executors.newFixedThreadPool(FIXED_THREAD_POOL_SIZE, threadFactory)
repeat(FIXED_THREAD_POOL_SIZE, { executorService.submit(TaskRunnable()) })
repeat(FIXED_THREAD_POOL_SIZE) { executorService.submit(TaskRunnable()) }
}
fun incrementRequests() {
@@ -264,6 +264,10 @@ public class RemoteDebugger implements ProcessDebugger {
// todo: change variable in lists doesn't work - either fix in pydevd or format var name appropriately
private void setTempVariable(final String threadId, final String frameId, final PyDebugValue var) {
final PyDebugValue topVar = var.getTopParent();
if (topVar == null) {
LOG.error("Top parent is null");
return;
}
if (!myDebugProcess.canSaveToTemp(topVar.getName())) {
return;
}
@@ -125,7 +125,7 @@ public class ServerModeDebuggerTransport extends BaseDebuggerTransport {
}
public static class DebuggerReader extends BaseDebuggerReader {
public DebuggerReader(@NotNull RemoteDebugger debugger, @NotNull InputStream stream) throws IOException {
public DebuggerReader(@NotNull RemoteDebugger debugger, @NotNull InputStream stream) {
super(stream, StandardCharsets.UTF_8, debugger); //TODO: correct encoding?
start(getClass().getName());
}
@@ -75,8 +75,6 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* @author yole
*/
// todo: bundle messages
// todo: pydevd supports module reloading - look for a way to use the feature
public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, ProcessListener {
private static final Logger LOG = Logger.getInstance(PyDebugProcess.class);
@@ -100,8 +98,6 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
private final Map<String, PyDebugValue> myNewVariableValue = Maps.newHashMap();
private boolean myDownloadSources = false;
private boolean myClosing = false;
protected PyPositionConverter myPositionConverter;
private final XSmartStepIntoHandler<?> mySmartStepIntoHandler;
private boolean myWaitingForConnection = false;
@@ -424,16 +420,16 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
if ("@@BUILD_NUMBER@@".equals(remoteVersion)) {
remoteVersion = currentBuild;
}
else remoteVersion = StringUtil.trimStart(remoteVersion, "PY-");
else {
remoteVersion = StringUtil.trimStart(remoteVersion, "PY-");
}
printToConsole("Connected to pydev debugger (build " + remoteVersion + ")\n", ConsoleViewContentType.SYSTEM_OUTPUT);
if (remoteVersion != null) {
if (!(remoteVersion.equals(currentBuild) || remoteVersion.startsWith(currentBuild))) {
LOG.warn(String.format("Wrong debugger version. Remote version: %s Current build: %s", remoteVersion, currentBuild));
printToConsole(String.format("Warning: wrong debugger version. Use pycharm-debugger.egg from PyCharm installation folder\n" +
"Or execute: 'pip install pydevd-pycharm~=%s'\n", currentBuild),
ConsoleViewContentType.ERROR_OUTPUT);
}
if (!(remoteVersion.equals(currentBuild) || remoteVersion.startsWith(currentBuild))) {
LOG.warn(String.format("Wrong debugger version. Remote version: %s Current build: %s", remoteVersion, currentBuild));
printToConsole(String.format("Warning: wrong debugger version. Use pycharm-debugger.egg from PyCharm installation folder\n" +
"Or execute: 'pip install pydevd-pycharm~=%s'\n", currentBuild),
ConsoleViewContentType.ERROR_OUTPUT);
}
}
@@ -564,7 +560,7 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
@Override
public void resume(@Nullable XSuspendContext context) {
passToAllThreads(ResumeOrStepCommand.Mode.RESUME);
passResumeToAllThreads();
}
@Override
@@ -611,11 +607,11 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
return false;
}
private void passToAllThreads(final ResumeOrStepCommand.Mode mode) {
private void passResumeToAllThreads() {
dropFrameCaches();
if (isConnected()) {
for (PyThreadInfo thread : myDebugger.getThreads()) {
myDebugger.resumeOrStep(thread.getId(), mode);
myDebugger.resumeOrStep(thread.getId(), ResumeOrStepCommand.Mode.RESUME);
}
}
}
@@ -1060,7 +1056,6 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
@Override
public void processWillTerminate(@NotNull ProcessEvent event, boolean willBeDestroyed) {
myClosing = true;
}
@Override