From 533f715d7b8ec4b630eab94d181ec021791a853f Mon Sep 17 00:00:00 2001 From: andxu Date: Fri, 8 Sep 2017 13:29:35 +0800 Subject: [PATCH 1/2] move src folders --- .gitignore | 38 ++ .../org}/eclipse/jdt/ls/debug/DebugEvent.java | 0 .../eclipse/jdt/ls/debug/DebugException.java | 64 +-- .../eclipse/jdt/ls/debug/DebugUtility.java | 0 .../eclipse/jdt/ls/debug/IBreakpoint.java | 0 .../eclipse/jdt/ls/debug/IDebugResource.java | 0 .../eclipse/jdt/ls/debug/IDebugSession.java | 0 .../org}/eclipse/jdt/ls/debug/IEventHub.java | 0 .../jdt/ls/debug/adapter/AdapterUtils.java | 0 .../ls/debug/adapter/BreakpointManager.java | 348 ++++++------ .../jdt/ls/debug/adapter/Constants.java | 32 +- .../jdt/ls/debug/adapter/DebugAdapter.java | 0 .../ls/debug/adapter/DebugAdapterContext.java | 344 ++++++------ .../jdt/ls/debug/adapter/ErrorCode.java | 74 +-- .../eclipse/jdt/ls/debug/adapter/Events.java | 0 .../jdt/ls/debug/adapter/IDebugAdapter.java | 0 .../debug/adapter/IDebugAdapterContext.java | 0 .../debug/adapter/IDebugRequestHandler.java | 0 .../jdt/ls/debug/adapter/IProvider.java | 0 .../ls/debug/adapter/IProviderContext.java | 0 .../debug/adapter/ISourceLookUpProvider.java | 0 .../IVirtualMachineManagerProvider.java | 0 .../jdt/ls/debug/adapter/IdCollection.java | 158 +++--- .../jdt/ls/debug/adapter/JsonUtils.java | 274 ++++----- .../jdt/ls/debug/adapter/LRUCache.java | 0 .../jdt/ls/debug/adapter/Messages.java | 0 .../jdt/ls/debug/adapter/ProcessConsole.java | 238 ++++---- .../jdt/ls/debug/adapter/ProtocolServer.java | 0 .../jdt/ls/debug/adapter/ProviderContext.java | 0 .../debug/adapter/RecyclableObjectPool.java | 0 .../jdt/ls/debug/adapter/Requests.java | 422 +++++++------- .../jdt/ls/debug/adapter/Responses.java | 0 .../eclipse/jdt/ls/debug/adapter/Types.java | 0 .../formatter/ArrayObjectFormatter.java | 0 .../adapter/formatter/BooleanFormatter.java | 0 .../adapter/formatter/CharacterFormatter.java | 0 .../formatter/ClassObjectFormatter.java | 0 .../debug/adapter/formatter/IFormatter.java | 0 .../adapter/formatter/ITypeFormatter.java | 0 .../adapter/formatter/IValueFormatter.java | 0 .../formatter/NullObjectFormatter.java | 0 .../adapter/formatter/NumericFormatEnum.java | 0 .../adapter/formatter/NumericFormatter.java | 0 .../adapter/formatter/ObjectFormatter.java | 0 .../formatter/SimpleTypeFormatter.java | 0 .../formatter/StringObjectFormatter.java | 0 .../adapter/formatter/TypeIdentifiers.java | 0 .../adapter/handler/AttachRequestHandler.java | 140 ++--- .../ConfigurationDoneRequestHandler.java | 196 +++---- .../handler/DisconnectRequestHandler.java | 90 +-- .../handler/EvaluateRequestHandler.java | 376 ++++++------- .../handler/InitializeRequestHandler.java | 0 .../adapter/handler/LaunchRequestHandler.java | 192 +++---- .../adapter/handler/ScopesRequestHandler.java | 110 ++-- .../handler/SetBreakpointsRequestHandler.java | 252 ++++----- ...SetExceptionBreakpointsRequestHandler.java | 98 ++-- .../handler/SetVariableRequestHandler.java | 528 +++++++++--------- .../adapter/handler/SourceRequestHandler.java | 96 ++-- .../handler/StackTraceRequestHandler.java | 260 ++++----- .../handler/ThreadsRequestHandler.java | 308 +++++----- .../handler/VariablesRequestHandler.java | 388 ++++++------- .../adapter/variables/IVariableFormatter.java | 0 .../adapter/variables/JdiObjectProxy.java | 0 .../ls/debug/adapter/variables/Variable.java | 0 .../adapter/variables/VariableFormatter.java | 0 .../variables/VariableFormatterFactory.java | 0 .../adapter/variables/VariableProxy.java | 140 ++--- .../adapter/variables/VariableUtils.java | 0 .../jdt/ls/debug/internal/Breakpoint.java | 0 .../jdt/ls/debug/internal/DebugSession.java | 0 .../jdt/ls/debug/internal/EventHub.java | 0 .../internal/JavaDebuggerServerPlugin.java | 0 .../eclipse/jdt/ls/debug/internal/Logger.java | 68 +-- .../internal/JavaDebuggerServerPlugin.java | 33 ++ .../debug/adapter/jdt/DebugServerFactory.java | 48 +- .../ls/debug/adapter/jdt/JavaDebugServer.java | 0 .../jdt/JdtProviderContextFactory.java | 0 .../adapter/jdt/JdtSourceLookUpProvider.java | 0 .../jdt/JdtVirtualMachineManagerProvider.java | 0 79 files changed, 2693 insertions(+), 2622 deletions(-) create mode 100644 .gitignore rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/DebugEvent.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/DebugException.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/DebugUtility.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/IBreakpoint.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/IDebugResource.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/IDebugSession.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/IEventHub.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/AdapterUtils.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/BreakpointManager.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Constants.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/DebugAdapter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ErrorCode.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Events.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IProvider.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IProviderContext.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IdCollection.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/JsonUtils.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/LRUCache.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Messages.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ProcessConsole.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ProtocolServer.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ProviderContext.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Requests.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Responses.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Types.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/Variable.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/Breakpoint.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/DebugSession.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/EventHub.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/Logger.java (97%) create mode 100644 com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java (97%) rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java (100%) rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java (100%) rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java (100%) rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..5e2dd10da --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar +*.iml + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + +**/.idea/ +**/node_modules/ +.DS_Store +.idea +target/ +.classpath +.project +.settings +javaConfig.json +**/.checkstyle +target/ +bin/ +**/lib/ \ No newline at end of file diff --git a/org/eclipse/jdt/ls/debug/DebugEvent.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugEvent.java similarity index 100% rename from org/eclipse/jdt/ls/debug/DebugEvent.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugEvent.java diff --git a/org/eclipse/jdt/ls/debug/DebugException.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugException.java similarity index 96% rename from org/eclipse/jdt/ls/debug/DebugException.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugException.java index 1a97b0aec..563273cb4 100644 --- a/org/eclipse/jdt/ls/debug/DebugException.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugException.java @@ -1,32 +1,32 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug; - -public class DebugException extends Exception { - private static final long serialVersionUID = 1L; - - public DebugException() { - super(); - } - - public DebugException(String message) { - super(message); - } - - public DebugException(String message, Throwable cause) { - super(message, cause); - } - - public DebugException(Throwable cause) { - super(cause); - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug; + +public class DebugException extends Exception { + private static final long serialVersionUID = 1L; + + public DebugException() { + super(); + } + + public DebugException(String message) { + super(message); + } + + public DebugException(String message, Throwable cause) { + super(message, cause); + } + + public DebugException(Throwable cause) { + super(cause); + } +} diff --git a/org/eclipse/jdt/ls/debug/DebugUtility.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugUtility.java similarity index 100% rename from org/eclipse/jdt/ls/debug/DebugUtility.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugUtility.java diff --git a/org/eclipse/jdt/ls/debug/IBreakpoint.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IBreakpoint.java similarity index 100% rename from org/eclipse/jdt/ls/debug/IBreakpoint.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IBreakpoint.java diff --git a/org/eclipse/jdt/ls/debug/IDebugResource.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IDebugResource.java similarity index 100% rename from org/eclipse/jdt/ls/debug/IDebugResource.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IDebugResource.java diff --git a/org/eclipse/jdt/ls/debug/IDebugSession.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IDebugSession.java similarity index 100% rename from org/eclipse/jdt/ls/debug/IDebugSession.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IDebugSession.java diff --git a/org/eclipse/jdt/ls/debug/IEventHub.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IEventHub.java similarity index 100% rename from org/eclipse/jdt/ls/debug/IEventHub.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IEventHub.java diff --git a/org/eclipse/jdt/ls/debug/adapter/AdapterUtils.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/AdapterUtils.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/AdapterUtils.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/AdapterUtils.java diff --git a/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java index 97510f878..33a9c5285 100644 --- a/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java @@ -1,174 +1,174 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - -import org.eclipse.jdt.ls.debug.IBreakpoint; -import org.eclipse.jdt.ls.debug.internal.Logger; - -public class BreakpointManager { - /** - * A collection of breakpoints registered with this manager. - */ - private List breakpoints; - private HashMap> sourceToBreakpoints; - private AtomicInteger nextBreakpointId = new AtomicInteger(1); - - /** - * Constructor. - */ - public BreakpointManager() { - this.breakpoints = Collections.synchronizedList(new ArrayList<>(5)); - this.sourceToBreakpoints = new HashMap<>(); - } - - /** - * Adds breakpoints to breakpoint manager. - * Deletes all breakpoints that are no longer listed. - * @param source - * source path of breakpoints - * @param breakpoints - * full list of breakpoints that locates in this source file - * @return the full breakpoint list that locates in the source file - */ - public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints) { - return setBreakpoints(source, breakpoints, false); - } - - /** - * Adds breakpoints to breakpoint manager. - * Deletes all breakpoints that are no longer listed. - * In the case of modified source, delete everything. - * @param source - * source path of breakpoints - * @param breakpoints - * full list of breakpoints that locates in this source file - * @param sourceModified - * the source file are modified or not. - * @return the full breakpoint list that locates in the source file - */ - public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints, boolean sourceModified) { - List result = new ArrayList<>(); - HashMap breakpointMap = this.sourceToBreakpoints.get(source); - // When source file is modified, delete all previously added breakpoints. - if (sourceModified && breakpointMap != null) { - for (IBreakpoint bp : breakpointMap.values()) { - try { - // Destroy the breakpoint on the debugee VM. - bp.close(); - } catch (Exception e) { - Logger.logException("Remove breakpoint exception", e); - } - this.breakpoints.remove(bp); - } - this.sourceToBreakpoints.put(source, null); - breakpointMap = null; - } - if (breakpointMap == null) { - breakpointMap = new HashMap<>(); - this.sourceToBreakpoints.put(source, breakpointMap); - } - - // Compute the breakpoints that are newly added. - List toAdd = new ArrayList<>(); - List visitedLineNumbers = new ArrayList<>(); - for (IBreakpoint breakpoint : breakpoints) { - IBreakpoint existed = breakpointMap.get(String.valueOf(breakpoint.lineNumber())); - if (existed != null) { - result.add(existed); - visitedLineNumbers.add(existed.lineNumber()); - continue; - } else { - result.add(breakpoint); - } - toAdd.add(breakpoint); - } - - // Compute the breakpoints that are no longer listed. - List toRemove = new ArrayList<>(); - for (IBreakpoint breakpoint : breakpointMap.values()) { - if (!visitedLineNumbers.contains(breakpoint.lineNumber())) { - toRemove.add(breakpoint); - } - } - - removeBreakpointsInternally(source, toRemove.toArray(new IBreakpoint[0])); - addBreakpointsInternally(source, toAdd.toArray(new IBreakpoint[0])); - - return result.toArray(new IBreakpoint[0]); - } - - private void addBreakpointsInternally(String source, IBreakpoint[] breakpoints) { - Map breakpointMap = this.sourceToBreakpoints.computeIfAbsent(source, k -> new HashMap<>()); - - if (breakpoints != null && breakpoints.length > 0) { - for (IBreakpoint breakpoint : breakpoints) { - breakpoint.putProperty("id", this.nextBreakpointId.getAndIncrement()); - this.breakpoints.add(breakpoint); - breakpointMap.put(String.valueOf(breakpoint.lineNumber()), breakpoint); - } - } - } - - /** - * Removes the specified breakpoints from breakpoint manager. - */ - private void removeBreakpointsInternally(String source, IBreakpoint[] breakpoints) { - Map breakpointMap = this.sourceToBreakpoints.get(source); - if (breakpointMap == null || breakpointMap.isEmpty() || breakpoints.length == 0) { - return; - } - - for (IBreakpoint breakpoint : breakpoints) { - if (this.breakpoints.contains(breakpoint)) { - try { - // Destroy the breakpoint on the debugee VM. - breakpoint.close(); - this.breakpoints.remove(breakpoint); - breakpointMap.remove(String.valueOf(breakpoint.lineNumber())); - } catch (Exception e) { - Logger.logException("Remove breakpoint exception", e); - } - } - } - } - - public IBreakpoint[] getBreakpoints() { - return this.breakpoints.toArray(new IBreakpoint[0]); - } - - /** - * Gets the registered breakpoints at the source file. - */ - public IBreakpoint[] getBreakpoints(String source) { - HashMap breakpointMap = this.sourceToBreakpoints.get(source); - if (breakpointMap == null) { - return new IBreakpoint[0]; - } - return breakpointMap.values().toArray(new IBreakpoint[0]); - } - - /** - * Cleanup all breakpoints and reset the breakpoint id counter. - */ - public void reset() { - this.sourceToBreakpoints.clear(); - this.breakpoints.clear(); - this.nextBreakpointId.set(1); - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +import org.eclipse.jdt.ls.debug.IBreakpoint; +import org.eclipse.jdt.ls.debug.internal.Logger; + +public class BreakpointManager { + /** + * A collection of breakpoints registered with this manager. + */ + private List breakpoints; + private HashMap> sourceToBreakpoints; + private AtomicInteger nextBreakpointId = new AtomicInteger(1); + + /** + * Constructor. + */ + public BreakpointManager() { + this.breakpoints = Collections.synchronizedList(new ArrayList<>(5)); + this.sourceToBreakpoints = new HashMap<>(); + } + + /** + * Adds breakpoints to breakpoint manager. + * Deletes all breakpoints that are no longer listed. + * @param source + * source path of breakpoints + * @param breakpoints + * full list of breakpoints that locates in this source file + * @return the full breakpoint list that locates in the source file + */ + public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints) { + return setBreakpoints(source, breakpoints, false); + } + + /** + * Adds breakpoints to breakpoint manager. + * Deletes all breakpoints that are no longer listed. + * In the case of modified source, delete everything. + * @param source + * source path of breakpoints + * @param breakpoints + * full list of breakpoints that locates in this source file + * @param sourceModified + * the source file are modified or not. + * @return the full breakpoint list that locates in the source file + */ + public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints, boolean sourceModified) { + List result = new ArrayList<>(); + HashMap breakpointMap = this.sourceToBreakpoints.get(source); + // When source file is modified, delete all previously added breakpoints. + if (sourceModified && breakpointMap != null) { + for (IBreakpoint bp : breakpointMap.values()) { + try { + // Destroy the breakpoint on the debugee VM. + bp.close(); + } catch (Exception e) { + Logger.logException("Remove breakpoint exception", e); + } + this.breakpoints.remove(bp); + } + this.sourceToBreakpoints.put(source, null); + breakpointMap = null; + } + if (breakpointMap == null) { + breakpointMap = new HashMap<>(); + this.sourceToBreakpoints.put(source, breakpointMap); + } + + // Compute the breakpoints that are newly added. + List toAdd = new ArrayList<>(); + List visitedLineNumbers = new ArrayList<>(); + for (IBreakpoint breakpoint : breakpoints) { + IBreakpoint existed = breakpointMap.get(String.valueOf(breakpoint.lineNumber())); + if (existed != null) { + result.add(existed); + visitedLineNumbers.add(existed.lineNumber()); + continue; + } else { + result.add(breakpoint); + } + toAdd.add(breakpoint); + } + + // Compute the breakpoints that are no longer listed. + List toRemove = new ArrayList<>(); + for (IBreakpoint breakpoint : breakpointMap.values()) { + if (!visitedLineNumbers.contains(breakpoint.lineNumber())) { + toRemove.add(breakpoint); + } + } + + removeBreakpointsInternally(source, toRemove.toArray(new IBreakpoint[0])); + addBreakpointsInternally(source, toAdd.toArray(new IBreakpoint[0])); + + return result.toArray(new IBreakpoint[0]); + } + + private void addBreakpointsInternally(String source, IBreakpoint[] breakpoints) { + Map breakpointMap = this.sourceToBreakpoints.computeIfAbsent(source, k -> new HashMap<>()); + + if (breakpoints != null && breakpoints.length > 0) { + for (IBreakpoint breakpoint : breakpoints) { + breakpoint.putProperty("id", this.nextBreakpointId.getAndIncrement()); + this.breakpoints.add(breakpoint); + breakpointMap.put(String.valueOf(breakpoint.lineNumber()), breakpoint); + } + } + } + + /** + * Removes the specified breakpoints from breakpoint manager. + */ + private void removeBreakpointsInternally(String source, IBreakpoint[] breakpoints) { + Map breakpointMap = this.sourceToBreakpoints.get(source); + if (breakpointMap == null || breakpointMap.isEmpty() || breakpoints.length == 0) { + return; + } + + for (IBreakpoint breakpoint : breakpoints) { + if (this.breakpoints.contains(breakpoint)) { + try { + // Destroy the breakpoint on the debugee VM. + breakpoint.close(); + this.breakpoints.remove(breakpoint); + breakpointMap.remove(String.valueOf(breakpoint.lineNumber())); + } catch (Exception e) { + Logger.logException("Remove breakpoint exception", e); + } + } + } + } + + public IBreakpoint[] getBreakpoints() { + return this.breakpoints.toArray(new IBreakpoint[0]); + } + + /** + * Gets the registered breakpoints at the source file. + */ + public IBreakpoint[] getBreakpoints(String source) { + HashMap breakpointMap = this.sourceToBreakpoints.get(source); + if (breakpointMap == null) { + return new IBreakpoint[0]; + } + return breakpointMap.values().toArray(new IBreakpoint[0]); + } + + /** + * Cleanup all breakpoints and reset the breakpoint id counter. + */ + public void reset() { + this.sourceToBreakpoints.clear(); + this.breakpoints.clear(); + this.nextBreakpointId.set(1); + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/Constants.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Constants.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/Constants.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Constants.java index 967705238..106237ae0 100644 --- a/org/eclipse/jdt/ls/debug/adapter/Constants.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Constants.java @@ -1,16 +1,16 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -public final class Constants { - public static final String PROJECTNAME = "projectName"; -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +public final class Constants { + public static final String PROJECTNAME = "projectName"; +} diff --git a/org/eclipse/jdt/ls/debug/adapter/DebugAdapter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/DebugAdapter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java index 8f38efc08..72d91c449 100644 --- a/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java @@ -1,172 +1,172 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.Map; - -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.Events.DebugEvent; -import org.eclipse.jdt.ls.debug.adapter.variables.IVariableFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableFormatterFactory; - -public class DebugAdapterContext implements IDebugAdapterContext { - private static final int MAX_CACHE_ITEMS = 10000; - private Map sourceMappingCache = Collections.synchronizedMap(new LRUCache<>(MAX_CACHE_ITEMS)); - private DebugAdapter debugAdapter; - - private IDebugSession debugSession; - private boolean debuggerLinesStartAt1 = true; - private boolean debuggerPathsAreUri = true; - private boolean clientLinesStartAt1 = true; - private boolean clientPathsAreUri = false; - private boolean isAttached = false; - private String[] sourcePaths; - private Charset debuggeeEncoding; - - private IdCollection sourceReferences = new IdCollection<>(); - private RecyclableObjectPool recyclableIdPool = new RecyclableObjectPool<>(); - private IVariableFormatter variableFormatter = VariableFormatterFactory.createVariableFormatter(); - - public DebugAdapterContext(DebugAdapter debugAdapter) { - this.debugAdapter = debugAdapter; - } - - @Override - public void sendEvent(DebugEvent event) { - this.debugAdapter.sendEvent(event); - } - - @Override - public void sendEventAsync(DebugEvent event) { - this.debugAdapter.sendEventLater(event); - } - - @Override - public T getProvider(Class clazz) { - return this.debugAdapter.getProvider(clazz); - } - - @Override - public void setDebugSession(IDebugSession session) { - this.debugSession = session; - } - - @Override - public IDebugSession getDebugSession() { - return this.debugSession; - } - - @Override - public boolean isDebuggerLinesStartAt1() { - return this.debuggerLinesStartAt1; - } - - @Override - public void setDebuggerLinesStartAt1(boolean debuggerLinesStartAt1) { - this.debuggerLinesStartAt1 = debuggerLinesStartAt1; - } - - @Override - public boolean isDebuggerPathsAreUri() { - return this.debuggerPathsAreUri; - } - - @Override - public void setDebuggerPathsAreUri(boolean debuggerPathsAreUri) { - this.debuggerPathsAreUri = debuggerPathsAreUri; - } - - @Override - public boolean isClientLinesStartAt1() { - return this.clientLinesStartAt1; - } - - @Override - public void setClientLinesStartAt1(boolean clientLinesStartAt1) { - this.clientLinesStartAt1 = clientLinesStartAt1; - } - - @Override - public boolean isClientPathsAreUri() { - return this.clientPathsAreUri; - } - - @Override - public void setClientPathsAreUri(boolean clientPathsAreUri) { - this.clientPathsAreUri = clientPathsAreUri; - } - - @Override - public boolean isAttached() { - return this.isAttached; - } - - @Override - public void setAttached(boolean attached) { - this.isAttached = attached; - } - - public String[] getSourcePaths() { - return this.sourcePaths; - } - - public void setSourcePaths(String[] sourcePaths) { - this.sourcePaths = sourcePaths; - } - - @Override - public String getSourceUri(int sourceReference) { - return this.sourceReferences.get(sourceReference); - } - - @Override - public int createSourceReference(String uri) { - return this.sourceReferences.create(uri); - } - - @Override - public RecyclableObjectPool getRecyclableIdPool() { - return this.recyclableIdPool; - } - - @Override - public void setRecyclableIdPool(RecyclableObjectPool idPool) { - this.recyclableIdPool = idPool; - } - - @Override - public IVariableFormatter getVariableFormatter() { - return this.variableFormatter; - } - - @Override - public void setVariableFormatter(IVariableFormatter variableFormatter) { - this.variableFormatter = variableFormatter; - } - - @Override - public Map getSourceLookupCache() { - return this.sourceMappingCache; - } - - @Override - public void setDebuggeeEncoding(Charset encoding) { - this.debuggeeEncoding = encoding; - } - - @Override - public Charset getDebuggeeEncoding() { - return this.debuggeeEncoding; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.nio.charset.Charset; +import java.util.Collections; +import java.util.Map; + +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.Events.DebugEvent; +import org.eclipse.jdt.ls.debug.adapter.variables.IVariableFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableFormatterFactory; + +public class DebugAdapterContext implements IDebugAdapterContext { + private static final int MAX_CACHE_ITEMS = 10000; + private Map sourceMappingCache = Collections.synchronizedMap(new LRUCache<>(MAX_CACHE_ITEMS)); + private DebugAdapter debugAdapter; + + private IDebugSession debugSession; + private boolean debuggerLinesStartAt1 = true; + private boolean debuggerPathsAreUri = true; + private boolean clientLinesStartAt1 = true; + private boolean clientPathsAreUri = false; + private boolean isAttached = false; + private String[] sourcePaths; + private Charset debuggeeEncoding; + + private IdCollection sourceReferences = new IdCollection<>(); + private RecyclableObjectPool recyclableIdPool = new RecyclableObjectPool<>(); + private IVariableFormatter variableFormatter = VariableFormatterFactory.createVariableFormatter(); + + public DebugAdapterContext(DebugAdapter debugAdapter) { + this.debugAdapter = debugAdapter; + } + + @Override + public void sendEvent(DebugEvent event) { + this.debugAdapter.sendEvent(event); + } + + @Override + public void sendEventAsync(DebugEvent event) { + this.debugAdapter.sendEventLater(event); + } + + @Override + public T getProvider(Class clazz) { + return this.debugAdapter.getProvider(clazz); + } + + @Override + public void setDebugSession(IDebugSession session) { + this.debugSession = session; + } + + @Override + public IDebugSession getDebugSession() { + return this.debugSession; + } + + @Override + public boolean isDebuggerLinesStartAt1() { + return this.debuggerLinesStartAt1; + } + + @Override + public void setDebuggerLinesStartAt1(boolean debuggerLinesStartAt1) { + this.debuggerLinesStartAt1 = debuggerLinesStartAt1; + } + + @Override + public boolean isDebuggerPathsAreUri() { + return this.debuggerPathsAreUri; + } + + @Override + public void setDebuggerPathsAreUri(boolean debuggerPathsAreUri) { + this.debuggerPathsAreUri = debuggerPathsAreUri; + } + + @Override + public boolean isClientLinesStartAt1() { + return this.clientLinesStartAt1; + } + + @Override + public void setClientLinesStartAt1(boolean clientLinesStartAt1) { + this.clientLinesStartAt1 = clientLinesStartAt1; + } + + @Override + public boolean isClientPathsAreUri() { + return this.clientPathsAreUri; + } + + @Override + public void setClientPathsAreUri(boolean clientPathsAreUri) { + this.clientPathsAreUri = clientPathsAreUri; + } + + @Override + public boolean isAttached() { + return this.isAttached; + } + + @Override + public void setAttached(boolean attached) { + this.isAttached = attached; + } + + public String[] getSourcePaths() { + return this.sourcePaths; + } + + public void setSourcePaths(String[] sourcePaths) { + this.sourcePaths = sourcePaths; + } + + @Override + public String getSourceUri(int sourceReference) { + return this.sourceReferences.get(sourceReference); + } + + @Override + public int createSourceReference(String uri) { + return this.sourceReferences.create(uri); + } + + @Override + public RecyclableObjectPool getRecyclableIdPool() { + return this.recyclableIdPool; + } + + @Override + public void setRecyclableIdPool(RecyclableObjectPool idPool) { + this.recyclableIdPool = idPool; + } + + @Override + public IVariableFormatter getVariableFormatter() { + return this.variableFormatter; + } + + @Override + public void setVariableFormatter(IVariableFormatter variableFormatter) { + this.variableFormatter = variableFormatter; + } + + @Override + public Map getSourceLookupCache() { + return this.sourceMappingCache; + } + + @Override + public void setDebuggeeEncoding(Charset encoding) { + this.debuggeeEncoding = encoding; + } + + @Override + public Charset getDebuggeeEncoding() { + return this.debuggeeEncoding; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/ErrorCode.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java index 7212f062b..640ac13f4 100644 --- a/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java @@ -1,37 +1,37 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -public enum ErrorCode { - UNKNOWN_FAILURE(1000), - UNRECOGNIZED_REQUEST_FAILURE(1001), - LAUNCH_FAILURE(1002), - ATTACH_FAILURE(1003), - ARGUMENT_MISSING(1004), - SET_BREAKPOINT_FAILURE(1005), - SET_EXCEPTIONBREAKPOINT_FAILURE(1006), - GET_STACKTRACE_FAILURE(1007), - GET_VARIABLE_FAILURE(1008), - SET_VARIABLE_FAILURE(1009), - EVALUATE_FAILURE(1010), - EMPTY_DEBUG_SESSION(1011); - - private int id; - - ErrorCode(int id) { - this.id = id; - } - - public int getId() { - return this.id; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +public enum ErrorCode { + UNKNOWN_FAILURE(1000), + UNRECOGNIZED_REQUEST_FAILURE(1001), + LAUNCH_FAILURE(1002), + ATTACH_FAILURE(1003), + ARGUMENT_MISSING(1004), + SET_BREAKPOINT_FAILURE(1005), + SET_EXCEPTIONBREAKPOINT_FAILURE(1006), + GET_STACKTRACE_FAILURE(1007), + GET_VARIABLE_FAILURE(1008), + SET_VARIABLE_FAILURE(1009), + EVALUATE_FAILURE(1010), + EMPTY_DEBUG_SESSION(1011); + + private int id; + + ErrorCode(int id) { + this.id = id; + } + + public int getId() { + return this.id; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/Events.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Events.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/Events.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Events.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IProvider.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IProvider.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IProvider.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IProviderContext.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IProviderContext.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IProviderContext.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IProviderContext.java diff --git a/org/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IdCollection.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IdCollection.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/IdCollection.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IdCollection.java index f29aa97c1..d0178e6a0 100644 --- a/org/eclipse/jdt/ls/debug/adapter/IdCollection.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IdCollection.java @@ -1,79 +1,79 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.util.HashMap; -import java.util.concurrent.atomic.AtomicInteger; - -public class IdCollection { - private int startId; - private AtomicInteger nextId; - private HashMap idMap; - private HashMap reverseMap; - - public IdCollection() { - this(1); - } - - /** - * Constructs a new id generator with the given startId as the start id number. - * @param startId - * the start id number - */ - public IdCollection(int startId) { - this.startId = startId; - this.nextId = new AtomicInteger(startId); - this.idMap = new HashMap<>(); - this.reverseMap = new HashMap<>(); - } - - /** - * Reset the id to the initial start number. - */ - public void reset() { - this.nextId.set(this.startId); - this.idMap.clear(); - this.reverseMap.clear(); - } - - /** - * Create a new id if the id doesn't exist for the given value. - * Otherwise return the existing id. - */ - public int create(T value) { - if (this.reverseMap.containsKey(value)) { - return this.reverseMap.get(value); - } - int id = this.nextId.getAndIncrement(); - this.idMap.put(id, value); - this.reverseMap.put(value, id); - return id; - } - - /** - * Get the original value by the id. - */ - public T get(int id) { - return this.idMap.get(id); - } - - /** - * Remove the id from the id collection. - */ - public T remove(int id) { - T target = this.idMap.remove(id); - if (target != null) { - this.reverseMap.remove(target); - } - return target; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicInteger; + +public class IdCollection { + private int startId; + private AtomicInteger nextId; + private HashMap idMap; + private HashMap reverseMap; + + public IdCollection() { + this(1); + } + + /** + * Constructs a new id generator with the given startId as the start id number. + * @param startId + * the start id number + */ + public IdCollection(int startId) { + this.startId = startId; + this.nextId = new AtomicInteger(startId); + this.idMap = new HashMap<>(); + this.reverseMap = new HashMap<>(); + } + + /** + * Reset the id to the initial start number. + */ + public void reset() { + this.nextId.set(this.startId); + this.idMap.clear(); + this.reverseMap.clear(); + } + + /** + * Create a new id if the id doesn't exist for the given value. + * Otherwise return the existing id. + */ + public int create(T value) { + if (this.reverseMap.containsKey(value)) { + return this.reverseMap.get(value); + } + int id = this.nextId.getAndIncrement(); + this.idMap.put(id, value); + this.reverseMap.put(value, id); + return id; + } + + /** + * Get the original value by the id. + */ + public T get(int id) { + return this.idMap.get(id); + } + + /** + * Remove the id from the id collection. + */ + public T remove(int id) { + T target = this.idMap.remove(id); + if (target != null) { + this.reverseMap.remove(target); + } + return target; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/JsonUtils.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java index 69673da9a..f23b30ff1 100644 --- a/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java @@ -1,137 +1,137 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.lang.reflect.Type; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; - -public class JsonUtils { - private static final Gson GSON = new Gson(); - - public static T fromJson(String json, Class classOfT) throws JsonSyntaxException { - return GSON.fromJson(json, classOfT); - } - - public static T fromJson(String json, Type typeOfT) throws JsonSyntaxException { - return GSON.fromJson(json, typeOfT); - } - - public static T fromJson(JsonElement json, Class classOfT) throws JsonSyntaxException { - return GSON.fromJson(json, classOfT); - } - - public T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException { - return GSON.fromJson(json, typeOfT); - } - - public static String toJson(Object src) { - return GSON.toJson(src); - } - - public static String toJson(Object src, Type typeOfSrc) { - return GSON.toJson(src, typeOfSrc); - } - - /** - * Get the integer value for the specified property from the json Object. - * @param args - * the json object - * @param property - * the key - * @param defaultValue - * if key doesn't exist in the json object, then return the default value - * @return the value as an integer number - */ - public static int getInt(JsonObject args, String property, int defaultValue) { - try { - return args.getAsInt(); - } catch (Exception e) { - // ignore and return default value; - } - return defaultValue; - } - - /** - * Get the string value for the specified property from the json Object. - * @param args - * the json object - * @param property - * the key - * @param defaultValue - * if key doesn't exist in the json object, then return the default value - * @return the value as a string - */ - public static String getString(JsonObject args, String property, String defaultValue) { - String value = null; - try { - JsonElement obj = args.get(property); - value = obj.getAsString(); - } catch (Exception e) { - // ignore and return default value; - } - if (value == null) { - return defaultValue; - } - value = value.trim(); - if (value.length() == 0) { - return defaultValue; - } - return value; - } - - /** - * Get the boolean value for the specified property from the json Object. - * @param args - * the json object - * @param property - * the key - * @param defaultValue - * if key doesn't exist in the json object, then return the default value - * @return the value as boolean - */ - public static boolean getBoolean(JsonObject args, String property, boolean defaultValue) { - try { - JsonElement obj = args.get(property); - return obj.getAsBoolean(); - } catch (Exception e) { - // ignore and return default value; - } - return defaultValue; - } - - /** - * Extracts a list of property values from a json array object. - * @param args - * the json array element - * @param property - * the key - * @return an string array - */ - public static String[] getStringArray(JsonElement args, String property) { - if (args instanceof JsonArray) { - JsonArray array = (JsonArray) args; - int size = array.size(); - String[] result = new String[size]; - for (int i = 0; i < size; i++) { - result[i] = array.get(i).getAsString(); - } - return result; - } else { - return new String[0]; - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.lang.reflect.Type; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; + +public class JsonUtils { + private static final Gson GSON = new Gson(); + + public static T fromJson(String json, Class classOfT) throws JsonSyntaxException { + return GSON.fromJson(json, classOfT); + } + + public static T fromJson(String json, Type typeOfT) throws JsonSyntaxException { + return GSON.fromJson(json, typeOfT); + } + + public static T fromJson(JsonElement json, Class classOfT) throws JsonSyntaxException { + return GSON.fromJson(json, classOfT); + } + + public T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException { + return GSON.fromJson(json, typeOfT); + } + + public static String toJson(Object src) { + return GSON.toJson(src); + } + + public static String toJson(Object src, Type typeOfSrc) { + return GSON.toJson(src, typeOfSrc); + } + + /** + * Get the integer value for the specified property from the json Object. + * @param args + * the json object + * @param property + * the key + * @param defaultValue + * if key doesn't exist in the json object, then return the default value + * @return the value as an integer number + */ + public static int getInt(JsonObject args, String property, int defaultValue) { + try { + return args.getAsInt(); + } catch (Exception e) { + // ignore and return default value; + } + return defaultValue; + } + + /** + * Get the string value for the specified property from the json Object. + * @param args + * the json object + * @param property + * the key + * @param defaultValue + * if key doesn't exist in the json object, then return the default value + * @return the value as a string + */ + public static String getString(JsonObject args, String property, String defaultValue) { + String value = null; + try { + JsonElement obj = args.get(property); + value = obj.getAsString(); + } catch (Exception e) { + // ignore and return default value; + } + if (value == null) { + return defaultValue; + } + value = value.trim(); + if (value.length() == 0) { + return defaultValue; + } + return value; + } + + /** + * Get the boolean value for the specified property from the json Object. + * @param args + * the json object + * @param property + * the key + * @param defaultValue + * if key doesn't exist in the json object, then return the default value + * @return the value as boolean + */ + public static boolean getBoolean(JsonObject args, String property, boolean defaultValue) { + try { + JsonElement obj = args.get(property); + return obj.getAsBoolean(); + } catch (Exception e) { + // ignore and return default value; + } + return defaultValue; + } + + /** + * Extracts a list of property values from a json array object. + * @param args + * the json array element + * @param property + * the key + * @return an string array + */ + public static String[] getStringArray(JsonElement args, String property) { + if (args instanceof JsonArray) { + JsonArray array = (JsonArray) args; + int size = array.size(); + String[] result = new String[size]; + for (int i = 0; i < size; i++) { + result[i] = array.get(i).getAsString(); + } + return result; + } else { + return new String[0]; + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/LRUCache.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/LRUCache.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/LRUCache.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/LRUCache.java diff --git a/org/eclipse/jdt/ls/debug/adapter/Messages.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Messages.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/Messages.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Messages.java diff --git a/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java index 2b949c8cc..b4a1bea9f 100644 --- a/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java @@ -1,119 +1,119 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -import io.reactivex.functions.Consumer; -import io.reactivex.subjects.PublishSubject; - -public class ProcessConsole { - private Process process; - private String name; - private Charset encoding; - private PublishSubject stdoutSubject = PublishSubject.create(); - private PublishSubject stderrSubject = PublishSubject.create(); - private Thread stdoutThread = null; - private Thread stderrThread = null; - - public ProcessConsole(Process process) { - this(process, "Process", StandardCharsets.UTF_8); - } - - /** - * Constructor. - * @param process - * the process - * @param name - * the process name - * @param encoding - * the process encoding format - */ - public ProcessConsole(Process process, String name, Charset encoding) { - this.process = process; - this.name = name; - this.encoding = encoding; - } - - /** - * Start two separate threads to monitor the messages from stdout and stderr streams of the target process. - */ - public void start() { - this.stdoutThread = new Thread(this.name + " Stdout Handler") { - public void run() { - monitor(process.getInputStream(), stdoutSubject); - } - }; - stdoutThread.setDaemon(true); - stdoutThread.start(); - - this.stderrThread = new Thread(this.name + " Stderr Handler") { - public void run() { - monitor(process.getErrorStream(), stderrSubject); - } - }; - stderrThread.setDaemon(true); - stderrThread.start(); - } - - /** - * Stop the process console handlers. - */ - public void stop() { - if (this.stdoutThread != null) { - this.stdoutThread.interrupt(); - this.stdoutThread = null; - } - - if (this.stderrThread != null) { - this.stderrThread.interrupt(); - this.stderrThread = null; - } - } - - public void onStdout(Consumer callback) { - stdoutSubject.subscribe(callback); - } - - public void onStderr(Consumer callback) { - stderrSubject.subscribe(callback); - } - - private void monitor(InputStream input, PublishSubject subject) { - BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding)); - final int BUFFERSIZE = 4096; - char[] buffer = new char[BUFFERSIZE]; - while (true) { - try { - if (Thread.interrupted()) { - subject.onComplete(); - return; - } - int read = reader.read(buffer, 0, BUFFERSIZE); - if (read == -1) { - subject.onComplete(); - return; - } - - subject.onNext(new String(buffer, 0, read)); - } catch (IOException e) { - subject.onError(e); - return; - } - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import io.reactivex.functions.Consumer; +import io.reactivex.subjects.PublishSubject; + +public class ProcessConsole { + private Process process; + private String name; + private Charset encoding; + private PublishSubject stdoutSubject = PublishSubject.create(); + private PublishSubject stderrSubject = PublishSubject.create(); + private Thread stdoutThread = null; + private Thread stderrThread = null; + + public ProcessConsole(Process process) { + this(process, "Process", StandardCharsets.UTF_8); + } + + /** + * Constructor. + * @param process + * the process + * @param name + * the process name + * @param encoding + * the process encoding format + */ + public ProcessConsole(Process process, String name, Charset encoding) { + this.process = process; + this.name = name; + this.encoding = encoding; + } + + /** + * Start two separate threads to monitor the messages from stdout and stderr streams of the target process. + */ + public void start() { + this.stdoutThread = new Thread(this.name + " Stdout Handler") { + public void run() { + monitor(process.getInputStream(), stdoutSubject); + } + }; + stdoutThread.setDaemon(true); + stdoutThread.start(); + + this.stderrThread = new Thread(this.name + " Stderr Handler") { + public void run() { + monitor(process.getErrorStream(), stderrSubject); + } + }; + stderrThread.setDaemon(true); + stderrThread.start(); + } + + /** + * Stop the process console handlers. + */ + public void stop() { + if (this.stdoutThread != null) { + this.stdoutThread.interrupt(); + this.stdoutThread = null; + } + + if (this.stderrThread != null) { + this.stderrThread.interrupt(); + this.stderrThread = null; + } + } + + public void onStdout(Consumer callback) { + stdoutSubject.subscribe(callback); + } + + public void onStderr(Consumer callback) { + stderrSubject.subscribe(callback); + } + + private void monitor(InputStream input, PublishSubject subject) { + BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding)); + final int BUFFERSIZE = 4096; + char[] buffer = new char[BUFFERSIZE]; + while (true) { + try { + if (Thread.interrupted()) { + subject.onComplete(); + return; + } + int read = reader.read(buffer, 0, BUFFERSIZE); + if (read == -1) { + subject.onComplete(); + return; + } + + subject.onNext(new String(buffer, 0, read)); + } catch (IOException e) { + subject.onError(e); + return; + } + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/ProtocolServer.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProtocolServer.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/ProtocolServer.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProtocolServer.java diff --git a/org/eclipse/jdt/ls/debug/adapter/ProviderContext.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProviderContext.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/ProviderContext.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProviderContext.java diff --git a/org/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java diff --git a/org/eclipse/jdt/ls/debug/adapter/Requests.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Requests.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/Requests.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Requests.java index 1744fbc08..178a8e366 100644 --- a/org/eclipse/jdt/ls/debug/adapter/Requests.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Requests.java @@ -1,211 +1,211 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.util.Arrays; - -/** - * The request arguments types defined by VSCode Debug Protocol. - */ -public class Requests { - - public static class ValueFormat { - public boolean hex; - } - - public static class Arguments { - - } - - public static class InitializeArguments extends Arguments { - public String clientID; - public String adapterID; - public String pathFormat; - public boolean linesStartAt1; - public boolean columnsStartAt1; - public boolean supportsVariableType; - public boolean supportsVariablePaging; - public boolean supportsRunInTerminalRequest; - } - - public static class LaunchArguments extends Arguments { - public String type; - public String name; - public String request; - public String projectName; - public String mainClass; - public String args = ""; - public String vmArgs = ""; - public String[] classPaths = new String[0]; - public String[] sourcePaths = new String[0]; - } - - public static class AttachArguments extends Arguments { - public String type; - public String name; - public String request; - public String hostName; - public int port; - public int timeout = 30000; // Default to 30s. - public String[] sourcePaths = new String[0]; - public String projectName; - } - - public static class RestartArguments extends Arguments { - - } - - public static class DisconnectArguments extends Arguments { - // If client doesn't set terminateDebuggee attribute at the DisconnectRequest, - // the debugger would choose to terminate debuggee by default. - public boolean terminateDebuggee = true; - public boolean restart; - } - - public static class ConfigurationDoneArguments extends Arguments { - - } - - public static class SetBreakpointArguments extends Arguments { - public Types.Source source; - public int[] lines = new int[0]; - public Types.SourceBreakpoint[] breakpoints = new Types.SourceBreakpoint[0]; - public boolean sourceModified = false; - } - - public static class StackTraceArguments extends Arguments { - public long threadId; - public int startFrame; - public int levels; - } - - public static class SetFunctionBreakpointsArguments extends Arguments { - public Types.FunctionBreakpoint[] breakpoints; - } - - public static class SetExceptionBreakpointsArguments extends Arguments { - public String[] filters = new String[0]; - } - - public static class ThreadsArguments extends Arguments { - - } - - public static class ContinueArguments extends Arguments { - public long threadId; - } - - public static class NextArguments extends Arguments { - public long threadId; - } - - public static class StepInArguments extends Arguments { - public long threadId; - public int targetId; - } - - public static class StepOutArguments extends Arguments { - public long threadId; - } - - public static class PauseArguments extends Arguments { - public long threadId; - } - - public static class ScopesArguments extends Arguments { - public int frameId; - } - - public static class VariablesArguments extends Arguments { - public int variablesReference = -1; - public String filter; - public int start; - public int count; - public ValueFormat format; - } - - public static class SetVariableArguments extends Arguments { - public int variablesReference; - public String name; - public String value; - public ValueFormat format; - } - - public static class SourceArguments extends Arguments { - public int sourceReference; - } - - public static class EvaluateArguments extends Arguments { - public String expression; - public int frameId; - public String context; - public ValueFormat format; - } - - public static enum Command { - INITIALIZE("initialize", InitializeArguments.class), - LAUNCH("launch", LaunchArguments.class), - ATTACH("attach", AttachArguments.class), - DISCONNECT("disconnect", DisconnectArguments.class), - CONFIGURATIONDONE("configurationDone", ConfigurationDoneArguments.class), - NEXT("next", NextArguments.class), - CONTINUE("continue", ContinueArguments.class), - STEPIN("stepIn", StepInArguments.class), - STEPOUT("stepOut", StepOutArguments.class), - PAUSE("pause", PauseArguments.class), - STACKTRACE("stackTrace", StackTraceArguments.class), - SCOPES("scopes", ScopesArguments.class), - VARIABLES("variables", VariablesArguments.class), - SETVARIABLE("setVariable", SetVariableArguments.class), - SOURCE("source", SourceArguments.class), - THREADS("threads", ThreadsArguments.class), - SETBREAKPOINTS("setBreakpoints", SetBreakpointArguments.class), - SETEXCEPTIONBREAKPOINTS("setExceptionBreakpoints", SetExceptionBreakpointsArguments.class), - SETFUNCTIONBREAKPOINTS("setFunctionBreakpoints", SetFunctionBreakpointsArguments.class), - EVALUATE("evaluate", EvaluateArguments.class), - UNSUPPORTED("", Arguments.class); - - private String command; - private Class argumentType; - - Command(String command, Class argumentType) { - this.command = command; - this.argumentType = argumentType; - } - - public String toString() { - return this.command; - } - - public Class getArgumentType() { - return this.argumentType; - } - - /** - * Get the corresponding Command type by the command name. - * If the command is not defined in the enum type, return UNSUPPORTED. - * @param command - * the command name - * @return the Command type - */ - public static Command parse(String command) { - Command[] found = Arrays.stream(Command.values()).filter(cmd -> { - return cmd.toString().equals(command); - }).toArray(Command[]::new); - - if (found.length > 0) { - return found[0]; - } - return UNSUPPORTED; - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.util.Arrays; + +/** + * The request arguments types defined by VSCode Debug Protocol. + */ +public class Requests { + + public static class ValueFormat { + public boolean hex; + } + + public static class Arguments { + + } + + public static class InitializeArguments extends Arguments { + public String clientID; + public String adapterID; + public String pathFormat; + public boolean linesStartAt1; + public boolean columnsStartAt1; + public boolean supportsVariableType; + public boolean supportsVariablePaging; + public boolean supportsRunInTerminalRequest; + } + + public static class LaunchArguments extends Arguments { + public String type; + public String name; + public String request; + public String projectName; + public String mainClass; + public String args = ""; + public String vmArgs = ""; + public String[] classPaths = new String[0]; + public String[] sourcePaths = new String[0]; + } + + public static class AttachArguments extends Arguments { + public String type; + public String name; + public String request; + public String hostName; + public int port; + public int timeout = 30000; // Default to 30s. + public String[] sourcePaths = new String[0]; + public String projectName; + } + + public static class RestartArguments extends Arguments { + + } + + public static class DisconnectArguments extends Arguments { + // If client doesn't set terminateDebuggee attribute at the DisconnectRequest, + // the debugger would choose to terminate debuggee by default. + public boolean terminateDebuggee = true; + public boolean restart; + } + + public static class ConfigurationDoneArguments extends Arguments { + + } + + public static class SetBreakpointArguments extends Arguments { + public Types.Source source; + public int[] lines = new int[0]; + public Types.SourceBreakpoint[] breakpoints = new Types.SourceBreakpoint[0]; + public boolean sourceModified = false; + } + + public static class StackTraceArguments extends Arguments { + public long threadId; + public int startFrame; + public int levels; + } + + public static class SetFunctionBreakpointsArguments extends Arguments { + public Types.FunctionBreakpoint[] breakpoints; + } + + public static class SetExceptionBreakpointsArguments extends Arguments { + public String[] filters = new String[0]; + } + + public static class ThreadsArguments extends Arguments { + + } + + public static class ContinueArguments extends Arguments { + public long threadId; + } + + public static class NextArguments extends Arguments { + public long threadId; + } + + public static class StepInArguments extends Arguments { + public long threadId; + public int targetId; + } + + public static class StepOutArguments extends Arguments { + public long threadId; + } + + public static class PauseArguments extends Arguments { + public long threadId; + } + + public static class ScopesArguments extends Arguments { + public int frameId; + } + + public static class VariablesArguments extends Arguments { + public int variablesReference = -1; + public String filter; + public int start; + public int count; + public ValueFormat format; + } + + public static class SetVariableArguments extends Arguments { + public int variablesReference; + public String name; + public String value; + public ValueFormat format; + } + + public static class SourceArguments extends Arguments { + public int sourceReference; + } + + public static class EvaluateArguments extends Arguments { + public String expression; + public int frameId; + public String context; + public ValueFormat format; + } + + public static enum Command { + INITIALIZE("initialize", InitializeArguments.class), + LAUNCH("launch", LaunchArguments.class), + ATTACH("attach", AttachArguments.class), + DISCONNECT("disconnect", DisconnectArguments.class), + CONFIGURATIONDONE("configurationDone", ConfigurationDoneArguments.class), + NEXT("next", NextArguments.class), + CONTINUE("continue", ContinueArguments.class), + STEPIN("stepIn", StepInArguments.class), + STEPOUT("stepOut", StepOutArguments.class), + PAUSE("pause", PauseArguments.class), + STACKTRACE("stackTrace", StackTraceArguments.class), + SCOPES("scopes", ScopesArguments.class), + VARIABLES("variables", VariablesArguments.class), + SETVARIABLE("setVariable", SetVariableArguments.class), + SOURCE("source", SourceArguments.class), + THREADS("threads", ThreadsArguments.class), + SETBREAKPOINTS("setBreakpoints", SetBreakpointArguments.class), + SETEXCEPTIONBREAKPOINTS("setExceptionBreakpoints", SetExceptionBreakpointsArguments.class), + SETFUNCTIONBREAKPOINTS("setFunctionBreakpoints", SetFunctionBreakpointsArguments.class), + EVALUATE("evaluate", EvaluateArguments.class), + UNSUPPORTED("", Arguments.class); + + private String command; + private Class argumentType; + + Command(String command, Class argumentType) { + this.command = command; + this.argumentType = argumentType; + } + + public String toString() { + return this.command; + } + + public Class getArgumentType() { + return this.argumentType; + } + + /** + * Get the corresponding Command type by the command name. + * If the command is not defined in the enum type, return UNSUPPORTED. + * @param command + * the command name + * @return the Command type + */ + public static Command parse(String command) { + Command[] found = Arrays.stream(Command.values()).filter(cmd -> { + return cmd.toString().equals(command); + }).toArray(Command[]::new); + + if (found.length > 0) { + return found[0]; + } + return UNSUPPORTED; + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/Responses.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Responses.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/Responses.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Responses.java diff --git a/org/eclipse/jdt/ls/debug/adapter/Types.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Types.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/Types.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Types.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java index 3f3e73607..43e5858e5 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java @@ -1,70 +1,70 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.eclipse.jdt.ls.debug.DebugUtility; -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.Constants; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.IVirtualMachineManagerProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.AttachArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.internal.Logger; - -import com.sun.jdi.connect.IllegalConnectorArgumentsException; - -public class AttachRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.ATTACH); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - AttachArguments attachArguments = (AttachArguments) arguments; - context.setAttached(true); - context.setSourcePaths(attachArguments.sourcePaths); - - IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class); - ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); - if (attachArguments.projectName != null) { - Map options = sourceProvider.getDefaultOptions(); - options.put(Constants.PROJECTNAME, attachArguments.projectName); - sourceProvider.initialize(options); - } - - try { - Logger.logInfo(String.format("Trying to attach to remote debuggee VM %s:%d .", - attachArguments.hostName, attachArguments.port)); - IDebugSession debugSession = DebugUtility.attach(vmProvider.getVirtualMachineManager(), - attachArguments.hostName, attachArguments.port, attachArguments.timeout); - context.setDebugSession(debugSession); - Logger.logInfo("Attaching to debuggee VM succeeded."); - } catch (IOException | IllegalConnectorArgumentsException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.ATTACH_FAILURE, - String.format("Failed to attach to remote debuggee VM. Reason: %s", e.toString())); - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.eclipse.jdt.ls.debug.DebugUtility; +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.Constants; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.IVirtualMachineManagerProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.AttachArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.internal.Logger; + +import com.sun.jdi.connect.IllegalConnectorArgumentsException; + +public class AttachRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.ATTACH); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + AttachArguments attachArguments = (AttachArguments) arguments; + context.setAttached(true); + context.setSourcePaths(attachArguments.sourcePaths); + + IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class); + ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); + if (attachArguments.projectName != null) { + Map options = sourceProvider.getDefaultOptions(); + options.put(Constants.PROJECTNAME, attachArguments.projectName); + sourceProvider.initialize(options); + } + + try { + Logger.logInfo(String.format("Trying to attach to remote debuggee VM %s:%d .", + attachArguments.hostName, attachArguments.port)); + IDebugSession debugSession = DebugUtility.attach(vmProvider.getVirtualMachineManager(), + attachArguments.hostName, attachArguments.port, attachArguments.timeout); + context.setDebugSession(debugSession); + Logger.logInfo("Attaching to debuggee VM succeeded."); + } catch (IOException | IllegalConnectorArgumentsException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.ATTACH_FAILURE, + String.format("Failed to attach to remote debuggee VM. Reason: %s", e.toString())); + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java index 9473e17e6..e19e54c5b 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java @@ -1,98 +1,98 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.DebugEvent; -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.Events; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; - -import com.sun.jdi.ThreadReference; -import com.sun.jdi.event.BreakpointEvent; -import com.sun.jdi.event.Event; -import com.sun.jdi.event.ExceptionEvent; -import com.sun.jdi.event.StepEvent; -import com.sun.jdi.event.ThreadDeathEvent; -import com.sun.jdi.event.ThreadStartEvent; -import com.sun.jdi.event.VMDeathEvent; -import com.sun.jdi.event.VMDisconnectEvent; -import com.sun.jdi.event.VMStartEvent; - -public class ConfigurationDoneRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.CONFIGURATIONDONE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - IDebugSession debugSession = context.getDebugSession(); - if (debugSession != null) { - // This is a global event handler to handle the JDI Event from Virtual Machine. - debugSession.eventHub().events().subscribe(debugEvent -> { - handleDebugEvent(debugEvent, debugSession, context); - }); - // configuration is done, and start debug session. - debugSession.start(); - } else { - context.sendEventAsync(new Events.TerminatedEvent()); - AdapterUtils.setErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Failed to launch debug session, the debugger will exit."); - } - } - - private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession, IDebugAdapterContext context) { - Event event = debugEvent.event; - if (event instanceof VMStartEvent) { - // do nothing. - } else if (event instanceof VMDeathEvent) { - context.sendEventAsync(new Events.ExitedEvent(0)); - } else if (event instanceof VMDisconnectEvent) { - context.sendEventAsync(new Events.TerminatedEvent()); - // Terminate eventHub thread. - try { - debugSession.eventHub().close(); - } catch (Exception e) { - // do nothing. - } - } else if (event instanceof ThreadStartEvent) { - ThreadReference startThread = ((ThreadStartEvent) event).thread(); - Events.ThreadEvent threadEvent = new Events.ThreadEvent("started", startThread.uniqueID()); - context.sendEventAsync(threadEvent); - } else if (event instanceof ThreadDeathEvent) { - ThreadReference deathThread = ((ThreadDeathEvent) event).thread(); - Events.ThreadEvent threadDeathEvent = new Events.ThreadEvent("exited", deathThread.uniqueID()); - context.sendEventAsync(threadDeathEvent); - } else if (event instanceof BreakpointEvent) { - ThreadReference bpThread = ((BreakpointEvent) event).thread(); - context.sendEventAsync(new Events.StoppedEvent("breakpoint", bpThread.uniqueID())); - debugEvent.shouldResume = false; - } else if (event instanceof StepEvent) { - ThreadReference stepThread = ((StepEvent) event).thread(); - context.sendEventAsync(new Events.StoppedEvent("step", stepThread.uniqueID())); - debugEvent.shouldResume = false; - } else if (event instanceof ExceptionEvent) { - ThreadReference thread = ((ExceptionEvent) event).thread(); - context.sendEventAsync(new Events.StoppedEvent("exception", thread.uniqueID())); - debugEvent.shouldResume = false; - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.DebugEvent; +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.Events; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; + +import com.sun.jdi.ThreadReference; +import com.sun.jdi.event.BreakpointEvent; +import com.sun.jdi.event.Event; +import com.sun.jdi.event.ExceptionEvent; +import com.sun.jdi.event.StepEvent; +import com.sun.jdi.event.ThreadDeathEvent; +import com.sun.jdi.event.ThreadStartEvent; +import com.sun.jdi.event.VMDeathEvent; +import com.sun.jdi.event.VMDisconnectEvent; +import com.sun.jdi.event.VMStartEvent; + +public class ConfigurationDoneRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.CONFIGURATIONDONE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + IDebugSession debugSession = context.getDebugSession(); + if (debugSession != null) { + // This is a global event handler to handle the JDI Event from Virtual Machine. + debugSession.eventHub().events().subscribe(debugEvent -> { + handleDebugEvent(debugEvent, debugSession, context); + }); + // configuration is done, and start debug session. + debugSession.start(); + } else { + context.sendEventAsync(new Events.TerminatedEvent()); + AdapterUtils.setErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Failed to launch debug session, the debugger will exit."); + } + } + + private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession, IDebugAdapterContext context) { + Event event = debugEvent.event; + if (event instanceof VMStartEvent) { + // do nothing. + } else if (event instanceof VMDeathEvent) { + context.sendEventAsync(new Events.ExitedEvent(0)); + } else if (event instanceof VMDisconnectEvent) { + context.sendEventAsync(new Events.TerminatedEvent()); + // Terminate eventHub thread. + try { + debugSession.eventHub().close(); + } catch (Exception e) { + // do nothing. + } + } else if (event instanceof ThreadStartEvent) { + ThreadReference startThread = ((ThreadStartEvent) event).thread(); + Events.ThreadEvent threadEvent = new Events.ThreadEvent("started", startThread.uniqueID()); + context.sendEventAsync(threadEvent); + } else if (event instanceof ThreadDeathEvent) { + ThreadReference deathThread = ((ThreadDeathEvent) event).thread(); + Events.ThreadEvent threadDeathEvent = new Events.ThreadEvent("exited", deathThread.uniqueID()); + context.sendEventAsync(threadDeathEvent); + } else if (event instanceof BreakpointEvent) { + ThreadReference bpThread = ((BreakpointEvent) event).thread(); + context.sendEventAsync(new Events.StoppedEvent("breakpoint", bpThread.uniqueID())); + debugEvent.shouldResume = false; + } else if (event instanceof StepEvent) { + ThreadReference stepThread = ((StepEvent) event).thread(); + context.sendEventAsync(new Events.StoppedEvent("step", stepThread.uniqueID())); + debugEvent.shouldResume = false; + } else if (event instanceof ExceptionEvent) { + ThreadReference thread = ((ExceptionEvent) event).thread(); + context.sendEventAsync(new Events.StoppedEvent("exception", thread.uniqueID())); + debugEvent.shouldResume = false; + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java index 26caf9c29..edb264b22 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java @@ -1,45 +1,45 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.DisconnectArguments; - -public class DisconnectRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.DISCONNECT); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - DisconnectArguments disconnectArguments = (DisconnectArguments) arguments; - IDebugSession debugSession = context.getDebugSession(); - if (debugSession != null) { - if (disconnectArguments.terminateDebuggee && !context.isAttached()) { - debugSession.terminate(); - } else { - debugSession.detach(); - } - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.DisconnectArguments; + +public class DisconnectRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.DISCONNECT); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + DisconnectArguments disconnectArguments = (DisconnectArguments) arguments; + IDebugSession debugSession = context.getDebugSession(); + if (debugSession != null) { + if (disconnectArguments.terminateDebuggee && !context.isAttached()) { + debugSession.terminate(); + } else { + debugSession.detach(); + } + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java index 55c315817..703f3329f 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java @@ -1,188 +1,188 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.EvaluateArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; -import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.Variable; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.ArrayReference; -import com.sun.jdi.Field; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.PrimitiveValue; -import com.sun.jdi.StackFrame; -import com.sun.jdi.ThreadReference; -import com.sun.jdi.Value; - -public class EvaluateRequestHandler implements IDebugRequestHandler { - private final Pattern simpleExprPattern = Pattern.compile("[A-Za-z0-9_.\\s]+"); - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.EVALUATE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - EvaluateArguments evalArguments = (EvaluateArguments) arguments; - if (StringUtils.isBlank(evalArguments.expression)) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "EvaluateRequest: property 'expression' is missing, null, or empty"); - return; - } - - // This should be false by default(currently true for test). - // User will need to explicitly turn it on by configuring launch.json - final boolean showStaticVariables = true; - // TODO: when vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. - boolean showFullyQualifiedNames = true; - Map options = context.getVariableFormatter().getDefaultOptions(); - if (evalArguments.format != null && evalArguments.format.hex) { - options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); - } - if (showFullyQualifiedNames) { - options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); - } - String expression = evalArguments.expression; - - if (StringUtils.isBlank(expression)) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Empty expression cannot be evaluated."); - return; - } - - if (!simpleExprPattern.matcher(expression).matches()) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - "Failed to evaluate. Reason: Complex expression is not supported currently."); - return; - } - - JdiObjectProxy stackFrameProxy = (JdiObjectProxy) context.getRecyclableIdPool().getObjectById(evalArguments.frameId); - if (stackFrameProxy == null) { - // stackFrameProxy is null means the stackframe is continued by user manually, - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Cannot evaluate because the thread is resumed."); - return; - } - - // split a.b.c => ["a", "b", "c"] - List referenceExpressions = Arrays.stream(StringUtils.split(expression, '.')) - .filter(StringUtils::isNotBlank).map(StringUtils::trim).collect(Collectors.toList()); - - // get first level of value from stack frame - Variable firstLevelValue = null; - boolean inStaticMethod = stackFrameProxy.getProxiedObject().location().method().isStatic(); - String firstExpression = referenceExpressions.get(0); - // handle special case of 'this' - if (firstExpression.equals("this") && !inStaticMethod) { - firstLevelValue = VariableUtils.getThisVariable(stackFrameProxy.getProxiedObject()); - } - if (firstLevelValue == null) { - try { - // local variables first, that means - // if both local variable and static variable are found, use local variable - List localVariables = VariableUtils.listLocalVariables(stackFrameProxy.getProxiedObject()); - List matchedLocal = localVariables.stream() - .filter(localVariable -> localVariable.name.equals(firstExpression)).collect(Collectors.toList()); - if (!matchedLocal.isEmpty()) { - firstLevelValue = matchedLocal.get(0); - } else { - List staticVariables = VariableUtils.listStaticVariables(stackFrameProxy.getProxiedObject()); - List matchedStatic = staticVariables.stream() - .filter(staticVariable -> staticVariable.name.equals(firstExpression)).collect(Collectors.toList()); - if (matchedStatic.isEmpty()) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find the variable: %s.", referenceExpressions.get(0))); - return; - } - firstLevelValue = matchedStatic.get(0); - } - - } catch (AbsentInformationException e) { - // ignore - } - } - - if (firstLevelValue == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find variable with name '%s'.", referenceExpressions.get(0))); - return; - } - ThreadReference thread = stackFrameProxy.getProxiedObject().thread(); - Value currentValue = firstLevelValue.value; - - for (int i = 1; i < referenceExpressions.size(); i++) { - String fieldName = referenceExpressions.get(i); - if (currentValue == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Evaluation encounters NPE error."); - return; - } - if (currentValue instanceof PrimitiveValue) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); - return; - } - if (currentValue instanceof ArrayReference) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Evaluating array elements is not supported currently.", fieldName)); - return; - } - ObjectReference obj = (ObjectReference) currentValue; - Field field = obj.referenceType().fieldByName(fieldName); - if (field == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); - return; - } - if (field.isStatic()) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); - return; - } - currentValue = obj.getValue(field); - } - - int referenceId = 0; - if (currentValue instanceof ObjectReference && VariableUtils.hasChildren(currentValue, showStaticVariables)) { - // save the evaluated value in object pool, because like java.lang.String, the evaluated object will have sub structures - // we need to set up the id map. - VariableProxy varProxy = new VariableProxy(thread.uniqueID(), "Local", (ObjectReference) currentValue); - referenceId = context.getRecyclableIdPool().addObject(thread.uniqueID(), varProxy); - } - int indexedVariables = 0; - if (currentValue instanceof ArrayReference) { - indexedVariables = ((ArrayReference) currentValue).length(); - } - response.body = new Responses.EvaluateResponseBody(context.getVariableFormatter().valueToString(currentValue, options), - referenceId, context.getVariableFormatter().typeToString(currentValue == null ? null : currentValue.type(), options), - indexedVariables); - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.EvaluateArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; +import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.Variable; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.ArrayReference; +import com.sun.jdi.Field; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.PrimitiveValue; +import com.sun.jdi.StackFrame; +import com.sun.jdi.ThreadReference; +import com.sun.jdi.Value; + +public class EvaluateRequestHandler implements IDebugRequestHandler { + private final Pattern simpleExprPattern = Pattern.compile("[A-Za-z0-9_.\\s]+"); + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.EVALUATE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + EvaluateArguments evalArguments = (EvaluateArguments) arguments; + if (StringUtils.isBlank(evalArguments.expression)) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + "EvaluateRequest: property 'expression' is missing, null, or empty"); + return; + } + + // This should be false by default(currently true for test). + // User will need to explicitly turn it on by configuring launch.json + final boolean showStaticVariables = true; + // TODO: when vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. + boolean showFullyQualifiedNames = true; + Map options = context.getVariableFormatter().getDefaultOptions(); + if (evalArguments.format != null && evalArguments.format.hex) { + options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); + } + if (showFullyQualifiedNames) { + options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); + } + String expression = evalArguments.expression; + + if (StringUtils.isBlank(expression)) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Empty expression cannot be evaluated."); + return; + } + + if (!simpleExprPattern.matcher(expression).matches()) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + "Failed to evaluate. Reason: Complex expression is not supported currently."); + return; + } + + JdiObjectProxy stackFrameProxy = (JdiObjectProxy) context.getRecyclableIdPool().getObjectById(evalArguments.frameId); + if (stackFrameProxy == null) { + // stackFrameProxy is null means the stackframe is continued by user manually, + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Cannot evaluate because the thread is resumed."); + return; + } + + // split a.b.c => ["a", "b", "c"] + List referenceExpressions = Arrays.stream(StringUtils.split(expression, '.')) + .filter(StringUtils::isNotBlank).map(StringUtils::trim).collect(Collectors.toList()); + + // get first level of value from stack frame + Variable firstLevelValue = null; + boolean inStaticMethod = stackFrameProxy.getProxiedObject().location().method().isStatic(); + String firstExpression = referenceExpressions.get(0); + // handle special case of 'this' + if (firstExpression.equals("this") && !inStaticMethod) { + firstLevelValue = VariableUtils.getThisVariable(stackFrameProxy.getProxiedObject()); + } + if (firstLevelValue == null) { + try { + // local variables first, that means + // if both local variable and static variable are found, use local variable + List localVariables = VariableUtils.listLocalVariables(stackFrameProxy.getProxiedObject()); + List matchedLocal = localVariables.stream() + .filter(localVariable -> localVariable.name.equals(firstExpression)).collect(Collectors.toList()); + if (!matchedLocal.isEmpty()) { + firstLevelValue = matchedLocal.get(0); + } else { + List staticVariables = VariableUtils.listStaticVariables(stackFrameProxy.getProxiedObject()); + List matchedStatic = staticVariables.stream() + .filter(staticVariable -> staticVariable.name.equals(firstExpression)).collect(Collectors.toList()); + if (matchedStatic.isEmpty()) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find the variable: %s.", referenceExpressions.get(0))); + return; + } + firstLevelValue = matchedStatic.get(0); + } + + } catch (AbsentInformationException e) { + // ignore + } + } + + if (firstLevelValue == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find variable with name '%s'.", referenceExpressions.get(0))); + return; + } + ThreadReference thread = stackFrameProxy.getProxiedObject().thread(); + Value currentValue = firstLevelValue.value; + + for (int i = 1; i < referenceExpressions.size(); i++) { + String fieldName = referenceExpressions.get(i); + if (currentValue == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Evaluation encounters NPE error."); + return; + } + if (currentValue instanceof PrimitiveValue) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); + return; + } + if (currentValue instanceof ArrayReference) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Evaluating array elements is not supported currently.", fieldName)); + return; + } + ObjectReference obj = (ObjectReference) currentValue; + Field field = obj.referenceType().fieldByName(fieldName); + if (field == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); + return; + } + if (field.isStatic()) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); + return; + } + currentValue = obj.getValue(field); + } + + int referenceId = 0; + if (currentValue instanceof ObjectReference && VariableUtils.hasChildren(currentValue, showStaticVariables)) { + // save the evaluated value in object pool, because like java.lang.String, the evaluated object will have sub structures + // we need to set up the id map. + VariableProxy varProxy = new VariableProxy(thread.uniqueID(), "Local", (ObjectReference) currentValue); + referenceId = context.getRecyclableIdPool().addObject(thread.uniqueID(), varProxy); + } + int indexedVariables = 0; + if (currentValue instanceof ArrayReference) { + indexedVariables = ((ArrayReference) currentValue).length(); + } + response.body = new Responses.EvaluateResponseBody(context.getVariableFormatter().valueToString(currentValue, options), + referenceId, context.getVariableFormatter().typeToString(currentValue == null ? null : currentValue.type(), options), + indexedVariables); + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java index 62236e843..3b3eb31f3 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java @@ -1,96 +1,96 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.ls.debug.DebugUtility; -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.Constants; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.Events; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.IVirtualMachineManagerProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.ProcessConsole; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.LaunchArguments; -import org.eclipse.jdt.ls.debug.internal.Logger; - -import com.sun.jdi.connect.IllegalConnectorArgumentsException; -import com.sun.jdi.connect.VMStartException; - -public class LaunchRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.LAUNCH); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - LaunchArguments launchArguments = (LaunchArguments) arguments; - if (StringUtils.isBlank(launchArguments.mainClass) || launchArguments.classPaths == null - || launchArguments.classPaths.length == 0) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - String.format("Failed to launch debuggee VM. Missing mainClass or classPath options in launch configuration")); - return; - } - - context.setAttached(false); - context.setSourcePaths(launchArguments.sourcePaths); - // TODO Currently the debuggee console just supports UTF-8 format. - // In future, we could let user to specify the debuggee encoding in launch.json. - context.setDebuggeeEncoding(StandardCharsets.UTF_8); - - IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class); - ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); - if (launchArguments.projectName != null) { - Map options = sourceProvider.getDefaultOptions(); - options.put(Constants.PROJECTNAME, launchArguments.projectName); - sourceProvider.initialize(options); - } - - try { - Logger.logInfo(String.format("Trying to launch Java Program with options \"%s -cp %s %s %s\" .", - launchArguments.vmArgs, launchArguments.classPaths, launchArguments.mainClass, launchArguments.args)); - IDebugSession debugSession = DebugUtility.launch(vmProvider.getVirtualMachineManager(), - launchArguments.mainClass, launchArguments.args, launchArguments.vmArgs, Arrays.asList(launchArguments.classPaths)); - context.setDebugSession(debugSession); - Logger.logInfo("Launching debuggee VM succeeded."); - - ProcessConsole debuggeeConsole = new ProcessConsole(debugSession.process(), "Debuggee", context.getDebuggeeEncoding()); - debuggeeConsole.onStdout((output) -> { - // When DA receives a new OutputEvent, it just shows that on Debug Console and doesn't affect the DA's dispatching workflow. - // That means the debugger can send OutputEvent to DA at any time. - context.sendEvent(Events.OutputEvent.createStdoutOutput(output)); - }); - - debuggeeConsole.onStderr((err) -> { - context.sendEvent(Events.OutputEvent.createStderrOutput(err)); - }); - debuggeeConsole.start(); - } catch (IOException | IllegalConnectorArgumentsException | VMStartException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.LAUNCH_FAILURE, - String.format("Failed to launch debuggee VM. Reason: %s", e.toString())); - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.ls.debug.DebugUtility; +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.Constants; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.Events; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.IVirtualMachineManagerProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.ProcessConsole; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.LaunchArguments; +import org.eclipse.jdt.ls.debug.internal.Logger; + +import com.sun.jdi.connect.IllegalConnectorArgumentsException; +import com.sun.jdi.connect.VMStartException; + +public class LaunchRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.LAUNCH); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + LaunchArguments launchArguments = (LaunchArguments) arguments; + if (StringUtils.isBlank(launchArguments.mainClass) || launchArguments.classPaths == null + || launchArguments.classPaths.length == 0) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + String.format("Failed to launch debuggee VM. Missing mainClass or classPath options in launch configuration")); + return; + } + + context.setAttached(false); + context.setSourcePaths(launchArguments.sourcePaths); + // TODO Currently the debuggee console just supports UTF-8 format. + // In future, we could let user to specify the debuggee encoding in launch.json. + context.setDebuggeeEncoding(StandardCharsets.UTF_8); + + IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class); + ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); + if (launchArguments.projectName != null) { + Map options = sourceProvider.getDefaultOptions(); + options.put(Constants.PROJECTNAME, launchArguments.projectName); + sourceProvider.initialize(options); + } + + try { + Logger.logInfo(String.format("Trying to launch Java Program with options \"%s -cp %s %s %s\" .", + launchArguments.vmArgs, launchArguments.classPaths, launchArguments.mainClass, launchArguments.args)); + IDebugSession debugSession = DebugUtility.launch(vmProvider.getVirtualMachineManager(), + launchArguments.mainClass, launchArguments.args, launchArguments.vmArgs, Arrays.asList(launchArguments.classPaths)); + context.setDebugSession(debugSession); + Logger.logInfo("Launching debuggee VM succeeded."); + + ProcessConsole debuggeeConsole = new ProcessConsole(debugSession.process(), "Debuggee", context.getDebuggeeEncoding()); + debuggeeConsole.onStdout((output) -> { + // When DA receives a new OutputEvent, it just shows that on Debug Console and doesn't affect the DA's dispatching workflow. + // That means the debugger can send OutputEvent to DA at any time. + context.sendEvent(Events.OutputEvent.createStdoutOutput(output)); + }); + + debuggeeConsole.onStderr((err) -> { + context.sendEvent(Events.OutputEvent.createStderrOutput(err)); + }); + debuggeeConsole.start(); + } catch (IOException | IllegalConnectorArgumentsException | VMStartException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.LAUNCH_FAILURE, + String.format("Failed to launch debuggee VM. Reason: %s", e.toString())); + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java index 90acf56a5..2590d35c2 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java @@ -1,55 +1,55 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.ScopesArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; -import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; - -import com.sun.jdi.StackFrame; - -public class ScopesRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SCOPES); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - ScopesArguments scopesArgs = (ScopesArguments) arguments; - List scopes = new ArrayList<>(); - JdiObjectProxy stackFrameProxy = (JdiObjectProxy) context.getRecyclableIdPool().getObjectById(scopesArgs.frameId); - if (stackFrameProxy == null) { - response.body = new Responses.ScopesResponseBody(scopes); - return; - } - StackFrame stackFrame = stackFrameProxy.getProxiedObject(); - VariableProxy localScope = new VariableProxy(stackFrame.thread().uniqueID(), "Local", stackFrame); - int localScopeId = context.getRecyclableIdPool().addObject(stackFrame.thread().uniqueID(), localScope); - scopes.add(new Types.Scope(localScope.getScope(), localScopeId, false)); - - response.body = new Responses.ScopesResponseBody(scopes); - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.ScopesArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; +import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; + +import com.sun.jdi.StackFrame; + +public class ScopesRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SCOPES); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + ScopesArguments scopesArgs = (ScopesArguments) arguments; + List scopes = new ArrayList<>(); + JdiObjectProxy stackFrameProxy = (JdiObjectProxy) context.getRecyclableIdPool().getObjectById(scopesArgs.frameId); + if (stackFrameProxy == null) { + response.body = new Responses.ScopesResponseBody(scopes); + return; + } + StackFrame stackFrame = stackFrameProxy.getProxiedObject(); + VariableProxy localScope = new VariableProxy(stackFrame.thread().uniqueID(), "Local", stackFrame); + int localScopeId = context.getRecyclableIdPool().addObject(stackFrame.thread().uniqueID(), localScope); + scopes.add(new Types.Scope(localScope.getScope(), localScopeId, false)); + + response.body = new Responses.ScopesResponseBody(scopes); + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java index 0dfde1d2f..1c0e56c26 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java @@ -1,126 +1,126 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.ls.debug.DebugException; -import org.eclipse.jdt.ls.debug.IBreakpoint; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.BreakpointManager; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.Events; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.SetBreakpointArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; - -public class SetBreakpointsRequestHandler implements IDebugRequestHandler { - private BreakpointManager manager = new BreakpointManager(); - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SETBREAKPOINTS); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - SetBreakpointArguments bpArguments = (SetBreakpointArguments) arguments; - String clientPath = bpArguments.source.path; - if (AdapterUtils.isWindows()) { - // VSCode may send drive letters with inconsistent casing which will mess up the key - // in the BreakpointManager. See https://github.com/Microsoft/vscode/issues/6268 - // Normalize the drive letter casing. Note that drive letters - // are not localized so invariant is safe here. - String drivePrefix = FilenameUtils.getPrefix(clientPath); - if (drivePrefix != null && drivePrefix.length() >= 2 - && Character.isLowerCase(drivePrefix.charAt(0)) && drivePrefix.charAt(1) == ':') { - drivePrefix = drivePrefix.substring(0, 2); // d:\ is an illegal regex string, convert it to d: - clientPath = clientPath.replaceFirst(drivePrefix, drivePrefix.toUpperCase()); - } - } - String sourcePath = clientPath; - if (bpArguments.source.sourceReference != 0 && context.getSourceUri(bpArguments.source.sourceReference) != null) { - sourcePath = context.getSourceUri(bpArguments.source.sourceReference); - } else { - sourcePath = AdapterUtils.convertPath(clientPath, context.isClientPathsAreUri(), context.isDebuggerPathsAreUri()); - } - - // When breakpoint source path is null or an invalid file path, send an ErrorResponse back. - if (sourcePath == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE, - String.format("Failed to setBreakpoint. Reason: '%s' is an invalid path.", bpArguments.source.path)); - return; - } - try { - List res = new ArrayList<>(); - IBreakpoint[] toAdds = this.convertClientBreakpointsToDebugger(sourcePath, bpArguments.breakpoints, context); - IBreakpoint[] added = manager.setBreakpoints(sourcePath, toAdds, bpArguments.sourceModified); - for (int i = 0; i < bpArguments.breakpoints.length; i++) { - // For newly added breakpoint, should install it to debuggee first. - if (toAdds[i] == added[i] && added[i].className() != null) { - added[i].install().thenAccept(bp -> { - Events.BreakpointEvent bpEvent = new Events.BreakpointEvent("new", this.convertDebuggerBreakpointToClient(bp, context)); - context.sendEventAsync(bpEvent); - }); - } else if (toAdds[i].hitCount() != added[i].hitCount() && added[i].className() != null) { - // Update hitCount condition. - added[i].setHitCount(toAdds[i].hitCount()); - } - res.add(this.convertDebuggerBreakpointToClient(added[i], context)); - } - response.body = new Responses.SetBreakpointsResponseBody(res); - } catch (DebugException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE, String.format("Failed to setBreakpoint. Reason: '%s'", e.toString())); - } - } - - private Types.Breakpoint convertDebuggerBreakpointToClient(IBreakpoint breakpoint, IDebugAdapterContext context) { - int id = (int) breakpoint.getProperty("id"); - boolean verified = breakpoint.getProperty("verified") != null && (boolean) breakpoint.getProperty("verified"); - int lineNumber = AdapterUtils.convertLineNumber(breakpoint.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1()); - return new Types.Breakpoint(id, verified, lineNumber, ""); - } - - private IBreakpoint[] convertClientBreakpointsToDebugger(String sourceFile, Types.SourceBreakpoint[] sourceBreakpoints, IDebugAdapterContext context) - throws DebugException { - int[] lines = Arrays.asList(sourceBreakpoints).stream().map(sourceBreakpoint -> { - return AdapterUtils.convertLineNumber(sourceBreakpoint.line, context.isClientLinesStartAt1(), context.isDebuggerLinesStartAt1()); - }).mapToInt(line -> line).toArray(); - ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); - String[] fqns = sourceProvider.getFullyQualifiedName(sourceFile, lines, null); - IBreakpoint[] breakpoints = new IBreakpoint[lines.length]; - for (int i = 0; i < lines.length; i++) { - int hitCount = 0; - try { - hitCount = Integer.parseInt(sourceBreakpoints[i].hitCondition); - } catch (NumberFormatException e) { - hitCount = 0; // If hitCount is an illegal number, ignore hitCount condition. - } - breakpoints[i] = context.getDebugSession().createBreakpoint(fqns[i], lines[i], hitCount); - if (sourceProvider.supportsRealtimeBreakpointVerification() && StringUtils.isNotBlank(fqns[i])) { - breakpoints[i].putProperty("verified", true); - } - } - return breakpoints; - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.ls.debug.DebugException; +import org.eclipse.jdt.ls.debug.IBreakpoint; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.BreakpointManager; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.Events; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.SetBreakpointArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; + +public class SetBreakpointsRequestHandler implements IDebugRequestHandler { + private BreakpointManager manager = new BreakpointManager(); + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SETBREAKPOINTS); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + SetBreakpointArguments bpArguments = (SetBreakpointArguments) arguments; + String clientPath = bpArguments.source.path; + if (AdapterUtils.isWindows()) { + // VSCode may send drive letters with inconsistent casing which will mess up the key + // in the BreakpointManager. See https://github.com/Microsoft/vscode/issues/6268 + // Normalize the drive letter casing. Note that drive letters + // are not localized so invariant is safe here. + String drivePrefix = FilenameUtils.getPrefix(clientPath); + if (drivePrefix != null && drivePrefix.length() >= 2 + && Character.isLowerCase(drivePrefix.charAt(0)) && drivePrefix.charAt(1) == ':') { + drivePrefix = drivePrefix.substring(0, 2); // d:\ is an illegal regex string, convert it to d: + clientPath = clientPath.replaceFirst(drivePrefix, drivePrefix.toUpperCase()); + } + } + String sourcePath = clientPath; + if (bpArguments.source.sourceReference != 0 && context.getSourceUri(bpArguments.source.sourceReference) != null) { + sourcePath = context.getSourceUri(bpArguments.source.sourceReference); + } else { + sourcePath = AdapterUtils.convertPath(clientPath, context.isClientPathsAreUri(), context.isDebuggerPathsAreUri()); + } + + // When breakpoint source path is null or an invalid file path, send an ErrorResponse back. + if (sourcePath == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE, + String.format("Failed to setBreakpoint. Reason: '%s' is an invalid path.", bpArguments.source.path)); + return; + } + try { + List res = new ArrayList<>(); + IBreakpoint[] toAdds = this.convertClientBreakpointsToDebugger(sourcePath, bpArguments.breakpoints, context); + IBreakpoint[] added = manager.setBreakpoints(sourcePath, toAdds, bpArguments.sourceModified); + for (int i = 0; i < bpArguments.breakpoints.length; i++) { + // For newly added breakpoint, should install it to debuggee first. + if (toAdds[i] == added[i] && added[i].className() != null) { + added[i].install().thenAccept(bp -> { + Events.BreakpointEvent bpEvent = new Events.BreakpointEvent("new", this.convertDebuggerBreakpointToClient(bp, context)); + context.sendEventAsync(bpEvent); + }); + } else if (toAdds[i].hitCount() != added[i].hitCount() && added[i].className() != null) { + // Update hitCount condition. + added[i].setHitCount(toAdds[i].hitCount()); + } + res.add(this.convertDebuggerBreakpointToClient(added[i], context)); + } + response.body = new Responses.SetBreakpointsResponseBody(res); + } catch (DebugException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE, String.format("Failed to setBreakpoint. Reason: '%s'", e.toString())); + } + } + + private Types.Breakpoint convertDebuggerBreakpointToClient(IBreakpoint breakpoint, IDebugAdapterContext context) { + int id = (int) breakpoint.getProperty("id"); + boolean verified = breakpoint.getProperty("verified") != null && (boolean) breakpoint.getProperty("verified"); + int lineNumber = AdapterUtils.convertLineNumber(breakpoint.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1()); + return new Types.Breakpoint(id, verified, lineNumber, ""); + } + + private IBreakpoint[] convertClientBreakpointsToDebugger(String sourceFile, Types.SourceBreakpoint[] sourceBreakpoints, IDebugAdapterContext context) + throws DebugException { + int[] lines = Arrays.asList(sourceBreakpoints).stream().map(sourceBreakpoint -> { + return AdapterUtils.convertLineNumber(sourceBreakpoint.line, context.isClientLinesStartAt1(), context.isDebuggerLinesStartAt1()); + }).mapToInt(line -> line).toArray(); + ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); + String[] fqns = sourceProvider.getFullyQualifiedName(sourceFile, lines, null); + IBreakpoint[] breakpoints = new IBreakpoint[lines.length]; + for (int i = 0; i < lines.length; i++) { + int hitCount = 0; + try { + hitCount = Integer.parseInt(sourceBreakpoints[i].hitCondition); + } catch (NumberFormatException e) { + hitCount = 0; // If hitCount is an illegal number, ignore hitCount condition. + } + breakpoints[i] = context.getDebugSession().createBreakpoint(fqns[i], lines[i], hitCount); + if (sourceProvider.supportsRealtimeBreakpointVerification() && StringUtils.isNotBlank(fqns[i])) { + breakpoints[i].putProperty("verified", true); + } + } + return breakpoints; + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java index a4b06b119..c3ef43f24 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java @@ -1,49 +1,49 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.lang3.ArrayUtils; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.SetExceptionBreakpointsArguments; -import org.eclipse.jdt.ls.debug.adapter.Types; - -public class SetExceptionBreakpointsRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SETEXCEPTIONBREAKPOINTS); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - String[] filters = ((SetExceptionBreakpointsArguments) arguments).filters; - try { - boolean notifyCaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.CAUGHT_EXCEPTION_FILTER_NAME); - boolean notifyUncaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.UNCAUGHT_EXCEPTION_FILTER_NAME); - - context.getDebugSession().setExceptionBreakpoints(notifyCaught, notifyUncaught); - } catch (Exception ex) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_EXCEPTIONBREAKPOINT_FAILURE, - String.format("Failed to setExceptionBreakpoints. Reason: '%s'", ex.toString())); - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.lang3.ArrayUtils; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.SetExceptionBreakpointsArguments; +import org.eclipse.jdt.ls.debug.adapter.Types; + +public class SetExceptionBreakpointsRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SETEXCEPTIONBREAKPOINTS); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + String[] filters = ((SetExceptionBreakpointsArguments) arguments).filters; + try { + boolean notifyCaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.CAUGHT_EXCEPTION_FILTER_NAME); + boolean notifyUncaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.UNCAUGHT_EXCEPTION_FILTER_NAME); + + context.getDebugSession().setExceptionBreakpoints(notifyCaught, notifyUncaught); + } catch (Exception ex) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_EXCEPTIONBREAKPOINT_FAILURE, + String.format("Failed to setExceptionBreakpoints. Reason: '%s'", ex.toString())); + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java index 70f3d0dc5..2693a51bf 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java @@ -1,264 +1,264 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.SetVariableArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; -import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.ArrayReference; -import com.sun.jdi.ArrayType; -import com.sun.jdi.ClassNotLoadedException; -import com.sun.jdi.ClassType; -import com.sun.jdi.Field; -import com.sun.jdi.InvalidTypeException; -import com.sun.jdi.LocalVariable; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.ReferenceType; -import com.sun.jdi.StackFrame; -import com.sun.jdi.Type; -import com.sun.jdi.TypeComponent; -import com.sun.jdi.Value; - -public class SetVariableRequestHandler implements IDebugRequestHandler { - private static final String PATTERN = "([a-zA-Z_0-9$]+)\\s*\\(([^)]+)\\)"; - private IDebugAdapterContext context = null; - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SETVARIABLE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - SetVariableArguments setVarArguments = (SetVariableArguments) arguments; - if (setVarArguments.value == null) { - // Just exit out of editing if we're given an empty expression. - return; - } else if (setVarArguments.variablesReference == -1) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "SetVariablesRequest: property 'variablesReference' is missing, null, or empty"); - return; - } else if (StringUtils.isBlank(setVarArguments.name)) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "SetVariablesRequest: property 'name' is missing, null, or empty"); - return; - } - - this.context = context; - Map options = context.getVariableFormatter().getDefaultOptions(); - // This should be false by default(currently true for test). - // User will need to explicitly turn it on by configuring launch.json - boolean showStaticVariables = true; - // TODO: when vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. - boolean showFullyQualifiedNames = true; - if (setVarArguments.format != null && setVarArguments.format.hex) { - options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); - } - if (showFullyQualifiedNames) { - options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); - } - - Object container = context.getRecyclableIdPool().getObjectById(setVarArguments.variablesReference); - // container is null means the stack frame is continued by user manually. - if (container == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, - "Failed to set variable. Reason: Cannot set value because the thread is resumed."); - return; - } - - String name = setVarArguments.name; - Value newValue; - String belongToClass = null; - - if (setVarArguments.name.contains("(")) { - name = setVarArguments.name.replaceFirst(PATTERN, "$1"); - belongToClass = setVarArguments.name.replaceFirst(PATTERN, "$2"); - } - - Object containerObj = ((VariableProxy) container).getProxiedVariable(); - try { - if (containerObj instanceof StackFrame) { - newValue = handleSetValueForStackFrame(name, belongToClass, setVarArguments.value, - showStaticVariables, (StackFrame) containerObj, options); - } else if (containerObj instanceof ObjectReference) { - newValue = handleSetValueForObject(name, belongToClass, setVarArguments.value, - (ObjectReference) containerObj, options); - } else { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, - String.format("SetVariableRequest: Variable %s cannot be found.", setVarArguments.variablesReference)); - return; - } - } catch (IllegalArgumentException | AbsentInformationException | InvalidTypeException - | UnsupportedOperationException | ClassNotLoadedException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, - String.format("Failed to set variable. Reason: %s", e.toString())); - return; - } - int referenceId = 0; - if (newValue instanceof ObjectReference && VariableUtils.hasChildren(newValue, showStaticVariables)) { - long threadId = ((VariableProxy) container).getThreadId(); - String scopeName = ((VariableProxy) container).getScope(); - VariableProxy varProxy = new VariableProxy(threadId, scopeName, (ObjectReference) newValue); - referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy); - } - - int indexedVariables = 0; - if (newValue instanceof ArrayReference) { - indexedVariables = ((ArrayReference) newValue).length(); - } - response.body = new Responses.SetVariablesResponseBody( - context.getVariableFormatter().typeToString(newValue == null ? null : newValue.type(), options), // type - context.getVariableFormatter().valueToString(newValue, options), // value, - referenceId, indexedVariables); - } - - private Value handleSetValueForObject(String name, String belongToClass, String valueString, - ObjectReference container, Map options) throws InvalidTypeException, ClassNotLoadedException { - Value newValue; - if (container instanceof ArrayReference) { - ArrayReference array = (ArrayReference) container; - Type eleType = ((ArrayType) array.referenceType()).componentType(); - newValue = setArrayValue(array, eleType, Integer.parseInt(name), valueString, options); - } else { - if (StringUtils.isBlank(belongToClass)) { - Field field = container.referenceType().fieldByName(name); - if (field != null) { - if (field.isStatic()) { - newValue = this.setStaticFieldValue(container.referenceType(), field, name, valueString, options); - } else { - newValue = this.setObjectFieldValue(container, field, name, valueString, options); - } - } else { - throw new IllegalArgumentException( - String.format("SetVariableRequest: Variable %s cannot be found.", name)); - } - } else { - newValue = setFieldValueWithConflict(container, container.referenceType().allFields(), name, belongToClass, valueString, options); - } - } - return newValue; - } - - private Value handleSetValueForStackFrame(String name, String belongToClass, String valueString, - boolean showStaticVariables, StackFrame container, Map options) - throws AbsentInformationException, InvalidTypeException, ClassNotLoadedException { - Value newValue; - if (name.equals("this")) { - throw new UnsupportedOperationException("SetVariableRequest: 'This' variable cannot be changed."); - } - LocalVariable variable = container.visibleVariableByName(name); - if (StringUtils.isBlank(belongToClass) && variable != null) { - newValue = this.setFrameValue(container, variable, valueString, options); - } else { - if (showStaticVariables && container.location().method().isStatic()) { - ReferenceType type = container.location().declaringType(); - if (StringUtils.isBlank(belongToClass)) { - Field field = type.fieldByName(name); - newValue = setStaticFieldValue(type, field, name, valueString, options); - } else { - newValue = setFieldValueWithConflict(null, type.allFields(), name, belongToClass, - valueString, options); - } - } else { - throw new UnsupportedOperationException( - String.format("SetVariableRequest: Variable %s cannot be found.", name)); - } - } - return newValue; - } - - private Value setValueProxy(Type type, String value, SetValueFunction setValueFunc, Map options) - throws ClassNotLoadedException, InvalidTypeException { - Value newValue = context.getVariableFormatter().stringToValue(value, type, options); - setValueFunc.apply(newValue); - return newValue; - } - - private Value setStaticFieldValue(Type declaringType, Field field, String name, String value, Map options) - throws ClassNotLoadedException, InvalidTypeException { - if (field.isFinal()) { - throw new UnsupportedOperationException( - String.format("SetVariableRequest: Final field %s cannot be changed.", name)); - } - if (!(declaringType instanceof ClassType)) { - throw new UnsupportedOperationException( - String.format("SetVariableRequest: Field %s in interface cannot be changed.", name)); - } - return setValueProxy(field.type(), value, newValue -> ((ClassType) declaringType).setValue(field, newValue), options); - } - - private Value setFrameValue(StackFrame frame, LocalVariable localVariable, String value, Map options) - throws ClassNotLoadedException, InvalidTypeException { - return setValueProxy(localVariable.type(), value, newValue -> frame.setValue(localVariable, newValue), options); - } - - private Value setObjectFieldValue(ObjectReference obj, Field field, String name, String value, Map options) - throws ClassNotLoadedException, InvalidTypeException { - if (field.isFinal()) { - throw new UnsupportedOperationException( - String.format("SetVariableRequest: Final field %s cannot be changed.", name)); - } - return setValueProxy(field.type(), value, newValue -> obj.setValue(field, newValue), options); - } - - private Value setArrayValue(ArrayReference array, Type eleType, int index, String value, Map options) - throws ClassNotLoadedException, InvalidTypeException { - return setValueProxy(eleType, value, newValue -> array.setValue(index, newValue), options); - } - - private Value setFieldValueWithConflict(ObjectReference obj, List fields, String name, String belongToClass, - String value, Map options) throws ClassNotLoadedException, InvalidTypeException { - Field field; - // first try to resolve field by fully qualified name - List narrowedFields = fields.stream().filter(TypeComponent::isStatic) - .filter(t -> t.name().equals(name) && t.declaringType().name().equals(belongToClass)) - .collect(Collectors.toList()); - if (narrowedFields.isEmpty()) { - // second try to resolve field by formatted name - narrowedFields = fields.stream().filter(TypeComponent::isStatic) - .filter(t -> t.name().equals(name) - && context.getVariableFormatter().typeToString(t.declaringType(), options).equals(belongToClass)) - .collect(Collectors.toList()); - } - if (narrowedFields.size() == 1) { - field = narrowedFields.get(0); - } else { - throw new UnsupportedOperationException(String.format("SetVariableRequest: Name conflicted for %s.", name)); - } - return field.isStatic() ? setStaticFieldValue(field.declaringType(), field, name, value, options) - : this.setObjectFieldValue(obj, field, name, value, options); - } - - @FunctionalInterface - interface SetValueFunction { - void apply(Value value) throws InvalidTypeException, ClassNotLoadedException; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.SetVariableArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; +import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.ArrayReference; +import com.sun.jdi.ArrayType; +import com.sun.jdi.ClassNotLoadedException; +import com.sun.jdi.ClassType; +import com.sun.jdi.Field; +import com.sun.jdi.InvalidTypeException; +import com.sun.jdi.LocalVariable; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.ReferenceType; +import com.sun.jdi.StackFrame; +import com.sun.jdi.Type; +import com.sun.jdi.TypeComponent; +import com.sun.jdi.Value; + +public class SetVariableRequestHandler implements IDebugRequestHandler { + private static final String PATTERN = "([a-zA-Z_0-9$]+)\\s*\\(([^)]+)\\)"; + private IDebugAdapterContext context = null; + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SETVARIABLE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + SetVariableArguments setVarArguments = (SetVariableArguments) arguments; + if (setVarArguments.value == null) { + // Just exit out of editing if we're given an empty expression. + return; + } else if (setVarArguments.variablesReference == -1) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + "SetVariablesRequest: property 'variablesReference' is missing, null, or empty"); + return; + } else if (StringUtils.isBlank(setVarArguments.name)) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + "SetVariablesRequest: property 'name' is missing, null, or empty"); + return; + } + + this.context = context; + Map options = context.getVariableFormatter().getDefaultOptions(); + // This should be false by default(currently true for test). + // User will need to explicitly turn it on by configuring launch.json + boolean showStaticVariables = true; + // TODO: when vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. + boolean showFullyQualifiedNames = true; + if (setVarArguments.format != null && setVarArguments.format.hex) { + options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); + } + if (showFullyQualifiedNames) { + options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); + } + + Object container = context.getRecyclableIdPool().getObjectById(setVarArguments.variablesReference); + // container is null means the stack frame is continued by user manually. + if (container == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, + "Failed to set variable. Reason: Cannot set value because the thread is resumed."); + return; + } + + String name = setVarArguments.name; + Value newValue; + String belongToClass = null; + + if (setVarArguments.name.contains("(")) { + name = setVarArguments.name.replaceFirst(PATTERN, "$1"); + belongToClass = setVarArguments.name.replaceFirst(PATTERN, "$2"); + } + + Object containerObj = ((VariableProxy) container).getProxiedVariable(); + try { + if (containerObj instanceof StackFrame) { + newValue = handleSetValueForStackFrame(name, belongToClass, setVarArguments.value, + showStaticVariables, (StackFrame) containerObj, options); + } else if (containerObj instanceof ObjectReference) { + newValue = handleSetValueForObject(name, belongToClass, setVarArguments.value, + (ObjectReference) containerObj, options); + } else { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, + String.format("SetVariableRequest: Variable %s cannot be found.", setVarArguments.variablesReference)); + return; + } + } catch (IllegalArgumentException | AbsentInformationException | InvalidTypeException + | UnsupportedOperationException | ClassNotLoadedException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, + String.format("Failed to set variable. Reason: %s", e.toString())); + return; + } + int referenceId = 0; + if (newValue instanceof ObjectReference && VariableUtils.hasChildren(newValue, showStaticVariables)) { + long threadId = ((VariableProxy) container).getThreadId(); + String scopeName = ((VariableProxy) container).getScope(); + VariableProxy varProxy = new VariableProxy(threadId, scopeName, (ObjectReference) newValue); + referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy); + } + + int indexedVariables = 0; + if (newValue instanceof ArrayReference) { + indexedVariables = ((ArrayReference) newValue).length(); + } + response.body = new Responses.SetVariablesResponseBody( + context.getVariableFormatter().typeToString(newValue == null ? null : newValue.type(), options), // type + context.getVariableFormatter().valueToString(newValue, options), // value, + referenceId, indexedVariables); + } + + private Value handleSetValueForObject(String name, String belongToClass, String valueString, + ObjectReference container, Map options) throws InvalidTypeException, ClassNotLoadedException { + Value newValue; + if (container instanceof ArrayReference) { + ArrayReference array = (ArrayReference) container; + Type eleType = ((ArrayType) array.referenceType()).componentType(); + newValue = setArrayValue(array, eleType, Integer.parseInt(name), valueString, options); + } else { + if (StringUtils.isBlank(belongToClass)) { + Field field = container.referenceType().fieldByName(name); + if (field != null) { + if (field.isStatic()) { + newValue = this.setStaticFieldValue(container.referenceType(), field, name, valueString, options); + } else { + newValue = this.setObjectFieldValue(container, field, name, valueString, options); + } + } else { + throw new IllegalArgumentException( + String.format("SetVariableRequest: Variable %s cannot be found.", name)); + } + } else { + newValue = setFieldValueWithConflict(container, container.referenceType().allFields(), name, belongToClass, valueString, options); + } + } + return newValue; + } + + private Value handleSetValueForStackFrame(String name, String belongToClass, String valueString, + boolean showStaticVariables, StackFrame container, Map options) + throws AbsentInformationException, InvalidTypeException, ClassNotLoadedException { + Value newValue; + if (name.equals("this")) { + throw new UnsupportedOperationException("SetVariableRequest: 'This' variable cannot be changed."); + } + LocalVariable variable = container.visibleVariableByName(name); + if (StringUtils.isBlank(belongToClass) && variable != null) { + newValue = this.setFrameValue(container, variable, valueString, options); + } else { + if (showStaticVariables && container.location().method().isStatic()) { + ReferenceType type = container.location().declaringType(); + if (StringUtils.isBlank(belongToClass)) { + Field field = type.fieldByName(name); + newValue = setStaticFieldValue(type, field, name, valueString, options); + } else { + newValue = setFieldValueWithConflict(null, type.allFields(), name, belongToClass, + valueString, options); + } + } else { + throw new UnsupportedOperationException( + String.format("SetVariableRequest: Variable %s cannot be found.", name)); + } + } + return newValue; + } + + private Value setValueProxy(Type type, String value, SetValueFunction setValueFunc, Map options) + throws ClassNotLoadedException, InvalidTypeException { + Value newValue = context.getVariableFormatter().stringToValue(value, type, options); + setValueFunc.apply(newValue); + return newValue; + } + + private Value setStaticFieldValue(Type declaringType, Field field, String name, String value, Map options) + throws ClassNotLoadedException, InvalidTypeException { + if (field.isFinal()) { + throw new UnsupportedOperationException( + String.format("SetVariableRequest: Final field %s cannot be changed.", name)); + } + if (!(declaringType instanceof ClassType)) { + throw new UnsupportedOperationException( + String.format("SetVariableRequest: Field %s in interface cannot be changed.", name)); + } + return setValueProxy(field.type(), value, newValue -> ((ClassType) declaringType).setValue(field, newValue), options); + } + + private Value setFrameValue(StackFrame frame, LocalVariable localVariable, String value, Map options) + throws ClassNotLoadedException, InvalidTypeException { + return setValueProxy(localVariable.type(), value, newValue -> frame.setValue(localVariable, newValue), options); + } + + private Value setObjectFieldValue(ObjectReference obj, Field field, String name, String value, Map options) + throws ClassNotLoadedException, InvalidTypeException { + if (field.isFinal()) { + throw new UnsupportedOperationException( + String.format("SetVariableRequest: Final field %s cannot be changed.", name)); + } + return setValueProxy(field.type(), value, newValue -> obj.setValue(field, newValue), options); + } + + private Value setArrayValue(ArrayReference array, Type eleType, int index, String value, Map options) + throws ClassNotLoadedException, InvalidTypeException { + return setValueProxy(eleType, value, newValue -> array.setValue(index, newValue), options); + } + + private Value setFieldValueWithConflict(ObjectReference obj, List fields, String name, String belongToClass, + String value, Map options) throws ClassNotLoadedException, InvalidTypeException { + Field field; + // first try to resolve field by fully qualified name + List narrowedFields = fields.stream().filter(TypeComponent::isStatic) + .filter(t -> t.name().equals(name) && t.declaringType().name().equals(belongToClass)) + .collect(Collectors.toList()); + if (narrowedFields.isEmpty()) { + // second try to resolve field by formatted name + narrowedFields = fields.stream().filter(TypeComponent::isStatic) + .filter(t -> t.name().equals(name) + && context.getVariableFormatter().typeToString(t.declaringType(), options).equals(belongToClass)) + .collect(Collectors.toList()); + } + if (narrowedFields.size() == 1) { + field = narrowedFields.get(0); + } else { + throw new UnsupportedOperationException(String.format("SetVariableRequest: Name conflicted for %s.", name)); + } + return field.isStatic() ? setStaticFieldValue(field.declaringType(), field, name, value, options) + : this.setObjectFieldValue(obj, field, name, value, options); + } + + @FunctionalInterface + interface SetValueFunction { + void apply(Value value) throws InvalidTypeException, ClassNotLoadedException; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java index 8d3755367..fda779a42 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java @@ -1,48 +1,48 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.SourceArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; - -public class SourceRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SOURCE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - int sourceReference = ((SourceArguments) arguments).sourceReference; - if (sourceReference <= 0) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "SourceRequest: property 'sourceReference' is missing, null, or empty"); - } else { - String uri = context.getSourceUri(sourceReference); - ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); - response.body = new Responses.SourceResponseBody(sourceProvider.getSourceContents(uri)); - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.SourceArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; + +public class SourceRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SOURCE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + int sourceReference = ((SourceArguments) arguments).sourceReference; + if (sourceReference <= 0) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + "SourceRequest: property 'sourceReference' is missing, null, or empty"); + } else { + String uri = context.getSourceUri(sourceReference); + ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); + response.body = new Responses.SourceResponseBody(sourceProvider.getSourceContents(uri)); + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java index 08de6e8a1..245b35b4f 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java @@ -1,130 +1,130 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.DebugUtility; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.StackTraceArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; -import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.IncompatibleThreadStateException; -import com.sun.jdi.Location; -import com.sun.jdi.Method; -import com.sun.jdi.StackFrame; -import com.sun.jdi.ThreadReference; - -public class StackTraceRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.STACKTRACE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - StackTraceArguments stacktraceArgs = (StackTraceArguments) arguments; - List result = new ArrayList<>(); - if (stacktraceArgs.startFrame < 0 || stacktraceArgs.levels < 0) { - response.body = new Responses.StackTraceResponseBody(result, 0); - return; - } - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), stacktraceArgs.threadId); - int totalFrames = 0; - if (thread != null) { - try { - totalFrames = thread.frameCount(); - if (totalFrames <= stacktraceArgs.startFrame) { - response.body = new Responses.StackTraceResponseBody(result, totalFrames); - return; - } - List stackFrames = stacktraceArgs.levels == 0 - ? thread.frames(stacktraceArgs.startFrame, totalFrames - stacktraceArgs.startFrame) - : thread.frames(stacktraceArgs.startFrame, - Math.min(totalFrames - stacktraceArgs.startFrame, stacktraceArgs.levels)); - for (int i = 0; i < stackFrames.size(); i++) { - StackFrame stackFrame = stackFrames.get(i); - int frameId = context.getRecyclableIdPool().addObject(stackFrame.thread().uniqueID(), - new JdiObjectProxy<>(stackFrame)); - Types.StackFrame clientStackFrame = convertDebuggerStackFrameToClient(stackFrame, frameId, context); - result.add(clientStackFrame); - } - } catch (IncompatibleThreadStateException | IndexOutOfBoundsException | URISyntaxException | AbsentInformationException e) { - // do nothing. - } - } - response.body = new Responses.StackTraceResponseBody(result, totalFrames); - } - - private Types.StackFrame convertDebuggerStackFrameToClient(StackFrame stackFrame, int frameId, IDebugAdapterContext context) - throws URISyntaxException, AbsentInformationException { - Location location = stackFrame.location(); - Method method = location.method(); - Types.Source clientSource = this.convertDebuggerSourceToClient(location, context); - String methodName = method.name(); - int lineNumber = AdapterUtils.convertLineNumber(location.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1()); - if (lineNumber < 0 && method.isNative()) { - // When the current stack frame stops at a native method, the line number is -1. - // Display a tip text "native method" in the Call Stack View. - methodName += "[native method]"; - } - return new Types.StackFrame(frameId, methodName, clientSource, lineNumber, 0); - } - - private Types.Source convertDebuggerSourceToClient(Location location, IDebugAdapterContext context) throws URISyntaxException { - final String fullyQualifiedName = location.declaringType().name(); - String sourceName = ""; - String relativeSourcePath = ""; - try { - // When the .class file doesn't contain source information in meta data, - // invoking Location#sourceName() would throw AbsentInformationException. - sourceName = location.sourceName(); - relativeSourcePath = location.sourcePath(); - } catch (AbsentInformationException e) { - String enclosingType = AdapterUtils.parseEnclosingType(fullyQualifiedName); - sourceName = enclosingType.substring(enclosingType.lastIndexOf('.') + 1) + ".java"; - relativeSourcePath = enclosingType.replace('.', '/') + ".java"; - } - - final String finalRelativeSourcePath = relativeSourcePath; - // use a lru cache for better performance - String uri = context.getSourceLookupCache().computeIfAbsent(fullyQualifiedName, key -> - context.getProvider(ISourceLookUpProvider.class).getSourceFileURI(key, finalRelativeSourcePath) - ); - - if (uri != null) { - String clientPath = AdapterUtils.convertPath(uri, context.isDebuggerPathsAreUri(), context.isClientPathsAreUri()); - if (uri.startsWith("file:")) { - return new Types.Source(sourceName, clientPath, 0); - } else { - return new Types.Source(sourceName, clientPath, context.createSourceReference(uri)); - } - } else { - // If the source lookup engine cannot find the source file, then lookup it in the source directories specified by user. - String absoluteSourcepath = AdapterUtils.sourceLookup(context.getSourcePaths(), relativeSourcePath); - return new Types.Source(sourceName, absoluteSourcepath, 0); - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.DebugUtility; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.StackTraceArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; +import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.IncompatibleThreadStateException; +import com.sun.jdi.Location; +import com.sun.jdi.Method; +import com.sun.jdi.StackFrame; +import com.sun.jdi.ThreadReference; + +public class StackTraceRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.STACKTRACE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + StackTraceArguments stacktraceArgs = (StackTraceArguments) arguments; + List result = new ArrayList<>(); + if (stacktraceArgs.startFrame < 0 || stacktraceArgs.levels < 0) { + response.body = new Responses.StackTraceResponseBody(result, 0); + return; + } + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), stacktraceArgs.threadId); + int totalFrames = 0; + if (thread != null) { + try { + totalFrames = thread.frameCount(); + if (totalFrames <= stacktraceArgs.startFrame) { + response.body = new Responses.StackTraceResponseBody(result, totalFrames); + return; + } + List stackFrames = stacktraceArgs.levels == 0 + ? thread.frames(stacktraceArgs.startFrame, totalFrames - stacktraceArgs.startFrame) + : thread.frames(stacktraceArgs.startFrame, + Math.min(totalFrames - stacktraceArgs.startFrame, stacktraceArgs.levels)); + for (int i = 0; i < stackFrames.size(); i++) { + StackFrame stackFrame = stackFrames.get(i); + int frameId = context.getRecyclableIdPool().addObject(stackFrame.thread().uniqueID(), + new JdiObjectProxy<>(stackFrame)); + Types.StackFrame clientStackFrame = convertDebuggerStackFrameToClient(stackFrame, frameId, context); + result.add(clientStackFrame); + } + } catch (IncompatibleThreadStateException | IndexOutOfBoundsException | URISyntaxException | AbsentInformationException e) { + // do nothing. + } + } + response.body = new Responses.StackTraceResponseBody(result, totalFrames); + } + + private Types.StackFrame convertDebuggerStackFrameToClient(StackFrame stackFrame, int frameId, IDebugAdapterContext context) + throws URISyntaxException, AbsentInformationException { + Location location = stackFrame.location(); + Method method = location.method(); + Types.Source clientSource = this.convertDebuggerSourceToClient(location, context); + String methodName = method.name(); + int lineNumber = AdapterUtils.convertLineNumber(location.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1()); + if (lineNumber < 0 && method.isNative()) { + // When the current stack frame stops at a native method, the line number is -1. + // Display a tip text "native method" in the Call Stack View. + methodName += "[native method]"; + } + return new Types.StackFrame(frameId, methodName, clientSource, lineNumber, 0); + } + + private Types.Source convertDebuggerSourceToClient(Location location, IDebugAdapterContext context) throws URISyntaxException { + final String fullyQualifiedName = location.declaringType().name(); + String sourceName = ""; + String relativeSourcePath = ""; + try { + // When the .class file doesn't contain source information in meta data, + // invoking Location#sourceName() would throw AbsentInformationException. + sourceName = location.sourceName(); + relativeSourcePath = location.sourcePath(); + } catch (AbsentInformationException e) { + String enclosingType = AdapterUtils.parseEnclosingType(fullyQualifiedName); + sourceName = enclosingType.substring(enclosingType.lastIndexOf('.') + 1) + ".java"; + relativeSourcePath = enclosingType.replace('.', '/') + ".java"; + } + + final String finalRelativeSourcePath = relativeSourcePath; + // use a lru cache for better performance + String uri = context.getSourceLookupCache().computeIfAbsent(fullyQualifiedName, key -> + context.getProvider(ISourceLookUpProvider.class).getSourceFileURI(key, finalRelativeSourcePath) + ); + + if (uri != null) { + String clientPath = AdapterUtils.convertPath(uri, context.isDebuggerPathsAreUri(), context.isClientPathsAreUri()); + if (uri.startsWith("file:")) { + return new Types.Source(sourceName, clientPath, 0); + } else { + return new Types.Source(sourceName, clientPath, context.createSourceReference(uri)); + } + } else { + // If the source lookup engine cannot find the source file, then lookup it in the source directories specified by user. + String absoluteSourcepath = AdapterUtils.sourceLookup(context.getSourcePaths(), relativeSourcePath); + return new Types.Source(sourceName, absoluteSourcepath, 0); + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java index 7d65db84a..009de3e86 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java @@ -1,154 +1,154 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.DebugUtility; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.Events; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.ContinueArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.NextArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.PauseArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.StepInArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.StepOutArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.ThreadsArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; - -import com.sun.jdi.ThreadReference; -import com.sun.jdi.VMDisconnectedException; - -public class ThreadsRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.THREADS, Command.STEPIN, Command.STEPOUT, Command.NEXT, Command.PAUSE, Command.CONTINUE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - if (context.getDebugSession() == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Debug Session doesn't exist."); - return; - } - switch (command) { - case THREADS: - this.threads((ThreadsArguments) arguments, response, context); - break; - case STEPIN: - this.stepIn((StepInArguments) arguments, response, context); - break; - case STEPOUT: - this.stepOut((StepOutArguments) arguments, response, context); - break; - case NEXT: - this.next((NextArguments) arguments, response, context); - break; - case PAUSE: - this.pause((PauseArguments) arguments, response, context); - break; - case CONTINUE: - this.resume((ContinueArguments) arguments, response, context); - break; - default: - return; - } - } - - private void threads(Requests.ThreadsArguments arguments, Response response, IDebugAdapterContext context) { - ArrayList threads = new ArrayList<>(); - for (ThreadReference thread : DebugUtility.getAllThreadsSafely(context.getDebugSession())) { - Types.Thread clientThread = new Types.Thread(thread.uniqueID(), "Thread [" + thread.name() + "]"); - threads.add(clientThread); - } - response.body = new Responses.ThreadsResponseBody(threads); - } - - private void stepIn(Requests.StepInArguments arguments, Response response, IDebugAdapterContext context) { - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - if (thread != null) { - DebugUtility.stepInto(thread, context.getDebugSession().eventHub()); - checkThreadRunningAndRecycleIds(thread, context); - } - } - - private void stepOut(Requests.StepOutArguments arguments, Response response, IDebugAdapterContext context) { - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - if (thread != null) { - DebugUtility.stepOut(thread, context.getDebugSession().eventHub()); - checkThreadRunningAndRecycleIds(thread, context); - } - } - - private void next(Requests.NextArguments arguments, Response response, IDebugAdapterContext context) { - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - if (thread != null) { - DebugUtility.stepOver(thread, context.getDebugSession().eventHub()); - checkThreadRunningAndRecycleIds(thread, context); - } - } - - private void pause(Requests.PauseArguments arguments, Response response, IDebugAdapterContext context) { - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - if (thread != null) { - thread.suspend(); - context.sendEventAsync(new Events.StoppedEvent("pause", arguments.threadId)); - } else { - context.getDebugSession().suspend(); - context.sendEventAsync(new Events.StoppedEvent("pause", arguments.threadId, true)); - } - } - - private void resume(Requests.ContinueArguments arguments, Response response, IDebugAdapterContext context) { - boolean allThreadsContinued = true; - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - /** - * See the jdi doc https://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/ThreadReference.html#resume(), - * suspends of both the virtual machine and individual threads are counted. Before a thread will run again, it must - * be resumed (through ThreadReference#resume() or VirtualMachine#resume()) the same number of times it has been suspended. - */ - if (thread != null) { - allThreadsContinued = false; - DebugUtility.resumeThread(thread); - checkThreadRunningAndRecycleIds(thread, context); - } else { - context.getDebugSession().resume(); - context.getRecyclableIdPool().removeAllObjects(); - } - response.body = new Responses.ContinueResponseBody(allThreadsContinued); - } - - private void checkThreadRunningAndRecycleIds(ThreadReference thread, IDebugAdapterContext context) { - try { - boolean allThreadsRunning = !DebugUtility.getAllThreadsSafely(context.getDebugSession()) - .stream().anyMatch(ThreadReference::isSuspended); - if (allThreadsRunning) { - context.getRecyclableIdPool().removeAllObjects(); - } else { - context.getRecyclableIdPool().removeObjectsByOwner(thread.uniqueID()); - } - } catch (VMDisconnectedException ex) { - context.getRecyclableIdPool().removeAllObjects(); - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.DebugUtility; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.Events; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.ContinueArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.NextArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.PauseArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.StepInArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.StepOutArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.ThreadsArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; + +import com.sun.jdi.ThreadReference; +import com.sun.jdi.VMDisconnectedException; + +public class ThreadsRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.THREADS, Command.STEPIN, Command.STEPOUT, Command.NEXT, Command.PAUSE, Command.CONTINUE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + if (context.getDebugSession() == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Debug Session doesn't exist."); + return; + } + switch (command) { + case THREADS: + this.threads((ThreadsArguments) arguments, response, context); + break; + case STEPIN: + this.stepIn((StepInArguments) arguments, response, context); + break; + case STEPOUT: + this.stepOut((StepOutArguments) arguments, response, context); + break; + case NEXT: + this.next((NextArguments) arguments, response, context); + break; + case PAUSE: + this.pause((PauseArguments) arguments, response, context); + break; + case CONTINUE: + this.resume((ContinueArguments) arguments, response, context); + break; + default: + return; + } + } + + private void threads(Requests.ThreadsArguments arguments, Response response, IDebugAdapterContext context) { + ArrayList threads = new ArrayList<>(); + for (ThreadReference thread : DebugUtility.getAllThreadsSafely(context.getDebugSession())) { + Types.Thread clientThread = new Types.Thread(thread.uniqueID(), "Thread [" + thread.name() + "]"); + threads.add(clientThread); + } + response.body = new Responses.ThreadsResponseBody(threads); + } + + private void stepIn(Requests.StepInArguments arguments, Response response, IDebugAdapterContext context) { + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + if (thread != null) { + DebugUtility.stepInto(thread, context.getDebugSession().eventHub()); + checkThreadRunningAndRecycleIds(thread, context); + } + } + + private void stepOut(Requests.StepOutArguments arguments, Response response, IDebugAdapterContext context) { + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + if (thread != null) { + DebugUtility.stepOut(thread, context.getDebugSession().eventHub()); + checkThreadRunningAndRecycleIds(thread, context); + } + } + + private void next(Requests.NextArguments arguments, Response response, IDebugAdapterContext context) { + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + if (thread != null) { + DebugUtility.stepOver(thread, context.getDebugSession().eventHub()); + checkThreadRunningAndRecycleIds(thread, context); + } + } + + private void pause(Requests.PauseArguments arguments, Response response, IDebugAdapterContext context) { + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + if (thread != null) { + thread.suspend(); + context.sendEventAsync(new Events.StoppedEvent("pause", arguments.threadId)); + } else { + context.getDebugSession().suspend(); + context.sendEventAsync(new Events.StoppedEvent("pause", arguments.threadId, true)); + } + } + + private void resume(Requests.ContinueArguments arguments, Response response, IDebugAdapterContext context) { + boolean allThreadsContinued = true; + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + /** + * See the jdi doc https://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/ThreadReference.html#resume(), + * suspends of both the virtual machine and individual threads are counted. Before a thread will run again, it must + * be resumed (through ThreadReference#resume() or VirtualMachine#resume()) the same number of times it has been suspended. + */ + if (thread != null) { + allThreadsContinued = false; + DebugUtility.resumeThread(thread); + checkThreadRunningAndRecycleIds(thread, context); + } else { + context.getDebugSession().resume(); + context.getRecyclableIdPool().removeAllObjects(); + } + response.body = new Responses.ContinueResponseBody(allThreadsContinued); + } + + private void checkThreadRunningAndRecycleIds(ThreadReference thread, IDebugAdapterContext context) { + try { + boolean allThreadsRunning = !DebugUtility.getAllThreadsSafely(context.getDebugSession()) + .stream().anyMatch(ThreadReference::isSuspended); + if (allThreadsRunning) { + context.getRecyclableIdPool().removeAllObjects(); + } else { + context.getRecyclableIdPool().removeObjectsByOwner(thread.uniqueID()); + } + } catch (VMDisconnectedException ex) { + context.getRecyclableIdPool().removeAllObjects(); + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java index c194d2ecc..755c5bf03 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java @@ -1,194 +1,194 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.VariablesArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; -import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.IVariableFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.Variable; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.ArrayReference; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.StackFrame; -import com.sun.jdi.Type; -import com.sun.jdi.Value; - -public class VariablesRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.VARIABLES); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - IVariableFormatter variableFormatter = context.getVariableFormatter(); - VariablesArguments varArgs = (VariablesArguments) arguments; - - Map options = variableFormatter.getDefaultOptions(); - // This should be false by default(currently true for test). - // User will need to explicitly turn it on by configuring launch.json - boolean showStaticVariables = true; - // TODO: When vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. - boolean showFullyQualifiedNames = true; - if (varArgs.format != null && varArgs.format.hex) { - options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); - } - if (showFullyQualifiedNames) { - options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); - } - - List list = new ArrayList<>(); - Object container = context.getRecyclableIdPool().getObjectById(varArgs.variablesReference); - // vscode will always send variables request to a staled scope, return the empty list is ok since the next - // variable request will contain the right variablesReference. - if (container == null) { - response.body = new Responses.VariablesResponseBody(list); - return; - } - - if (!(container instanceof VariableProxy)) { - AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("VariablesRequest: Invalid variablesReference %d.", varArgs.variablesReference)); - return; - } - - VariableProxy containerNode = (VariableProxy) container; - List childrenList; - if (containerNode.getProxiedVariable() instanceof StackFrame) { - try { - StackFrame frame = (StackFrame) containerNode.getProxiedVariable(); - childrenList = VariableUtils.listLocalVariables(frame); - Variable thisVariable = VariableUtils.getThisVariable(frame); - if (thisVariable != null) { - childrenList.add(thisVariable); - } - if (showStaticVariables && frame.location().method().isStatic()) { - childrenList.addAll(VariableUtils.listStaticVariables(frame)); - } - } catch (AbsentInformationException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("Failed to get variables. Reason: %s", e.toString())); - return; - } - } else { - try { - ObjectReference containerObj = (ObjectReference) containerNode.getProxiedVariable(); - - if (varArgs.count > 0) { - childrenList = VariableUtils.listFieldVariables(containerObj, varArgs.start, varArgs.count); - } else { - childrenList = VariableUtils.listFieldVariables(containerObj, showStaticVariables); - } - } catch (AbsentInformationException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("Failed to get variables. Reason: %s", e.toString())); - return; - } - } - - // Find variable name duplicates - Set duplicateNames = getDuplicateNames(childrenList.stream().map(var -> var.name) - .collect(Collectors.toList())); - Map variableNameMap = new HashMap<>(); - if (!duplicateNames.isEmpty()) { - Map> duplicateVars = - childrenList.stream() - .filter(var -> duplicateNames.contains(var.name)) - .collect(Collectors.groupingBy(var -> var.name, Collectors.toList())); - - duplicateVars.forEach((k, duplicateVariables) -> { - Set declarationTypeNames = new HashSet<>(); - boolean declarationTypeNameConflict = false; - // try use type formatter to resolve name conflict - for (Variable javaVariable : duplicateVariables) { - Type declarationType = javaVariable.getDeclaringType(); - if (declarationType != null) { - String declarationTypeName = variableFormatter.typeToString(declarationType, options); - String compositeName = String.format("%s (%s)", javaVariable.name, declarationTypeName); - if (!declarationTypeNames.add(compositeName)) { - declarationTypeNameConflict = true; - break; - } - variableNameMap.put(javaVariable, compositeName); - } - } - // If there are duplicate names on declaration types, use fully qualified name - if (declarationTypeNameConflict) { - for (Variable javaVariable : duplicateVariables) { - Type declarationType = javaVariable.getDeclaringType(); - if (declarationType != null) { - variableNameMap.put(javaVariable, String.format("%s (%s)", javaVariable.name, declarationType.name())); - } - } - } - }); - } - for (Variable javaVariable : childrenList) { - Value value = javaVariable.value; - String name = javaVariable.name; - if (variableNameMap.containsKey(javaVariable)) { - name = variableNameMap.get(javaVariable); - } - int referenceId = 0; - if (value instanceof ObjectReference && VariableUtils.hasChildren(value, showStaticVariables)) { - VariableProxy varProxy = new VariableProxy(containerNode.getThreadId(), containerNode.getScope(), value); - referenceId = context.getRecyclableIdPool().addObject(containerNode.getThreadId(), varProxy); - } - Types.Variable typedVariables = new Types.Variable(name, variableFormatter.valueToString(value, options), - variableFormatter.typeToString(value == null ? null : value.type(), options), referenceId, null); - if (javaVariable.value instanceof ArrayReference) { - typedVariables.indexedVariables = ((ArrayReference) javaVariable.value).length(); - } - list.add(typedVariables); - } - response.body = new Responses.VariablesResponseBody(list); - } - - private Set getDuplicateNames(Collection list) { - Set result = new HashSet<>(); - Set set = new HashSet<>(); - - for (String item : list) { - if (!set.contains(item)) { - set.add(item); - } else { - result.add(item); - } - } - return result; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.VariablesArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; +import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.IVariableFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.Variable; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.ArrayReference; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.StackFrame; +import com.sun.jdi.Type; +import com.sun.jdi.Value; + +public class VariablesRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.VARIABLES); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + IVariableFormatter variableFormatter = context.getVariableFormatter(); + VariablesArguments varArgs = (VariablesArguments) arguments; + + Map options = variableFormatter.getDefaultOptions(); + // This should be false by default(currently true for test). + // User will need to explicitly turn it on by configuring launch.json + boolean showStaticVariables = true; + // TODO: When vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. + boolean showFullyQualifiedNames = true; + if (varArgs.format != null && varArgs.format.hex) { + options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); + } + if (showFullyQualifiedNames) { + options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); + } + + List list = new ArrayList<>(); + Object container = context.getRecyclableIdPool().getObjectById(varArgs.variablesReference); + // vscode will always send variables request to a staled scope, return the empty list is ok since the next + // variable request will contain the right variablesReference. + if (container == null) { + response.body = new Responses.VariablesResponseBody(list); + return; + } + + if (!(container instanceof VariableProxy)) { + AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, + String.format("VariablesRequest: Invalid variablesReference %d.", varArgs.variablesReference)); + return; + } + + VariableProxy containerNode = (VariableProxy) container; + List childrenList; + if (containerNode.getProxiedVariable() instanceof StackFrame) { + try { + StackFrame frame = (StackFrame) containerNode.getProxiedVariable(); + childrenList = VariableUtils.listLocalVariables(frame); + Variable thisVariable = VariableUtils.getThisVariable(frame); + if (thisVariable != null) { + childrenList.add(thisVariable); + } + if (showStaticVariables && frame.location().method().isStatic()) { + childrenList.addAll(VariableUtils.listStaticVariables(frame)); + } + } catch (AbsentInformationException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, + String.format("Failed to get variables. Reason: %s", e.toString())); + return; + } + } else { + try { + ObjectReference containerObj = (ObjectReference) containerNode.getProxiedVariable(); + + if (varArgs.count > 0) { + childrenList = VariableUtils.listFieldVariables(containerObj, varArgs.start, varArgs.count); + } else { + childrenList = VariableUtils.listFieldVariables(containerObj, showStaticVariables); + } + } catch (AbsentInformationException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, + String.format("Failed to get variables. Reason: %s", e.toString())); + return; + } + } + + // Find variable name duplicates + Set duplicateNames = getDuplicateNames(childrenList.stream().map(var -> var.name) + .collect(Collectors.toList())); + Map variableNameMap = new HashMap<>(); + if (!duplicateNames.isEmpty()) { + Map> duplicateVars = + childrenList.stream() + .filter(var -> duplicateNames.contains(var.name)) + .collect(Collectors.groupingBy(var -> var.name, Collectors.toList())); + + duplicateVars.forEach((k, duplicateVariables) -> { + Set declarationTypeNames = new HashSet<>(); + boolean declarationTypeNameConflict = false; + // try use type formatter to resolve name conflict + for (Variable javaVariable : duplicateVariables) { + Type declarationType = javaVariable.getDeclaringType(); + if (declarationType != null) { + String declarationTypeName = variableFormatter.typeToString(declarationType, options); + String compositeName = String.format("%s (%s)", javaVariable.name, declarationTypeName); + if (!declarationTypeNames.add(compositeName)) { + declarationTypeNameConflict = true; + break; + } + variableNameMap.put(javaVariable, compositeName); + } + } + // If there are duplicate names on declaration types, use fully qualified name + if (declarationTypeNameConflict) { + for (Variable javaVariable : duplicateVariables) { + Type declarationType = javaVariable.getDeclaringType(); + if (declarationType != null) { + variableNameMap.put(javaVariable, String.format("%s (%s)", javaVariable.name, declarationType.name())); + } + } + } + }); + } + for (Variable javaVariable : childrenList) { + Value value = javaVariable.value; + String name = javaVariable.name; + if (variableNameMap.containsKey(javaVariable)) { + name = variableNameMap.get(javaVariable); + } + int referenceId = 0; + if (value instanceof ObjectReference && VariableUtils.hasChildren(value, showStaticVariables)) { + VariableProxy varProxy = new VariableProxy(containerNode.getThreadId(), containerNode.getScope(), value); + referenceId = context.getRecyclableIdPool().addObject(containerNode.getThreadId(), varProxy); + } + Types.Variable typedVariables = new Types.Variable(name, variableFormatter.valueToString(value, options), + variableFormatter.typeToString(value == null ? null : value.type(), options), referenceId, null); + if (javaVariable.value instanceof ArrayReference) { + typedVariables.indexedVariables = ((ArrayReference) javaVariable.value).length(); + } + list.add(typedVariables); + } + response.body = new Responses.VariablesResponseBody(list); + } + + private Set getDuplicateNames(Collection list) { + Set result = new HashSet<>(); + Set set = new HashSet<>(); + + for (String item : list) { + if (!set.contains(item)) { + set.add(item); + } else { + result.add(item); + } + } + return result; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/Variable.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/Variable.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/Variable.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/Variable.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java index 13f051834..d776102ae 100644 --- a/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java @@ -1,70 +1,70 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.variables; - -import java.util.Objects; - -public class VariableProxy { - private final long threadId; - private final String scopeName; - private Object variable; - private int hashCode; - - /** - * Create a variable proxy. - * @param threadId - * the context thread id - * @param scopeName - * the scope name - * @param variable - * the variable object - */ - public VariableProxy(long threadId, String scopeName, Object variable) { - this.threadId = threadId; - this.scopeName = scopeName; - this.variable = variable; - this.hashCode = (int) (threadId & scopeName.hashCode() & variable.hashCode()); - } - - @Override - public String toString() { - return String.format("%s %s", String.valueOf(this.variable), this.scopeName); - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof VariableProxy)) { - return false; - } - final VariableProxy other = (VariableProxy) o; - return this.getThreadId() == other.getThreadId() - && Objects.equals(this.getScope(), other.getScope()) - && Objects.equals(this.getProxiedVariable(), other.getProxiedVariable()); - } - - public long getThreadId() { - return this.threadId; - } - - public String getScope() { - return this.scopeName; - } - - public Object getProxiedVariable() { - return this.variable; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.variables; + +import java.util.Objects; + +public class VariableProxy { + private final long threadId; + private final String scopeName; + private Object variable; + private int hashCode; + + /** + * Create a variable proxy. + * @param threadId + * the context thread id + * @param scopeName + * the scope name + * @param variable + * the variable object + */ + public VariableProxy(long threadId, String scopeName, Object variable) { + this.threadId = threadId; + this.scopeName = scopeName; + this.variable = variable; + this.hashCode = (int) (threadId & scopeName.hashCode() & variable.hashCode()); + } + + @Override + public String toString() { + return String.format("%s %s", String.valueOf(this.variable), this.scopeName); + } + + @Override + public int hashCode() { + return hashCode; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof VariableProxy)) { + return false; + } + final VariableProxy other = (VariableProxy) o; + return this.getThreadId() == other.getThreadId() + && Objects.equals(this.getScope(), other.getScope()) + && Objects.equals(this.getProxiedVariable(), other.getProxiedVariable()); + } + + public long getThreadId() { + return this.threadId; + } + + public String getScope() { + return this.scopeName; + } + + public Object getProxiedVariable() { + return this.variable; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java diff --git a/org/eclipse/jdt/ls/debug/internal/Breakpoint.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Breakpoint.java similarity index 100% rename from org/eclipse/jdt/ls/debug/internal/Breakpoint.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Breakpoint.java diff --git a/org/eclipse/jdt/ls/debug/internal/DebugSession.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/DebugSession.java similarity index 100% rename from org/eclipse/jdt/ls/debug/internal/DebugSession.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/DebugSession.java diff --git a/org/eclipse/jdt/ls/debug/internal/EventHub.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/EventHub.java similarity index 100% rename from org/eclipse/jdt/ls/debug/internal/EventHub.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/EventHub.java diff --git a/org/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java similarity index 100% rename from org/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java diff --git a/org/eclipse/jdt/ls/debug/internal/Logger.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Logger.java similarity index 97% rename from org/eclipse/jdt/ls/debug/internal/Logger.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Logger.java index c91ac90f9..4cad01691 100644 --- a/org/eclipse/jdt/ls/debug/internal/Logger.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Logger.java @@ -1,34 +1,34 @@ -/******************************************************************************* - * Copyright (c) 2017 Microsoft Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Microsoft Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jdt.ls.debug.internal; - -import org.eclipse.jdt.ls.debug.internal.JavaDebuggerServerPlugin; - -public class Logger { - /** - * Log the info message with the plugin's logger. - * @param message - * message to log - */ - public static void logInfo(String message) { - JavaDebuggerServerPlugin.logInfo(message); - } - - public static void logException(String message, Exception e) { - JavaDebuggerServerPlugin.logException(message, e); - } - - public static void logError(String error) { - JavaDebuggerServerPlugin.logError(error); - } - -} +/******************************************************************************* + * Copyright (c) 2017 Microsoft Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Microsoft Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jdt.ls.debug.internal; + +import org.eclipse.jdt.ls.debug.internal.JavaDebuggerServerPlugin; + +public class Logger { + /** + * Log the info message with the plugin's logger. + * @param message + * message to log + */ + public static void logInfo(String message) { + JavaDebuggerServerPlugin.logInfo(message); + } + + public static void logException(String message, Exception e) { + JavaDebuggerServerPlugin.logException(message, e); + } + + public static void logError(String error) { + JavaDebuggerServerPlugin.logError(error); + } + +} diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java new file mode 100644 index 000000000..1eea8de7e --- /dev/null +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java @@ -0,0 +1,33 @@ +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package com.microsoft.java.debug.plugin.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class JavaDebuggerServerPlugin implements BundleActivator { + + public static final String PLUGIN_ID = "com.microsoft.java.debug"; + + + @Override + public void start(BundleContext context) throws Exception { + System.out.println("Starting " + PLUGIN_ID); + } + + @Override + public void stop(BundleContext context) throws Exception { + + } + +} + diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java index 2ff281f80..9feaacdd1 100644 --- a/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java +++ b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java @@ -1,24 +1,24 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.jdt; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IExecutableExtensionFactory; - -public class DebugServerFactory implements IExecutableExtensionFactory { - - @Override - public Object create() throws CoreException { - return JavaDebugServer.getInstance(); - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.jdt; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IExecutableExtensionFactory; + +public class DebugServerFactory implements IExecutableExtensionFactory { + + @Override + public Object create() throws CoreException { + return JavaDebugServer.getInstance(); + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java From 2584413e8a2d33c3f5a491f7cb071741d1642063 Mon Sep 17 00:00:00 2001 From: andxu Date: Fri, 8 Sep 2017 13:29:35 +0800 Subject: [PATCH 2/2] move src folders Signed-off-by: andxu --- .gitignore | 38 ++ .../org}/eclipse/jdt/ls/debug/DebugEvent.java | 0 .../eclipse/jdt/ls/debug/DebugException.java | 64 +-- .../eclipse/jdt/ls/debug/DebugUtility.java | 0 .../eclipse/jdt/ls/debug/IBreakpoint.java | 0 .../eclipse/jdt/ls/debug/IDebugResource.java | 0 .../eclipse/jdt/ls/debug/IDebugSession.java | 0 .../org}/eclipse/jdt/ls/debug/IEventHub.java | 0 .../jdt/ls/debug/adapter/AdapterUtils.java | 0 .../ls/debug/adapter/BreakpointManager.java | 348 ++++++------ .../jdt/ls/debug/adapter/Constants.java | 32 +- .../jdt/ls/debug/adapter/DebugAdapter.java | 0 .../ls/debug/adapter/DebugAdapterContext.java | 344 ++++++------ .../jdt/ls/debug/adapter/ErrorCode.java | 74 +-- .../eclipse/jdt/ls/debug/adapter/Events.java | 0 .../jdt/ls/debug/adapter/IDebugAdapter.java | 0 .../debug/adapter/IDebugAdapterContext.java | 0 .../debug/adapter/IDebugRequestHandler.java | 0 .../jdt/ls/debug/adapter/IProvider.java | 0 .../ls/debug/adapter/IProviderContext.java | 0 .../debug/adapter/ISourceLookUpProvider.java | 0 .../IVirtualMachineManagerProvider.java | 0 .../jdt/ls/debug/adapter/IdCollection.java | 158 +++--- .../jdt/ls/debug/adapter/JsonUtils.java | 274 ++++----- .../jdt/ls/debug/adapter/LRUCache.java | 0 .../jdt/ls/debug/adapter/Messages.java | 0 .../jdt/ls/debug/adapter/ProcessConsole.java | 238 ++++---- .../jdt/ls/debug/adapter/ProtocolServer.java | 0 .../jdt/ls/debug/adapter/ProviderContext.java | 0 .../debug/adapter/RecyclableObjectPool.java | 0 .../jdt/ls/debug/adapter/Requests.java | 422 +++++++------- .../jdt/ls/debug/adapter/Responses.java | 0 .../eclipse/jdt/ls/debug/adapter/Types.java | 0 .../formatter/ArrayObjectFormatter.java | 0 .../adapter/formatter/BooleanFormatter.java | 0 .../adapter/formatter/CharacterFormatter.java | 0 .../formatter/ClassObjectFormatter.java | 0 .../debug/adapter/formatter/IFormatter.java | 0 .../adapter/formatter/ITypeFormatter.java | 0 .../adapter/formatter/IValueFormatter.java | 0 .../formatter/NullObjectFormatter.java | 0 .../adapter/formatter/NumericFormatEnum.java | 0 .../adapter/formatter/NumericFormatter.java | 0 .../adapter/formatter/ObjectFormatter.java | 0 .../formatter/SimpleTypeFormatter.java | 0 .../formatter/StringObjectFormatter.java | 0 .../adapter/formatter/TypeIdentifiers.java | 0 .../adapter/handler/AttachRequestHandler.java | 140 ++--- .../ConfigurationDoneRequestHandler.java | 196 +++---- .../handler/DisconnectRequestHandler.java | 90 +-- .../handler/EvaluateRequestHandler.java | 376 ++++++------- .../handler/InitializeRequestHandler.java | 0 .../adapter/handler/LaunchRequestHandler.java | 192 +++---- .../adapter/handler/ScopesRequestHandler.java | 110 ++-- .../handler/SetBreakpointsRequestHandler.java | 252 ++++----- ...SetExceptionBreakpointsRequestHandler.java | 98 ++-- .../handler/SetVariableRequestHandler.java | 528 +++++++++--------- .../adapter/handler/SourceRequestHandler.java | 96 ++-- .../handler/StackTraceRequestHandler.java | 260 ++++----- .../handler/ThreadsRequestHandler.java | 308 +++++----- .../handler/VariablesRequestHandler.java | 388 ++++++------- .../adapter/variables/IVariableFormatter.java | 0 .../adapter/variables/JdiObjectProxy.java | 0 .../ls/debug/adapter/variables/Variable.java | 0 .../adapter/variables/VariableFormatter.java | 0 .../variables/VariableFormatterFactory.java | 0 .../adapter/variables/VariableProxy.java | 140 ++--- .../adapter/variables/VariableUtils.java | 0 .../jdt/ls/debug/internal/Breakpoint.java | 0 .../jdt/ls/debug/internal/DebugSession.java | 0 .../jdt/ls/debug/internal/EventHub.java | 0 .../internal/JavaDebuggerServerPlugin.java | 0 .../eclipse/jdt/ls/debug/internal/Logger.java | 68 +-- .../internal/JavaDebuggerServerPlugin.java | 33 ++ .../debug/adapter/jdt/DebugServerFactory.java | 48 +- .../ls/debug/adapter/jdt/JavaDebugServer.java | 0 .../jdt/JdtProviderContextFactory.java | 0 .../adapter/jdt/JdtSourceLookUpProvider.java | 0 .../jdt/JdtVirtualMachineManagerProvider.java | 0 79 files changed, 2693 insertions(+), 2622 deletions(-) create mode 100644 .gitignore rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/DebugEvent.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/DebugException.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/DebugUtility.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/IBreakpoint.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/IDebugResource.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/IDebugSession.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/IEventHub.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/AdapterUtils.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/BreakpointManager.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Constants.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/DebugAdapter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ErrorCode.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Events.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IProvider.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IProviderContext.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/IdCollection.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/JsonUtils.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/LRUCache.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Messages.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ProcessConsole.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ProtocolServer.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/ProviderContext.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Requests.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Responses.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/Types.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java (98%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java (97%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/Variable.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java (96%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/Breakpoint.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/DebugSession.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/EventHub.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java (100%) rename {org => com.microsoft.java.debug.core/src/main/java/org}/eclipse/jdt/ls/debug/internal/Logger.java (97%) create mode 100644 com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java (97%) rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java (100%) rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java (100%) rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java (100%) rename {org => com.microsoft.java.debug.plugin/src/main/java/org}/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..5e2dd10da --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar +*.iml + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + +**/.idea/ +**/node_modules/ +.DS_Store +.idea +target/ +.classpath +.project +.settings +javaConfig.json +**/.checkstyle +target/ +bin/ +**/lib/ \ No newline at end of file diff --git a/org/eclipse/jdt/ls/debug/DebugEvent.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugEvent.java similarity index 100% rename from org/eclipse/jdt/ls/debug/DebugEvent.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugEvent.java diff --git a/org/eclipse/jdt/ls/debug/DebugException.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugException.java similarity index 96% rename from org/eclipse/jdt/ls/debug/DebugException.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugException.java index 1a97b0aec..563273cb4 100644 --- a/org/eclipse/jdt/ls/debug/DebugException.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugException.java @@ -1,32 +1,32 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug; - -public class DebugException extends Exception { - private static final long serialVersionUID = 1L; - - public DebugException() { - super(); - } - - public DebugException(String message) { - super(message); - } - - public DebugException(String message, Throwable cause) { - super(message, cause); - } - - public DebugException(Throwable cause) { - super(cause); - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug; + +public class DebugException extends Exception { + private static final long serialVersionUID = 1L; + + public DebugException() { + super(); + } + + public DebugException(String message) { + super(message); + } + + public DebugException(String message, Throwable cause) { + super(message, cause); + } + + public DebugException(Throwable cause) { + super(cause); + } +} diff --git a/org/eclipse/jdt/ls/debug/DebugUtility.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugUtility.java similarity index 100% rename from org/eclipse/jdt/ls/debug/DebugUtility.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/DebugUtility.java diff --git a/org/eclipse/jdt/ls/debug/IBreakpoint.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IBreakpoint.java similarity index 100% rename from org/eclipse/jdt/ls/debug/IBreakpoint.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IBreakpoint.java diff --git a/org/eclipse/jdt/ls/debug/IDebugResource.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IDebugResource.java similarity index 100% rename from org/eclipse/jdt/ls/debug/IDebugResource.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IDebugResource.java diff --git a/org/eclipse/jdt/ls/debug/IDebugSession.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IDebugSession.java similarity index 100% rename from org/eclipse/jdt/ls/debug/IDebugSession.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IDebugSession.java diff --git a/org/eclipse/jdt/ls/debug/IEventHub.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IEventHub.java similarity index 100% rename from org/eclipse/jdt/ls/debug/IEventHub.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/IEventHub.java diff --git a/org/eclipse/jdt/ls/debug/adapter/AdapterUtils.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/AdapterUtils.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/AdapterUtils.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/AdapterUtils.java diff --git a/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java index 97510f878..33a9c5285 100644 --- a/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/BreakpointManager.java @@ -1,174 +1,174 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - -import org.eclipse.jdt.ls.debug.IBreakpoint; -import org.eclipse.jdt.ls.debug.internal.Logger; - -public class BreakpointManager { - /** - * A collection of breakpoints registered with this manager. - */ - private List breakpoints; - private HashMap> sourceToBreakpoints; - private AtomicInteger nextBreakpointId = new AtomicInteger(1); - - /** - * Constructor. - */ - public BreakpointManager() { - this.breakpoints = Collections.synchronizedList(new ArrayList<>(5)); - this.sourceToBreakpoints = new HashMap<>(); - } - - /** - * Adds breakpoints to breakpoint manager. - * Deletes all breakpoints that are no longer listed. - * @param source - * source path of breakpoints - * @param breakpoints - * full list of breakpoints that locates in this source file - * @return the full breakpoint list that locates in the source file - */ - public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints) { - return setBreakpoints(source, breakpoints, false); - } - - /** - * Adds breakpoints to breakpoint manager. - * Deletes all breakpoints that are no longer listed. - * In the case of modified source, delete everything. - * @param source - * source path of breakpoints - * @param breakpoints - * full list of breakpoints that locates in this source file - * @param sourceModified - * the source file are modified or not. - * @return the full breakpoint list that locates in the source file - */ - public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints, boolean sourceModified) { - List result = new ArrayList<>(); - HashMap breakpointMap = this.sourceToBreakpoints.get(source); - // When source file is modified, delete all previously added breakpoints. - if (sourceModified && breakpointMap != null) { - for (IBreakpoint bp : breakpointMap.values()) { - try { - // Destroy the breakpoint on the debugee VM. - bp.close(); - } catch (Exception e) { - Logger.logException("Remove breakpoint exception", e); - } - this.breakpoints.remove(bp); - } - this.sourceToBreakpoints.put(source, null); - breakpointMap = null; - } - if (breakpointMap == null) { - breakpointMap = new HashMap<>(); - this.sourceToBreakpoints.put(source, breakpointMap); - } - - // Compute the breakpoints that are newly added. - List toAdd = new ArrayList<>(); - List visitedLineNumbers = new ArrayList<>(); - for (IBreakpoint breakpoint : breakpoints) { - IBreakpoint existed = breakpointMap.get(String.valueOf(breakpoint.lineNumber())); - if (existed != null) { - result.add(existed); - visitedLineNumbers.add(existed.lineNumber()); - continue; - } else { - result.add(breakpoint); - } - toAdd.add(breakpoint); - } - - // Compute the breakpoints that are no longer listed. - List toRemove = new ArrayList<>(); - for (IBreakpoint breakpoint : breakpointMap.values()) { - if (!visitedLineNumbers.contains(breakpoint.lineNumber())) { - toRemove.add(breakpoint); - } - } - - removeBreakpointsInternally(source, toRemove.toArray(new IBreakpoint[0])); - addBreakpointsInternally(source, toAdd.toArray(new IBreakpoint[0])); - - return result.toArray(new IBreakpoint[0]); - } - - private void addBreakpointsInternally(String source, IBreakpoint[] breakpoints) { - Map breakpointMap = this.sourceToBreakpoints.computeIfAbsent(source, k -> new HashMap<>()); - - if (breakpoints != null && breakpoints.length > 0) { - for (IBreakpoint breakpoint : breakpoints) { - breakpoint.putProperty("id", this.nextBreakpointId.getAndIncrement()); - this.breakpoints.add(breakpoint); - breakpointMap.put(String.valueOf(breakpoint.lineNumber()), breakpoint); - } - } - } - - /** - * Removes the specified breakpoints from breakpoint manager. - */ - private void removeBreakpointsInternally(String source, IBreakpoint[] breakpoints) { - Map breakpointMap = this.sourceToBreakpoints.get(source); - if (breakpointMap == null || breakpointMap.isEmpty() || breakpoints.length == 0) { - return; - } - - for (IBreakpoint breakpoint : breakpoints) { - if (this.breakpoints.contains(breakpoint)) { - try { - // Destroy the breakpoint on the debugee VM. - breakpoint.close(); - this.breakpoints.remove(breakpoint); - breakpointMap.remove(String.valueOf(breakpoint.lineNumber())); - } catch (Exception e) { - Logger.logException("Remove breakpoint exception", e); - } - } - } - } - - public IBreakpoint[] getBreakpoints() { - return this.breakpoints.toArray(new IBreakpoint[0]); - } - - /** - * Gets the registered breakpoints at the source file. - */ - public IBreakpoint[] getBreakpoints(String source) { - HashMap breakpointMap = this.sourceToBreakpoints.get(source); - if (breakpointMap == null) { - return new IBreakpoint[0]; - } - return breakpointMap.values().toArray(new IBreakpoint[0]); - } - - /** - * Cleanup all breakpoints and reset the breakpoint id counter. - */ - public void reset() { - this.sourceToBreakpoints.clear(); - this.breakpoints.clear(); - this.nextBreakpointId.set(1); - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +import org.eclipse.jdt.ls.debug.IBreakpoint; +import org.eclipse.jdt.ls.debug.internal.Logger; + +public class BreakpointManager { + /** + * A collection of breakpoints registered with this manager. + */ + private List breakpoints; + private HashMap> sourceToBreakpoints; + private AtomicInteger nextBreakpointId = new AtomicInteger(1); + + /** + * Constructor. + */ + public BreakpointManager() { + this.breakpoints = Collections.synchronizedList(new ArrayList<>(5)); + this.sourceToBreakpoints = new HashMap<>(); + } + + /** + * Adds breakpoints to breakpoint manager. + * Deletes all breakpoints that are no longer listed. + * @param source + * source path of breakpoints + * @param breakpoints + * full list of breakpoints that locates in this source file + * @return the full breakpoint list that locates in the source file + */ + public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints) { + return setBreakpoints(source, breakpoints, false); + } + + /** + * Adds breakpoints to breakpoint manager. + * Deletes all breakpoints that are no longer listed. + * In the case of modified source, delete everything. + * @param source + * source path of breakpoints + * @param breakpoints + * full list of breakpoints that locates in this source file + * @param sourceModified + * the source file are modified or not. + * @return the full breakpoint list that locates in the source file + */ + public IBreakpoint[] setBreakpoints(String source, IBreakpoint[] breakpoints, boolean sourceModified) { + List result = new ArrayList<>(); + HashMap breakpointMap = this.sourceToBreakpoints.get(source); + // When source file is modified, delete all previously added breakpoints. + if (sourceModified && breakpointMap != null) { + for (IBreakpoint bp : breakpointMap.values()) { + try { + // Destroy the breakpoint on the debugee VM. + bp.close(); + } catch (Exception e) { + Logger.logException("Remove breakpoint exception", e); + } + this.breakpoints.remove(bp); + } + this.sourceToBreakpoints.put(source, null); + breakpointMap = null; + } + if (breakpointMap == null) { + breakpointMap = new HashMap<>(); + this.sourceToBreakpoints.put(source, breakpointMap); + } + + // Compute the breakpoints that are newly added. + List toAdd = new ArrayList<>(); + List visitedLineNumbers = new ArrayList<>(); + for (IBreakpoint breakpoint : breakpoints) { + IBreakpoint existed = breakpointMap.get(String.valueOf(breakpoint.lineNumber())); + if (existed != null) { + result.add(existed); + visitedLineNumbers.add(existed.lineNumber()); + continue; + } else { + result.add(breakpoint); + } + toAdd.add(breakpoint); + } + + // Compute the breakpoints that are no longer listed. + List toRemove = new ArrayList<>(); + for (IBreakpoint breakpoint : breakpointMap.values()) { + if (!visitedLineNumbers.contains(breakpoint.lineNumber())) { + toRemove.add(breakpoint); + } + } + + removeBreakpointsInternally(source, toRemove.toArray(new IBreakpoint[0])); + addBreakpointsInternally(source, toAdd.toArray(new IBreakpoint[0])); + + return result.toArray(new IBreakpoint[0]); + } + + private void addBreakpointsInternally(String source, IBreakpoint[] breakpoints) { + Map breakpointMap = this.sourceToBreakpoints.computeIfAbsent(source, k -> new HashMap<>()); + + if (breakpoints != null && breakpoints.length > 0) { + for (IBreakpoint breakpoint : breakpoints) { + breakpoint.putProperty("id", this.nextBreakpointId.getAndIncrement()); + this.breakpoints.add(breakpoint); + breakpointMap.put(String.valueOf(breakpoint.lineNumber()), breakpoint); + } + } + } + + /** + * Removes the specified breakpoints from breakpoint manager. + */ + private void removeBreakpointsInternally(String source, IBreakpoint[] breakpoints) { + Map breakpointMap = this.sourceToBreakpoints.get(source); + if (breakpointMap == null || breakpointMap.isEmpty() || breakpoints.length == 0) { + return; + } + + for (IBreakpoint breakpoint : breakpoints) { + if (this.breakpoints.contains(breakpoint)) { + try { + // Destroy the breakpoint on the debugee VM. + breakpoint.close(); + this.breakpoints.remove(breakpoint); + breakpointMap.remove(String.valueOf(breakpoint.lineNumber())); + } catch (Exception e) { + Logger.logException("Remove breakpoint exception", e); + } + } + } + } + + public IBreakpoint[] getBreakpoints() { + return this.breakpoints.toArray(new IBreakpoint[0]); + } + + /** + * Gets the registered breakpoints at the source file. + */ + public IBreakpoint[] getBreakpoints(String source) { + HashMap breakpointMap = this.sourceToBreakpoints.get(source); + if (breakpointMap == null) { + return new IBreakpoint[0]; + } + return breakpointMap.values().toArray(new IBreakpoint[0]); + } + + /** + * Cleanup all breakpoints and reset the breakpoint id counter. + */ + public void reset() { + this.sourceToBreakpoints.clear(); + this.breakpoints.clear(); + this.nextBreakpointId.set(1); + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/Constants.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Constants.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/Constants.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Constants.java index 967705238..106237ae0 100644 --- a/org/eclipse/jdt/ls/debug/adapter/Constants.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Constants.java @@ -1,16 +1,16 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -public final class Constants { - public static final String PROJECTNAME = "projectName"; -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +public final class Constants { + public static final String PROJECTNAME = "projectName"; +} diff --git a/org/eclipse/jdt/ls/debug/adapter/DebugAdapter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/DebugAdapter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java index 8f38efc08..72d91c449 100644 --- a/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/DebugAdapterContext.java @@ -1,172 +1,172 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.nio.charset.Charset; -import java.util.Collections; -import java.util.Map; - -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.Events.DebugEvent; -import org.eclipse.jdt.ls.debug.adapter.variables.IVariableFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableFormatterFactory; - -public class DebugAdapterContext implements IDebugAdapterContext { - private static final int MAX_CACHE_ITEMS = 10000; - private Map sourceMappingCache = Collections.synchronizedMap(new LRUCache<>(MAX_CACHE_ITEMS)); - private DebugAdapter debugAdapter; - - private IDebugSession debugSession; - private boolean debuggerLinesStartAt1 = true; - private boolean debuggerPathsAreUri = true; - private boolean clientLinesStartAt1 = true; - private boolean clientPathsAreUri = false; - private boolean isAttached = false; - private String[] sourcePaths; - private Charset debuggeeEncoding; - - private IdCollection sourceReferences = new IdCollection<>(); - private RecyclableObjectPool recyclableIdPool = new RecyclableObjectPool<>(); - private IVariableFormatter variableFormatter = VariableFormatterFactory.createVariableFormatter(); - - public DebugAdapterContext(DebugAdapter debugAdapter) { - this.debugAdapter = debugAdapter; - } - - @Override - public void sendEvent(DebugEvent event) { - this.debugAdapter.sendEvent(event); - } - - @Override - public void sendEventAsync(DebugEvent event) { - this.debugAdapter.sendEventLater(event); - } - - @Override - public T getProvider(Class clazz) { - return this.debugAdapter.getProvider(clazz); - } - - @Override - public void setDebugSession(IDebugSession session) { - this.debugSession = session; - } - - @Override - public IDebugSession getDebugSession() { - return this.debugSession; - } - - @Override - public boolean isDebuggerLinesStartAt1() { - return this.debuggerLinesStartAt1; - } - - @Override - public void setDebuggerLinesStartAt1(boolean debuggerLinesStartAt1) { - this.debuggerLinesStartAt1 = debuggerLinesStartAt1; - } - - @Override - public boolean isDebuggerPathsAreUri() { - return this.debuggerPathsAreUri; - } - - @Override - public void setDebuggerPathsAreUri(boolean debuggerPathsAreUri) { - this.debuggerPathsAreUri = debuggerPathsAreUri; - } - - @Override - public boolean isClientLinesStartAt1() { - return this.clientLinesStartAt1; - } - - @Override - public void setClientLinesStartAt1(boolean clientLinesStartAt1) { - this.clientLinesStartAt1 = clientLinesStartAt1; - } - - @Override - public boolean isClientPathsAreUri() { - return this.clientPathsAreUri; - } - - @Override - public void setClientPathsAreUri(boolean clientPathsAreUri) { - this.clientPathsAreUri = clientPathsAreUri; - } - - @Override - public boolean isAttached() { - return this.isAttached; - } - - @Override - public void setAttached(boolean attached) { - this.isAttached = attached; - } - - public String[] getSourcePaths() { - return this.sourcePaths; - } - - public void setSourcePaths(String[] sourcePaths) { - this.sourcePaths = sourcePaths; - } - - @Override - public String getSourceUri(int sourceReference) { - return this.sourceReferences.get(sourceReference); - } - - @Override - public int createSourceReference(String uri) { - return this.sourceReferences.create(uri); - } - - @Override - public RecyclableObjectPool getRecyclableIdPool() { - return this.recyclableIdPool; - } - - @Override - public void setRecyclableIdPool(RecyclableObjectPool idPool) { - this.recyclableIdPool = idPool; - } - - @Override - public IVariableFormatter getVariableFormatter() { - return this.variableFormatter; - } - - @Override - public void setVariableFormatter(IVariableFormatter variableFormatter) { - this.variableFormatter = variableFormatter; - } - - @Override - public Map getSourceLookupCache() { - return this.sourceMappingCache; - } - - @Override - public void setDebuggeeEncoding(Charset encoding) { - this.debuggeeEncoding = encoding; - } - - @Override - public Charset getDebuggeeEncoding() { - return this.debuggeeEncoding; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.nio.charset.Charset; +import java.util.Collections; +import java.util.Map; + +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.Events.DebugEvent; +import org.eclipse.jdt.ls.debug.adapter.variables.IVariableFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableFormatterFactory; + +public class DebugAdapterContext implements IDebugAdapterContext { + private static final int MAX_CACHE_ITEMS = 10000; + private Map sourceMappingCache = Collections.synchronizedMap(new LRUCache<>(MAX_CACHE_ITEMS)); + private DebugAdapter debugAdapter; + + private IDebugSession debugSession; + private boolean debuggerLinesStartAt1 = true; + private boolean debuggerPathsAreUri = true; + private boolean clientLinesStartAt1 = true; + private boolean clientPathsAreUri = false; + private boolean isAttached = false; + private String[] sourcePaths; + private Charset debuggeeEncoding; + + private IdCollection sourceReferences = new IdCollection<>(); + private RecyclableObjectPool recyclableIdPool = new RecyclableObjectPool<>(); + private IVariableFormatter variableFormatter = VariableFormatterFactory.createVariableFormatter(); + + public DebugAdapterContext(DebugAdapter debugAdapter) { + this.debugAdapter = debugAdapter; + } + + @Override + public void sendEvent(DebugEvent event) { + this.debugAdapter.sendEvent(event); + } + + @Override + public void sendEventAsync(DebugEvent event) { + this.debugAdapter.sendEventLater(event); + } + + @Override + public T getProvider(Class clazz) { + return this.debugAdapter.getProvider(clazz); + } + + @Override + public void setDebugSession(IDebugSession session) { + this.debugSession = session; + } + + @Override + public IDebugSession getDebugSession() { + return this.debugSession; + } + + @Override + public boolean isDebuggerLinesStartAt1() { + return this.debuggerLinesStartAt1; + } + + @Override + public void setDebuggerLinesStartAt1(boolean debuggerLinesStartAt1) { + this.debuggerLinesStartAt1 = debuggerLinesStartAt1; + } + + @Override + public boolean isDebuggerPathsAreUri() { + return this.debuggerPathsAreUri; + } + + @Override + public void setDebuggerPathsAreUri(boolean debuggerPathsAreUri) { + this.debuggerPathsAreUri = debuggerPathsAreUri; + } + + @Override + public boolean isClientLinesStartAt1() { + return this.clientLinesStartAt1; + } + + @Override + public void setClientLinesStartAt1(boolean clientLinesStartAt1) { + this.clientLinesStartAt1 = clientLinesStartAt1; + } + + @Override + public boolean isClientPathsAreUri() { + return this.clientPathsAreUri; + } + + @Override + public void setClientPathsAreUri(boolean clientPathsAreUri) { + this.clientPathsAreUri = clientPathsAreUri; + } + + @Override + public boolean isAttached() { + return this.isAttached; + } + + @Override + public void setAttached(boolean attached) { + this.isAttached = attached; + } + + public String[] getSourcePaths() { + return this.sourcePaths; + } + + public void setSourcePaths(String[] sourcePaths) { + this.sourcePaths = sourcePaths; + } + + @Override + public String getSourceUri(int sourceReference) { + return this.sourceReferences.get(sourceReference); + } + + @Override + public int createSourceReference(String uri) { + return this.sourceReferences.create(uri); + } + + @Override + public RecyclableObjectPool getRecyclableIdPool() { + return this.recyclableIdPool; + } + + @Override + public void setRecyclableIdPool(RecyclableObjectPool idPool) { + this.recyclableIdPool = idPool; + } + + @Override + public IVariableFormatter getVariableFormatter() { + return this.variableFormatter; + } + + @Override + public void setVariableFormatter(IVariableFormatter variableFormatter) { + this.variableFormatter = variableFormatter; + } + + @Override + public Map getSourceLookupCache() { + return this.sourceMappingCache; + } + + @Override + public void setDebuggeeEncoding(Charset encoding) { + this.debuggeeEncoding = encoding; + } + + @Override + public Charset getDebuggeeEncoding() { + return this.debuggeeEncoding; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/ErrorCode.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java index 7212f062b..640ac13f4 100644 --- a/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ErrorCode.java @@ -1,37 +1,37 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -public enum ErrorCode { - UNKNOWN_FAILURE(1000), - UNRECOGNIZED_REQUEST_FAILURE(1001), - LAUNCH_FAILURE(1002), - ATTACH_FAILURE(1003), - ARGUMENT_MISSING(1004), - SET_BREAKPOINT_FAILURE(1005), - SET_EXCEPTIONBREAKPOINT_FAILURE(1006), - GET_STACKTRACE_FAILURE(1007), - GET_VARIABLE_FAILURE(1008), - SET_VARIABLE_FAILURE(1009), - EVALUATE_FAILURE(1010), - EMPTY_DEBUG_SESSION(1011); - - private int id; - - ErrorCode(int id) { - this.id = id; - } - - public int getId() { - return this.id; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +public enum ErrorCode { + UNKNOWN_FAILURE(1000), + UNRECOGNIZED_REQUEST_FAILURE(1001), + LAUNCH_FAILURE(1002), + ATTACH_FAILURE(1003), + ARGUMENT_MISSING(1004), + SET_BREAKPOINT_FAILURE(1005), + SET_EXCEPTIONBREAKPOINT_FAILURE(1006), + GET_STACKTRACE_FAILURE(1007), + GET_VARIABLE_FAILURE(1008), + SET_VARIABLE_FAILURE(1009), + EVALUATE_FAILURE(1010), + EMPTY_DEBUG_SESSION(1011); + + private int id; + + ErrorCode(int id) { + this.id = id; + } + + public int getId() { + return this.id; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/Events.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Events.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/Events.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Events.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugAdapter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugAdapterContext.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IDebugRequestHandler.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IProvider.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IProvider.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IProvider.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IProviderContext.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IProviderContext.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IProviderContext.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IProviderContext.java diff --git a/org/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ISourceLookUpProvider.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IVirtualMachineManagerProvider.java diff --git a/org/eclipse/jdt/ls/debug/adapter/IdCollection.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IdCollection.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/IdCollection.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IdCollection.java index f29aa97c1..d0178e6a0 100644 --- a/org/eclipse/jdt/ls/debug/adapter/IdCollection.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/IdCollection.java @@ -1,79 +1,79 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.util.HashMap; -import java.util.concurrent.atomic.AtomicInteger; - -public class IdCollection { - private int startId; - private AtomicInteger nextId; - private HashMap idMap; - private HashMap reverseMap; - - public IdCollection() { - this(1); - } - - /** - * Constructs a new id generator with the given startId as the start id number. - * @param startId - * the start id number - */ - public IdCollection(int startId) { - this.startId = startId; - this.nextId = new AtomicInteger(startId); - this.idMap = new HashMap<>(); - this.reverseMap = new HashMap<>(); - } - - /** - * Reset the id to the initial start number. - */ - public void reset() { - this.nextId.set(this.startId); - this.idMap.clear(); - this.reverseMap.clear(); - } - - /** - * Create a new id if the id doesn't exist for the given value. - * Otherwise return the existing id. - */ - public int create(T value) { - if (this.reverseMap.containsKey(value)) { - return this.reverseMap.get(value); - } - int id = this.nextId.getAndIncrement(); - this.idMap.put(id, value); - this.reverseMap.put(value, id); - return id; - } - - /** - * Get the original value by the id. - */ - public T get(int id) { - return this.idMap.get(id); - } - - /** - * Remove the id from the id collection. - */ - public T remove(int id) { - T target = this.idMap.remove(id); - if (target != null) { - this.reverseMap.remove(target); - } - return target; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicInteger; + +public class IdCollection { + private int startId; + private AtomicInteger nextId; + private HashMap idMap; + private HashMap reverseMap; + + public IdCollection() { + this(1); + } + + /** + * Constructs a new id generator with the given startId as the start id number. + * @param startId + * the start id number + */ + public IdCollection(int startId) { + this.startId = startId; + this.nextId = new AtomicInteger(startId); + this.idMap = new HashMap<>(); + this.reverseMap = new HashMap<>(); + } + + /** + * Reset the id to the initial start number. + */ + public void reset() { + this.nextId.set(this.startId); + this.idMap.clear(); + this.reverseMap.clear(); + } + + /** + * Create a new id if the id doesn't exist for the given value. + * Otherwise return the existing id. + */ + public int create(T value) { + if (this.reverseMap.containsKey(value)) { + return this.reverseMap.get(value); + } + int id = this.nextId.getAndIncrement(); + this.idMap.put(id, value); + this.reverseMap.put(value, id); + return id; + } + + /** + * Get the original value by the id. + */ + public T get(int id) { + return this.idMap.get(id); + } + + /** + * Remove the id from the id collection. + */ + public T remove(int id) { + T target = this.idMap.remove(id); + if (target != null) { + this.reverseMap.remove(target); + } + return target; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/JsonUtils.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java index 69673da9a..f23b30ff1 100644 --- a/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/JsonUtils.java @@ -1,137 +1,137 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.lang.reflect.Type; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSyntaxException; - -public class JsonUtils { - private static final Gson GSON = new Gson(); - - public static T fromJson(String json, Class classOfT) throws JsonSyntaxException { - return GSON.fromJson(json, classOfT); - } - - public static T fromJson(String json, Type typeOfT) throws JsonSyntaxException { - return GSON.fromJson(json, typeOfT); - } - - public static T fromJson(JsonElement json, Class classOfT) throws JsonSyntaxException { - return GSON.fromJson(json, classOfT); - } - - public T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException { - return GSON.fromJson(json, typeOfT); - } - - public static String toJson(Object src) { - return GSON.toJson(src); - } - - public static String toJson(Object src, Type typeOfSrc) { - return GSON.toJson(src, typeOfSrc); - } - - /** - * Get the integer value for the specified property from the json Object. - * @param args - * the json object - * @param property - * the key - * @param defaultValue - * if key doesn't exist in the json object, then return the default value - * @return the value as an integer number - */ - public static int getInt(JsonObject args, String property, int defaultValue) { - try { - return args.getAsInt(); - } catch (Exception e) { - // ignore and return default value; - } - return defaultValue; - } - - /** - * Get the string value for the specified property from the json Object. - * @param args - * the json object - * @param property - * the key - * @param defaultValue - * if key doesn't exist in the json object, then return the default value - * @return the value as a string - */ - public static String getString(JsonObject args, String property, String defaultValue) { - String value = null; - try { - JsonElement obj = args.get(property); - value = obj.getAsString(); - } catch (Exception e) { - // ignore and return default value; - } - if (value == null) { - return defaultValue; - } - value = value.trim(); - if (value.length() == 0) { - return defaultValue; - } - return value; - } - - /** - * Get the boolean value for the specified property from the json Object. - * @param args - * the json object - * @param property - * the key - * @param defaultValue - * if key doesn't exist in the json object, then return the default value - * @return the value as boolean - */ - public static boolean getBoolean(JsonObject args, String property, boolean defaultValue) { - try { - JsonElement obj = args.get(property); - return obj.getAsBoolean(); - } catch (Exception e) { - // ignore and return default value; - } - return defaultValue; - } - - /** - * Extracts a list of property values from a json array object. - * @param args - * the json array element - * @param property - * the key - * @return an string array - */ - public static String[] getStringArray(JsonElement args, String property) { - if (args instanceof JsonArray) { - JsonArray array = (JsonArray) args; - int size = array.size(); - String[] result = new String[size]; - for (int i = 0; i < size; i++) { - result[i] = array.get(i).getAsString(); - } - return result; - } else { - return new String[0]; - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.lang.reflect.Type; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; + +public class JsonUtils { + private static final Gson GSON = new Gson(); + + public static T fromJson(String json, Class classOfT) throws JsonSyntaxException { + return GSON.fromJson(json, classOfT); + } + + public static T fromJson(String json, Type typeOfT) throws JsonSyntaxException { + return GSON.fromJson(json, typeOfT); + } + + public static T fromJson(JsonElement json, Class classOfT) throws JsonSyntaxException { + return GSON.fromJson(json, classOfT); + } + + public T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException { + return GSON.fromJson(json, typeOfT); + } + + public static String toJson(Object src) { + return GSON.toJson(src); + } + + public static String toJson(Object src, Type typeOfSrc) { + return GSON.toJson(src, typeOfSrc); + } + + /** + * Get the integer value for the specified property from the json Object. + * @param args + * the json object + * @param property + * the key + * @param defaultValue + * if key doesn't exist in the json object, then return the default value + * @return the value as an integer number + */ + public static int getInt(JsonObject args, String property, int defaultValue) { + try { + return args.getAsInt(); + } catch (Exception e) { + // ignore and return default value; + } + return defaultValue; + } + + /** + * Get the string value for the specified property from the json Object. + * @param args + * the json object + * @param property + * the key + * @param defaultValue + * if key doesn't exist in the json object, then return the default value + * @return the value as a string + */ + public static String getString(JsonObject args, String property, String defaultValue) { + String value = null; + try { + JsonElement obj = args.get(property); + value = obj.getAsString(); + } catch (Exception e) { + // ignore and return default value; + } + if (value == null) { + return defaultValue; + } + value = value.trim(); + if (value.length() == 0) { + return defaultValue; + } + return value; + } + + /** + * Get the boolean value for the specified property from the json Object. + * @param args + * the json object + * @param property + * the key + * @param defaultValue + * if key doesn't exist in the json object, then return the default value + * @return the value as boolean + */ + public static boolean getBoolean(JsonObject args, String property, boolean defaultValue) { + try { + JsonElement obj = args.get(property); + return obj.getAsBoolean(); + } catch (Exception e) { + // ignore and return default value; + } + return defaultValue; + } + + /** + * Extracts a list of property values from a json array object. + * @param args + * the json array element + * @param property + * the key + * @return an string array + */ + public static String[] getStringArray(JsonElement args, String property) { + if (args instanceof JsonArray) { + JsonArray array = (JsonArray) args; + int size = array.size(); + String[] result = new String[size]; + for (int i = 0; i < size; i++) { + result[i] = array.get(i).getAsString(); + } + return result; + } else { + return new String[0]; + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/LRUCache.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/LRUCache.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/LRUCache.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/LRUCache.java diff --git a/org/eclipse/jdt/ls/debug/adapter/Messages.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Messages.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/Messages.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Messages.java diff --git a/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java index 2b949c8cc..b4a1bea9f 100644 --- a/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProcessConsole.java @@ -1,119 +1,119 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -import io.reactivex.functions.Consumer; -import io.reactivex.subjects.PublishSubject; - -public class ProcessConsole { - private Process process; - private String name; - private Charset encoding; - private PublishSubject stdoutSubject = PublishSubject.create(); - private PublishSubject stderrSubject = PublishSubject.create(); - private Thread stdoutThread = null; - private Thread stderrThread = null; - - public ProcessConsole(Process process) { - this(process, "Process", StandardCharsets.UTF_8); - } - - /** - * Constructor. - * @param process - * the process - * @param name - * the process name - * @param encoding - * the process encoding format - */ - public ProcessConsole(Process process, String name, Charset encoding) { - this.process = process; - this.name = name; - this.encoding = encoding; - } - - /** - * Start two separate threads to monitor the messages from stdout and stderr streams of the target process. - */ - public void start() { - this.stdoutThread = new Thread(this.name + " Stdout Handler") { - public void run() { - monitor(process.getInputStream(), stdoutSubject); - } - }; - stdoutThread.setDaemon(true); - stdoutThread.start(); - - this.stderrThread = new Thread(this.name + " Stderr Handler") { - public void run() { - monitor(process.getErrorStream(), stderrSubject); - } - }; - stderrThread.setDaemon(true); - stderrThread.start(); - } - - /** - * Stop the process console handlers. - */ - public void stop() { - if (this.stdoutThread != null) { - this.stdoutThread.interrupt(); - this.stdoutThread = null; - } - - if (this.stderrThread != null) { - this.stderrThread.interrupt(); - this.stderrThread = null; - } - } - - public void onStdout(Consumer callback) { - stdoutSubject.subscribe(callback); - } - - public void onStderr(Consumer callback) { - stderrSubject.subscribe(callback); - } - - private void monitor(InputStream input, PublishSubject subject) { - BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding)); - final int BUFFERSIZE = 4096; - char[] buffer = new char[BUFFERSIZE]; - while (true) { - try { - if (Thread.interrupted()) { - subject.onComplete(); - return; - } - int read = reader.read(buffer, 0, BUFFERSIZE); - if (read == -1) { - subject.onComplete(); - return; - } - - subject.onNext(new String(buffer, 0, read)); - } catch (IOException e) { - subject.onError(e); - return; - } - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import io.reactivex.functions.Consumer; +import io.reactivex.subjects.PublishSubject; + +public class ProcessConsole { + private Process process; + private String name; + private Charset encoding; + private PublishSubject stdoutSubject = PublishSubject.create(); + private PublishSubject stderrSubject = PublishSubject.create(); + private Thread stdoutThread = null; + private Thread stderrThread = null; + + public ProcessConsole(Process process) { + this(process, "Process", StandardCharsets.UTF_8); + } + + /** + * Constructor. + * @param process + * the process + * @param name + * the process name + * @param encoding + * the process encoding format + */ + public ProcessConsole(Process process, String name, Charset encoding) { + this.process = process; + this.name = name; + this.encoding = encoding; + } + + /** + * Start two separate threads to monitor the messages from stdout and stderr streams of the target process. + */ + public void start() { + this.stdoutThread = new Thread(this.name + " Stdout Handler") { + public void run() { + monitor(process.getInputStream(), stdoutSubject); + } + }; + stdoutThread.setDaemon(true); + stdoutThread.start(); + + this.stderrThread = new Thread(this.name + " Stderr Handler") { + public void run() { + monitor(process.getErrorStream(), stderrSubject); + } + }; + stderrThread.setDaemon(true); + stderrThread.start(); + } + + /** + * Stop the process console handlers. + */ + public void stop() { + if (this.stdoutThread != null) { + this.stdoutThread.interrupt(); + this.stdoutThread = null; + } + + if (this.stderrThread != null) { + this.stderrThread.interrupt(); + this.stderrThread = null; + } + } + + public void onStdout(Consumer callback) { + stdoutSubject.subscribe(callback); + } + + public void onStderr(Consumer callback) { + stderrSubject.subscribe(callback); + } + + private void monitor(InputStream input, PublishSubject subject) { + BufferedReader reader = new BufferedReader(new InputStreamReader(input, encoding)); + final int BUFFERSIZE = 4096; + char[] buffer = new char[BUFFERSIZE]; + while (true) { + try { + if (Thread.interrupted()) { + subject.onComplete(); + return; + } + int read = reader.read(buffer, 0, BUFFERSIZE); + if (read == -1) { + subject.onComplete(); + return; + } + + subject.onNext(new String(buffer, 0, read)); + } catch (IOException e) { + subject.onError(e); + return; + } + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/ProtocolServer.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProtocolServer.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/ProtocolServer.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProtocolServer.java diff --git a/org/eclipse/jdt/ls/debug/adapter/ProviderContext.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProviderContext.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/ProviderContext.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/ProviderContext.java diff --git a/org/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/RecyclableObjectPool.java diff --git a/org/eclipse/jdt/ls/debug/adapter/Requests.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Requests.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/Requests.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Requests.java index 1744fbc08..178a8e366 100644 --- a/org/eclipse/jdt/ls/debug/adapter/Requests.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Requests.java @@ -1,211 +1,211 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter; - -import java.util.Arrays; - -/** - * The request arguments types defined by VSCode Debug Protocol. - */ -public class Requests { - - public static class ValueFormat { - public boolean hex; - } - - public static class Arguments { - - } - - public static class InitializeArguments extends Arguments { - public String clientID; - public String adapterID; - public String pathFormat; - public boolean linesStartAt1; - public boolean columnsStartAt1; - public boolean supportsVariableType; - public boolean supportsVariablePaging; - public boolean supportsRunInTerminalRequest; - } - - public static class LaunchArguments extends Arguments { - public String type; - public String name; - public String request; - public String projectName; - public String mainClass; - public String args = ""; - public String vmArgs = ""; - public String[] classPaths = new String[0]; - public String[] sourcePaths = new String[0]; - } - - public static class AttachArguments extends Arguments { - public String type; - public String name; - public String request; - public String hostName; - public int port; - public int timeout = 30000; // Default to 30s. - public String[] sourcePaths = new String[0]; - public String projectName; - } - - public static class RestartArguments extends Arguments { - - } - - public static class DisconnectArguments extends Arguments { - // If client doesn't set terminateDebuggee attribute at the DisconnectRequest, - // the debugger would choose to terminate debuggee by default. - public boolean terminateDebuggee = true; - public boolean restart; - } - - public static class ConfigurationDoneArguments extends Arguments { - - } - - public static class SetBreakpointArguments extends Arguments { - public Types.Source source; - public int[] lines = new int[0]; - public Types.SourceBreakpoint[] breakpoints = new Types.SourceBreakpoint[0]; - public boolean sourceModified = false; - } - - public static class StackTraceArguments extends Arguments { - public long threadId; - public int startFrame; - public int levels; - } - - public static class SetFunctionBreakpointsArguments extends Arguments { - public Types.FunctionBreakpoint[] breakpoints; - } - - public static class SetExceptionBreakpointsArguments extends Arguments { - public String[] filters = new String[0]; - } - - public static class ThreadsArguments extends Arguments { - - } - - public static class ContinueArguments extends Arguments { - public long threadId; - } - - public static class NextArguments extends Arguments { - public long threadId; - } - - public static class StepInArguments extends Arguments { - public long threadId; - public int targetId; - } - - public static class StepOutArguments extends Arguments { - public long threadId; - } - - public static class PauseArguments extends Arguments { - public long threadId; - } - - public static class ScopesArguments extends Arguments { - public int frameId; - } - - public static class VariablesArguments extends Arguments { - public int variablesReference = -1; - public String filter; - public int start; - public int count; - public ValueFormat format; - } - - public static class SetVariableArguments extends Arguments { - public int variablesReference; - public String name; - public String value; - public ValueFormat format; - } - - public static class SourceArguments extends Arguments { - public int sourceReference; - } - - public static class EvaluateArguments extends Arguments { - public String expression; - public int frameId; - public String context; - public ValueFormat format; - } - - public static enum Command { - INITIALIZE("initialize", InitializeArguments.class), - LAUNCH("launch", LaunchArguments.class), - ATTACH("attach", AttachArguments.class), - DISCONNECT("disconnect", DisconnectArguments.class), - CONFIGURATIONDONE("configurationDone", ConfigurationDoneArguments.class), - NEXT("next", NextArguments.class), - CONTINUE("continue", ContinueArguments.class), - STEPIN("stepIn", StepInArguments.class), - STEPOUT("stepOut", StepOutArguments.class), - PAUSE("pause", PauseArguments.class), - STACKTRACE("stackTrace", StackTraceArguments.class), - SCOPES("scopes", ScopesArguments.class), - VARIABLES("variables", VariablesArguments.class), - SETVARIABLE("setVariable", SetVariableArguments.class), - SOURCE("source", SourceArguments.class), - THREADS("threads", ThreadsArguments.class), - SETBREAKPOINTS("setBreakpoints", SetBreakpointArguments.class), - SETEXCEPTIONBREAKPOINTS("setExceptionBreakpoints", SetExceptionBreakpointsArguments.class), - SETFUNCTIONBREAKPOINTS("setFunctionBreakpoints", SetFunctionBreakpointsArguments.class), - EVALUATE("evaluate", EvaluateArguments.class), - UNSUPPORTED("", Arguments.class); - - private String command; - private Class argumentType; - - Command(String command, Class argumentType) { - this.command = command; - this.argumentType = argumentType; - } - - public String toString() { - return this.command; - } - - public Class getArgumentType() { - return this.argumentType; - } - - /** - * Get the corresponding Command type by the command name. - * If the command is not defined in the enum type, return UNSUPPORTED. - * @param command - * the command name - * @return the Command type - */ - public static Command parse(String command) { - Command[] found = Arrays.stream(Command.values()).filter(cmd -> { - return cmd.toString().equals(command); - }).toArray(Command[]::new); - - if (found.length > 0) { - return found[0]; - } - return UNSUPPORTED; - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter; + +import java.util.Arrays; + +/** + * The request arguments types defined by VSCode Debug Protocol. + */ +public class Requests { + + public static class ValueFormat { + public boolean hex; + } + + public static class Arguments { + + } + + public static class InitializeArguments extends Arguments { + public String clientID; + public String adapterID; + public String pathFormat; + public boolean linesStartAt1; + public boolean columnsStartAt1; + public boolean supportsVariableType; + public boolean supportsVariablePaging; + public boolean supportsRunInTerminalRequest; + } + + public static class LaunchArguments extends Arguments { + public String type; + public String name; + public String request; + public String projectName; + public String mainClass; + public String args = ""; + public String vmArgs = ""; + public String[] classPaths = new String[0]; + public String[] sourcePaths = new String[0]; + } + + public static class AttachArguments extends Arguments { + public String type; + public String name; + public String request; + public String hostName; + public int port; + public int timeout = 30000; // Default to 30s. + public String[] sourcePaths = new String[0]; + public String projectName; + } + + public static class RestartArguments extends Arguments { + + } + + public static class DisconnectArguments extends Arguments { + // If client doesn't set terminateDebuggee attribute at the DisconnectRequest, + // the debugger would choose to terminate debuggee by default. + public boolean terminateDebuggee = true; + public boolean restart; + } + + public static class ConfigurationDoneArguments extends Arguments { + + } + + public static class SetBreakpointArguments extends Arguments { + public Types.Source source; + public int[] lines = new int[0]; + public Types.SourceBreakpoint[] breakpoints = new Types.SourceBreakpoint[0]; + public boolean sourceModified = false; + } + + public static class StackTraceArguments extends Arguments { + public long threadId; + public int startFrame; + public int levels; + } + + public static class SetFunctionBreakpointsArguments extends Arguments { + public Types.FunctionBreakpoint[] breakpoints; + } + + public static class SetExceptionBreakpointsArguments extends Arguments { + public String[] filters = new String[0]; + } + + public static class ThreadsArguments extends Arguments { + + } + + public static class ContinueArguments extends Arguments { + public long threadId; + } + + public static class NextArguments extends Arguments { + public long threadId; + } + + public static class StepInArguments extends Arguments { + public long threadId; + public int targetId; + } + + public static class StepOutArguments extends Arguments { + public long threadId; + } + + public static class PauseArguments extends Arguments { + public long threadId; + } + + public static class ScopesArguments extends Arguments { + public int frameId; + } + + public static class VariablesArguments extends Arguments { + public int variablesReference = -1; + public String filter; + public int start; + public int count; + public ValueFormat format; + } + + public static class SetVariableArguments extends Arguments { + public int variablesReference; + public String name; + public String value; + public ValueFormat format; + } + + public static class SourceArguments extends Arguments { + public int sourceReference; + } + + public static class EvaluateArguments extends Arguments { + public String expression; + public int frameId; + public String context; + public ValueFormat format; + } + + public static enum Command { + INITIALIZE("initialize", InitializeArguments.class), + LAUNCH("launch", LaunchArguments.class), + ATTACH("attach", AttachArguments.class), + DISCONNECT("disconnect", DisconnectArguments.class), + CONFIGURATIONDONE("configurationDone", ConfigurationDoneArguments.class), + NEXT("next", NextArguments.class), + CONTINUE("continue", ContinueArguments.class), + STEPIN("stepIn", StepInArguments.class), + STEPOUT("stepOut", StepOutArguments.class), + PAUSE("pause", PauseArguments.class), + STACKTRACE("stackTrace", StackTraceArguments.class), + SCOPES("scopes", ScopesArguments.class), + VARIABLES("variables", VariablesArguments.class), + SETVARIABLE("setVariable", SetVariableArguments.class), + SOURCE("source", SourceArguments.class), + THREADS("threads", ThreadsArguments.class), + SETBREAKPOINTS("setBreakpoints", SetBreakpointArguments.class), + SETEXCEPTIONBREAKPOINTS("setExceptionBreakpoints", SetExceptionBreakpointsArguments.class), + SETFUNCTIONBREAKPOINTS("setFunctionBreakpoints", SetFunctionBreakpointsArguments.class), + EVALUATE("evaluate", EvaluateArguments.class), + UNSUPPORTED("", Arguments.class); + + private String command; + private Class argumentType; + + Command(String command, Class argumentType) { + this.command = command; + this.argumentType = argumentType; + } + + public String toString() { + return this.command; + } + + public Class getArgumentType() { + return this.argumentType; + } + + /** + * Get the corresponding Command type by the command name. + * If the command is not defined in the enum type, return UNSUPPORTED. + * @param command + * the command name + * @return the Command type + */ + public static Command parse(String command) { + Command[] found = Arrays.stream(Command.values()).filter(cmd -> { + return cmd.toString().equals(command); + }).toArray(Command[]::new); + + if (found.length > 0) { + return found[0]; + } + return UNSUPPORTED; + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/Responses.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Responses.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/Responses.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Responses.java diff --git a/org/eclipse/jdt/ls/debug/adapter/Types.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Types.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/Types.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/Types.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ArrayObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/BooleanFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/CharacterFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ClassObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/IFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ITypeFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/IValueFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NullObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatEnum.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/NumericFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/ObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/SimpleTypeFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/StringObjectFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/formatter/TypeIdentifiers.java diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java index 3f3e73607..43e5858e5 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/AttachRequestHandler.java @@ -1,70 +1,70 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.eclipse.jdt.ls.debug.DebugUtility; -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.Constants; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.IVirtualMachineManagerProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.AttachArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.internal.Logger; - -import com.sun.jdi.connect.IllegalConnectorArgumentsException; - -public class AttachRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.ATTACH); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - AttachArguments attachArguments = (AttachArguments) arguments; - context.setAttached(true); - context.setSourcePaths(attachArguments.sourcePaths); - - IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class); - ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); - if (attachArguments.projectName != null) { - Map options = sourceProvider.getDefaultOptions(); - options.put(Constants.PROJECTNAME, attachArguments.projectName); - sourceProvider.initialize(options); - } - - try { - Logger.logInfo(String.format("Trying to attach to remote debuggee VM %s:%d .", - attachArguments.hostName, attachArguments.port)); - IDebugSession debugSession = DebugUtility.attach(vmProvider.getVirtualMachineManager(), - attachArguments.hostName, attachArguments.port, attachArguments.timeout); - context.setDebugSession(debugSession); - Logger.logInfo("Attaching to debuggee VM succeeded."); - } catch (IOException | IllegalConnectorArgumentsException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.ATTACH_FAILURE, - String.format("Failed to attach to remote debuggee VM. Reason: %s", e.toString())); - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.eclipse.jdt.ls.debug.DebugUtility; +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.Constants; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.IVirtualMachineManagerProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.AttachArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.internal.Logger; + +import com.sun.jdi.connect.IllegalConnectorArgumentsException; + +public class AttachRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.ATTACH); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + AttachArguments attachArguments = (AttachArguments) arguments; + context.setAttached(true); + context.setSourcePaths(attachArguments.sourcePaths); + + IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class); + ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); + if (attachArguments.projectName != null) { + Map options = sourceProvider.getDefaultOptions(); + options.put(Constants.PROJECTNAME, attachArguments.projectName); + sourceProvider.initialize(options); + } + + try { + Logger.logInfo(String.format("Trying to attach to remote debuggee VM %s:%d .", + attachArguments.hostName, attachArguments.port)); + IDebugSession debugSession = DebugUtility.attach(vmProvider.getVirtualMachineManager(), + attachArguments.hostName, attachArguments.port, attachArguments.timeout); + context.setDebugSession(debugSession); + Logger.logInfo("Attaching to debuggee VM succeeded."); + } catch (IOException | IllegalConnectorArgumentsException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.ATTACH_FAILURE, + String.format("Failed to attach to remote debuggee VM. Reason: %s", e.toString())); + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java index 9473e17e6..e19e54c5b 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ConfigurationDoneRequestHandler.java @@ -1,98 +1,98 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.DebugEvent; -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.Events; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; - -import com.sun.jdi.ThreadReference; -import com.sun.jdi.event.BreakpointEvent; -import com.sun.jdi.event.Event; -import com.sun.jdi.event.ExceptionEvent; -import com.sun.jdi.event.StepEvent; -import com.sun.jdi.event.ThreadDeathEvent; -import com.sun.jdi.event.ThreadStartEvent; -import com.sun.jdi.event.VMDeathEvent; -import com.sun.jdi.event.VMDisconnectEvent; -import com.sun.jdi.event.VMStartEvent; - -public class ConfigurationDoneRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.CONFIGURATIONDONE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - IDebugSession debugSession = context.getDebugSession(); - if (debugSession != null) { - // This is a global event handler to handle the JDI Event from Virtual Machine. - debugSession.eventHub().events().subscribe(debugEvent -> { - handleDebugEvent(debugEvent, debugSession, context); - }); - // configuration is done, and start debug session. - debugSession.start(); - } else { - context.sendEventAsync(new Events.TerminatedEvent()); - AdapterUtils.setErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Failed to launch debug session, the debugger will exit."); - } - } - - private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession, IDebugAdapterContext context) { - Event event = debugEvent.event; - if (event instanceof VMStartEvent) { - // do nothing. - } else if (event instanceof VMDeathEvent) { - context.sendEventAsync(new Events.ExitedEvent(0)); - } else if (event instanceof VMDisconnectEvent) { - context.sendEventAsync(new Events.TerminatedEvent()); - // Terminate eventHub thread. - try { - debugSession.eventHub().close(); - } catch (Exception e) { - // do nothing. - } - } else if (event instanceof ThreadStartEvent) { - ThreadReference startThread = ((ThreadStartEvent) event).thread(); - Events.ThreadEvent threadEvent = new Events.ThreadEvent("started", startThread.uniqueID()); - context.sendEventAsync(threadEvent); - } else if (event instanceof ThreadDeathEvent) { - ThreadReference deathThread = ((ThreadDeathEvent) event).thread(); - Events.ThreadEvent threadDeathEvent = new Events.ThreadEvent("exited", deathThread.uniqueID()); - context.sendEventAsync(threadDeathEvent); - } else if (event instanceof BreakpointEvent) { - ThreadReference bpThread = ((BreakpointEvent) event).thread(); - context.sendEventAsync(new Events.StoppedEvent("breakpoint", bpThread.uniqueID())); - debugEvent.shouldResume = false; - } else if (event instanceof StepEvent) { - ThreadReference stepThread = ((StepEvent) event).thread(); - context.sendEventAsync(new Events.StoppedEvent("step", stepThread.uniqueID())); - debugEvent.shouldResume = false; - } else if (event instanceof ExceptionEvent) { - ThreadReference thread = ((ExceptionEvent) event).thread(); - context.sendEventAsync(new Events.StoppedEvent("exception", thread.uniqueID())); - debugEvent.shouldResume = false; - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.DebugEvent; +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.Events; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; + +import com.sun.jdi.ThreadReference; +import com.sun.jdi.event.BreakpointEvent; +import com.sun.jdi.event.Event; +import com.sun.jdi.event.ExceptionEvent; +import com.sun.jdi.event.StepEvent; +import com.sun.jdi.event.ThreadDeathEvent; +import com.sun.jdi.event.ThreadStartEvent; +import com.sun.jdi.event.VMDeathEvent; +import com.sun.jdi.event.VMDisconnectEvent; +import com.sun.jdi.event.VMStartEvent; + +public class ConfigurationDoneRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.CONFIGURATIONDONE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + IDebugSession debugSession = context.getDebugSession(); + if (debugSession != null) { + // This is a global event handler to handle the JDI Event from Virtual Machine. + debugSession.eventHub().events().subscribe(debugEvent -> { + handleDebugEvent(debugEvent, debugSession, context); + }); + // configuration is done, and start debug session. + debugSession.start(); + } else { + context.sendEventAsync(new Events.TerminatedEvent()); + AdapterUtils.setErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Failed to launch debug session, the debugger will exit."); + } + } + + private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession, IDebugAdapterContext context) { + Event event = debugEvent.event; + if (event instanceof VMStartEvent) { + // do nothing. + } else if (event instanceof VMDeathEvent) { + context.sendEventAsync(new Events.ExitedEvent(0)); + } else if (event instanceof VMDisconnectEvent) { + context.sendEventAsync(new Events.TerminatedEvent()); + // Terminate eventHub thread. + try { + debugSession.eventHub().close(); + } catch (Exception e) { + // do nothing. + } + } else if (event instanceof ThreadStartEvent) { + ThreadReference startThread = ((ThreadStartEvent) event).thread(); + Events.ThreadEvent threadEvent = new Events.ThreadEvent("started", startThread.uniqueID()); + context.sendEventAsync(threadEvent); + } else if (event instanceof ThreadDeathEvent) { + ThreadReference deathThread = ((ThreadDeathEvent) event).thread(); + Events.ThreadEvent threadDeathEvent = new Events.ThreadEvent("exited", deathThread.uniqueID()); + context.sendEventAsync(threadDeathEvent); + } else if (event instanceof BreakpointEvent) { + ThreadReference bpThread = ((BreakpointEvent) event).thread(); + context.sendEventAsync(new Events.StoppedEvent("breakpoint", bpThread.uniqueID())); + debugEvent.shouldResume = false; + } else if (event instanceof StepEvent) { + ThreadReference stepThread = ((StepEvent) event).thread(); + context.sendEventAsync(new Events.StoppedEvent("step", stepThread.uniqueID())); + debugEvent.shouldResume = false; + } else if (event instanceof ExceptionEvent) { + ThreadReference thread = ((ExceptionEvent) event).thread(); + context.sendEventAsync(new Events.StoppedEvent("exception", thread.uniqueID())); + debugEvent.shouldResume = false; + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java index 26caf9c29..edb264b22 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/DisconnectRequestHandler.java @@ -1,45 +1,45 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.DisconnectArguments; - -public class DisconnectRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.DISCONNECT); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - DisconnectArguments disconnectArguments = (DisconnectArguments) arguments; - IDebugSession debugSession = context.getDebugSession(); - if (debugSession != null) { - if (disconnectArguments.terminateDebuggee && !context.isAttached()) { - debugSession.terminate(); - } else { - debugSession.detach(); - } - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.DisconnectArguments; + +public class DisconnectRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.DISCONNECT); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + DisconnectArguments disconnectArguments = (DisconnectArguments) arguments; + IDebugSession debugSession = context.getDebugSession(); + if (debugSession != null) { + if (disconnectArguments.terminateDebuggee && !context.isAttached()) { + debugSession.terminate(); + } else { + debugSession.detach(); + } + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java index 55c315817..703f3329f 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/EvaluateRequestHandler.java @@ -1,188 +1,188 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.EvaluateArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; -import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.Variable; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.ArrayReference; -import com.sun.jdi.Field; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.PrimitiveValue; -import com.sun.jdi.StackFrame; -import com.sun.jdi.ThreadReference; -import com.sun.jdi.Value; - -public class EvaluateRequestHandler implements IDebugRequestHandler { - private final Pattern simpleExprPattern = Pattern.compile("[A-Za-z0-9_.\\s]+"); - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.EVALUATE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - EvaluateArguments evalArguments = (EvaluateArguments) arguments; - if (StringUtils.isBlank(evalArguments.expression)) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "EvaluateRequest: property 'expression' is missing, null, or empty"); - return; - } - - // This should be false by default(currently true for test). - // User will need to explicitly turn it on by configuring launch.json - final boolean showStaticVariables = true; - // TODO: when vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. - boolean showFullyQualifiedNames = true; - Map options = context.getVariableFormatter().getDefaultOptions(); - if (evalArguments.format != null && evalArguments.format.hex) { - options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); - } - if (showFullyQualifiedNames) { - options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); - } - String expression = evalArguments.expression; - - if (StringUtils.isBlank(expression)) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Empty expression cannot be evaluated."); - return; - } - - if (!simpleExprPattern.matcher(expression).matches()) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - "Failed to evaluate. Reason: Complex expression is not supported currently."); - return; - } - - JdiObjectProxy stackFrameProxy = (JdiObjectProxy) context.getRecyclableIdPool().getObjectById(evalArguments.frameId); - if (stackFrameProxy == null) { - // stackFrameProxy is null means the stackframe is continued by user manually, - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Cannot evaluate because the thread is resumed."); - return; - } - - // split a.b.c => ["a", "b", "c"] - List referenceExpressions = Arrays.stream(StringUtils.split(expression, '.')) - .filter(StringUtils::isNotBlank).map(StringUtils::trim).collect(Collectors.toList()); - - // get first level of value from stack frame - Variable firstLevelValue = null; - boolean inStaticMethod = stackFrameProxy.getProxiedObject().location().method().isStatic(); - String firstExpression = referenceExpressions.get(0); - // handle special case of 'this' - if (firstExpression.equals("this") && !inStaticMethod) { - firstLevelValue = VariableUtils.getThisVariable(stackFrameProxy.getProxiedObject()); - } - if (firstLevelValue == null) { - try { - // local variables first, that means - // if both local variable and static variable are found, use local variable - List localVariables = VariableUtils.listLocalVariables(stackFrameProxy.getProxiedObject()); - List matchedLocal = localVariables.stream() - .filter(localVariable -> localVariable.name.equals(firstExpression)).collect(Collectors.toList()); - if (!matchedLocal.isEmpty()) { - firstLevelValue = matchedLocal.get(0); - } else { - List staticVariables = VariableUtils.listStaticVariables(stackFrameProxy.getProxiedObject()); - List matchedStatic = staticVariables.stream() - .filter(staticVariable -> staticVariable.name.equals(firstExpression)).collect(Collectors.toList()); - if (matchedStatic.isEmpty()) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find the variable: %s.", referenceExpressions.get(0))); - return; - } - firstLevelValue = matchedStatic.get(0); - } - - } catch (AbsentInformationException e) { - // ignore - } - } - - if (firstLevelValue == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find variable with name '%s'.", referenceExpressions.get(0))); - return; - } - ThreadReference thread = stackFrameProxy.getProxiedObject().thread(); - Value currentValue = firstLevelValue.value; - - for (int i = 1; i < referenceExpressions.size(); i++) { - String fieldName = referenceExpressions.get(i); - if (currentValue == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Evaluation encounters NPE error."); - return; - } - if (currentValue instanceof PrimitiveValue) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); - return; - } - if (currentValue instanceof ArrayReference) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Evaluating array elements is not supported currently.", fieldName)); - return; - } - ObjectReference obj = (ObjectReference) currentValue; - Field field = obj.referenceType().fieldByName(fieldName); - if (field == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); - return; - } - if (field.isStatic()) { - AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, - String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); - return; - } - currentValue = obj.getValue(field); - } - - int referenceId = 0; - if (currentValue instanceof ObjectReference && VariableUtils.hasChildren(currentValue, showStaticVariables)) { - // save the evaluated value in object pool, because like java.lang.String, the evaluated object will have sub structures - // we need to set up the id map. - VariableProxy varProxy = new VariableProxy(thread.uniqueID(), "Local", (ObjectReference) currentValue); - referenceId = context.getRecyclableIdPool().addObject(thread.uniqueID(), varProxy); - } - int indexedVariables = 0; - if (currentValue instanceof ArrayReference) { - indexedVariables = ((ArrayReference) currentValue).length(); - } - response.body = new Responses.EvaluateResponseBody(context.getVariableFormatter().valueToString(currentValue, options), - referenceId, context.getVariableFormatter().typeToString(currentValue == null ? null : currentValue.type(), options), - indexedVariables); - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.EvaluateArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; +import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.Variable; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.ArrayReference; +import com.sun.jdi.Field; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.PrimitiveValue; +import com.sun.jdi.StackFrame; +import com.sun.jdi.ThreadReference; +import com.sun.jdi.Value; + +public class EvaluateRequestHandler implements IDebugRequestHandler { + private final Pattern simpleExprPattern = Pattern.compile("[A-Za-z0-9_.\\s]+"); + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.EVALUATE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + EvaluateArguments evalArguments = (EvaluateArguments) arguments; + if (StringUtils.isBlank(evalArguments.expression)) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + "EvaluateRequest: property 'expression' is missing, null, or empty"); + return; + } + + // This should be false by default(currently true for test). + // User will need to explicitly turn it on by configuring launch.json + final boolean showStaticVariables = true; + // TODO: when vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. + boolean showFullyQualifiedNames = true; + Map options = context.getVariableFormatter().getDefaultOptions(); + if (evalArguments.format != null && evalArguments.format.hex) { + options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); + } + if (showFullyQualifiedNames) { + options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); + } + String expression = evalArguments.expression; + + if (StringUtils.isBlank(expression)) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Empty expression cannot be evaluated."); + return; + } + + if (!simpleExprPattern.matcher(expression).matches()) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + "Failed to evaluate. Reason: Complex expression is not supported currently."); + return; + } + + JdiObjectProxy stackFrameProxy = (JdiObjectProxy) context.getRecyclableIdPool().getObjectById(evalArguments.frameId); + if (stackFrameProxy == null) { + // stackFrameProxy is null means the stackframe is continued by user manually, + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Cannot evaluate because the thread is resumed."); + return; + } + + // split a.b.c => ["a", "b", "c"] + List referenceExpressions = Arrays.stream(StringUtils.split(expression, '.')) + .filter(StringUtils::isNotBlank).map(StringUtils::trim).collect(Collectors.toList()); + + // get first level of value from stack frame + Variable firstLevelValue = null; + boolean inStaticMethod = stackFrameProxy.getProxiedObject().location().method().isStatic(); + String firstExpression = referenceExpressions.get(0); + // handle special case of 'this' + if (firstExpression.equals("this") && !inStaticMethod) { + firstLevelValue = VariableUtils.getThisVariable(stackFrameProxy.getProxiedObject()); + } + if (firstLevelValue == null) { + try { + // local variables first, that means + // if both local variable and static variable are found, use local variable + List localVariables = VariableUtils.listLocalVariables(stackFrameProxy.getProxiedObject()); + List matchedLocal = localVariables.stream() + .filter(localVariable -> localVariable.name.equals(firstExpression)).collect(Collectors.toList()); + if (!matchedLocal.isEmpty()) { + firstLevelValue = matchedLocal.get(0); + } else { + List staticVariables = VariableUtils.listStaticVariables(stackFrameProxy.getProxiedObject()); + List matchedStatic = staticVariables.stream() + .filter(staticVariable -> staticVariable.name.equals(firstExpression)).collect(Collectors.toList()); + if (matchedStatic.isEmpty()) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find the variable: %s.", referenceExpressions.get(0))); + return; + } + firstLevelValue = matchedStatic.get(0); + } + + } catch (AbsentInformationException e) { + // ignore + } + } + + if (firstLevelValue == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find variable with name '%s'.", referenceExpressions.get(0))); + return; + } + ThreadReference thread = stackFrameProxy.getProxiedObject().thread(); + Value currentValue = firstLevelValue.value; + + for (int i = 1; i < referenceExpressions.size(); i++) { + String fieldName = referenceExpressions.get(i); + if (currentValue == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Evaluation encounters NPE error."); + return; + } + if (currentValue instanceof PrimitiveValue) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); + return; + } + if (currentValue instanceof ArrayReference) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Evaluating array elements is not supported currently.", fieldName)); + return; + } + ObjectReference obj = (ObjectReference) currentValue; + Field field = obj.referenceType().fieldByName(fieldName); + if (field == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); + return; + } + if (field.isStatic()) { + AdapterUtils.setErrorResponse(response, ErrorCode.EVALUATE_FAILURE, + String.format("Failed to evaluate. Reason: Cannot find the field: %s.", fieldName)); + return; + } + currentValue = obj.getValue(field); + } + + int referenceId = 0; + if (currentValue instanceof ObjectReference && VariableUtils.hasChildren(currentValue, showStaticVariables)) { + // save the evaluated value in object pool, because like java.lang.String, the evaluated object will have sub structures + // we need to set up the id map. + VariableProxy varProxy = new VariableProxy(thread.uniqueID(), "Local", (ObjectReference) currentValue); + referenceId = context.getRecyclableIdPool().addObject(thread.uniqueID(), varProxy); + } + int indexedVariables = 0; + if (currentValue instanceof ArrayReference) { + indexedVariables = ((ArrayReference) currentValue).length(); + } + response.body = new Responses.EvaluateResponseBody(context.getVariableFormatter().valueToString(currentValue, options), + referenceId, context.getVariableFormatter().typeToString(currentValue == null ? null : currentValue.type(), options), + indexedVariables); + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/InitializeRequestHandler.java diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java index 62236e843..3b3eb31f3 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/LaunchRequestHandler.java @@ -1,96 +1,96 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.ls.debug.DebugUtility; -import org.eclipse.jdt.ls.debug.IDebugSession; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.Constants; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.Events; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.IVirtualMachineManagerProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.ProcessConsole; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.LaunchArguments; -import org.eclipse.jdt.ls.debug.internal.Logger; - -import com.sun.jdi.connect.IllegalConnectorArgumentsException; -import com.sun.jdi.connect.VMStartException; - -public class LaunchRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.LAUNCH); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - LaunchArguments launchArguments = (LaunchArguments) arguments; - if (StringUtils.isBlank(launchArguments.mainClass) || launchArguments.classPaths == null - || launchArguments.classPaths.length == 0) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - String.format("Failed to launch debuggee VM. Missing mainClass or classPath options in launch configuration")); - return; - } - - context.setAttached(false); - context.setSourcePaths(launchArguments.sourcePaths); - // TODO Currently the debuggee console just supports UTF-8 format. - // In future, we could let user to specify the debuggee encoding in launch.json. - context.setDebuggeeEncoding(StandardCharsets.UTF_8); - - IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class); - ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); - if (launchArguments.projectName != null) { - Map options = sourceProvider.getDefaultOptions(); - options.put(Constants.PROJECTNAME, launchArguments.projectName); - sourceProvider.initialize(options); - } - - try { - Logger.logInfo(String.format("Trying to launch Java Program with options \"%s -cp %s %s %s\" .", - launchArguments.vmArgs, launchArguments.classPaths, launchArguments.mainClass, launchArguments.args)); - IDebugSession debugSession = DebugUtility.launch(vmProvider.getVirtualMachineManager(), - launchArguments.mainClass, launchArguments.args, launchArguments.vmArgs, Arrays.asList(launchArguments.classPaths)); - context.setDebugSession(debugSession); - Logger.logInfo("Launching debuggee VM succeeded."); - - ProcessConsole debuggeeConsole = new ProcessConsole(debugSession.process(), "Debuggee", context.getDebuggeeEncoding()); - debuggeeConsole.onStdout((output) -> { - // When DA receives a new OutputEvent, it just shows that on Debug Console and doesn't affect the DA's dispatching workflow. - // That means the debugger can send OutputEvent to DA at any time. - context.sendEvent(Events.OutputEvent.createStdoutOutput(output)); - }); - - debuggeeConsole.onStderr((err) -> { - context.sendEvent(Events.OutputEvent.createStderrOutput(err)); - }); - debuggeeConsole.start(); - } catch (IOException | IllegalConnectorArgumentsException | VMStartException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.LAUNCH_FAILURE, - String.format("Failed to launch debuggee VM. Reason: %s", e.toString())); - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.ls.debug.DebugUtility; +import org.eclipse.jdt.ls.debug.IDebugSession; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.Constants; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.Events; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.IVirtualMachineManagerProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.ProcessConsole; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.LaunchArguments; +import org.eclipse.jdt.ls.debug.internal.Logger; + +import com.sun.jdi.connect.IllegalConnectorArgumentsException; +import com.sun.jdi.connect.VMStartException; + +public class LaunchRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.LAUNCH); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + LaunchArguments launchArguments = (LaunchArguments) arguments; + if (StringUtils.isBlank(launchArguments.mainClass) || launchArguments.classPaths == null + || launchArguments.classPaths.length == 0) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + String.format("Failed to launch debuggee VM. Missing mainClass or classPath options in launch configuration")); + return; + } + + context.setAttached(false); + context.setSourcePaths(launchArguments.sourcePaths); + // TODO Currently the debuggee console just supports UTF-8 format. + // In future, we could let user to specify the debuggee encoding in launch.json. + context.setDebuggeeEncoding(StandardCharsets.UTF_8); + + IVirtualMachineManagerProvider vmProvider = context.getProvider(IVirtualMachineManagerProvider.class); + ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); + if (launchArguments.projectName != null) { + Map options = sourceProvider.getDefaultOptions(); + options.put(Constants.PROJECTNAME, launchArguments.projectName); + sourceProvider.initialize(options); + } + + try { + Logger.logInfo(String.format("Trying to launch Java Program with options \"%s -cp %s %s %s\" .", + launchArguments.vmArgs, launchArguments.classPaths, launchArguments.mainClass, launchArguments.args)); + IDebugSession debugSession = DebugUtility.launch(vmProvider.getVirtualMachineManager(), + launchArguments.mainClass, launchArguments.args, launchArguments.vmArgs, Arrays.asList(launchArguments.classPaths)); + context.setDebugSession(debugSession); + Logger.logInfo("Launching debuggee VM succeeded."); + + ProcessConsole debuggeeConsole = new ProcessConsole(debugSession.process(), "Debuggee", context.getDebuggeeEncoding()); + debuggeeConsole.onStdout((output) -> { + // When DA receives a new OutputEvent, it just shows that on Debug Console and doesn't affect the DA's dispatching workflow. + // That means the debugger can send OutputEvent to DA at any time. + context.sendEvent(Events.OutputEvent.createStdoutOutput(output)); + }); + + debuggeeConsole.onStderr((err) -> { + context.sendEvent(Events.OutputEvent.createStderrOutput(err)); + }); + debuggeeConsole.start(); + } catch (IOException | IllegalConnectorArgumentsException | VMStartException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.LAUNCH_FAILURE, + String.format("Failed to launch debuggee VM. Reason: %s", e.toString())); + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java index 90acf56a5..2590d35c2 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ScopesRequestHandler.java @@ -1,55 +1,55 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.ScopesArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; -import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; - -import com.sun.jdi.StackFrame; - -public class ScopesRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SCOPES); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - ScopesArguments scopesArgs = (ScopesArguments) arguments; - List scopes = new ArrayList<>(); - JdiObjectProxy stackFrameProxy = (JdiObjectProxy) context.getRecyclableIdPool().getObjectById(scopesArgs.frameId); - if (stackFrameProxy == null) { - response.body = new Responses.ScopesResponseBody(scopes); - return; - } - StackFrame stackFrame = stackFrameProxy.getProxiedObject(); - VariableProxy localScope = new VariableProxy(stackFrame.thread().uniqueID(), "Local", stackFrame); - int localScopeId = context.getRecyclableIdPool().addObject(stackFrame.thread().uniqueID(), localScope); - scopes.add(new Types.Scope(localScope.getScope(), localScopeId, false)); - - response.body = new Responses.ScopesResponseBody(scopes); - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.ScopesArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; +import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; + +import com.sun.jdi.StackFrame; + +public class ScopesRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SCOPES); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + ScopesArguments scopesArgs = (ScopesArguments) arguments; + List scopes = new ArrayList<>(); + JdiObjectProxy stackFrameProxy = (JdiObjectProxy) context.getRecyclableIdPool().getObjectById(scopesArgs.frameId); + if (stackFrameProxy == null) { + response.body = new Responses.ScopesResponseBody(scopes); + return; + } + StackFrame stackFrame = stackFrameProxy.getProxiedObject(); + VariableProxy localScope = new VariableProxy(stackFrame.thread().uniqueID(), "Local", stackFrame); + int localScopeId = context.getRecyclableIdPool().addObject(stackFrame.thread().uniqueID(), localScope); + scopes.add(new Types.Scope(localScope.getScope(), localScopeId, false)); + + response.body = new Responses.ScopesResponseBody(scopes); + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java index 0dfde1d2f..1c0e56c26 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetBreakpointsRequestHandler.java @@ -1,126 +1,126 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.ls.debug.DebugException; -import org.eclipse.jdt.ls.debug.IBreakpoint; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.BreakpointManager; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.Events; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.SetBreakpointArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; - -public class SetBreakpointsRequestHandler implements IDebugRequestHandler { - private BreakpointManager manager = new BreakpointManager(); - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SETBREAKPOINTS); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - SetBreakpointArguments bpArguments = (SetBreakpointArguments) arguments; - String clientPath = bpArguments.source.path; - if (AdapterUtils.isWindows()) { - // VSCode may send drive letters with inconsistent casing which will mess up the key - // in the BreakpointManager. See https://github.com/Microsoft/vscode/issues/6268 - // Normalize the drive letter casing. Note that drive letters - // are not localized so invariant is safe here. - String drivePrefix = FilenameUtils.getPrefix(clientPath); - if (drivePrefix != null && drivePrefix.length() >= 2 - && Character.isLowerCase(drivePrefix.charAt(0)) && drivePrefix.charAt(1) == ':') { - drivePrefix = drivePrefix.substring(0, 2); // d:\ is an illegal regex string, convert it to d: - clientPath = clientPath.replaceFirst(drivePrefix, drivePrefix.toUpperCase()); - } - } - String sourcePath = clientPath; - if (bpArguments.source.sourceReference != 0 && context.getSourceUri(bpArguments.source.sourceReference) != null) { - sourcePath = context.getSourceUri(bpArguments.source.sourceReference); - } else { - sourcePath = AdapterUtils.convertPath(clientPath, context.isClientPathsAreUri(), context.isDebuggerPathsAreUri()); - } - - // When breakpoint source path is null or an invalid file path, send an ErrorResponse back. - if (sourcePath == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE, - String.format("Failed to setBreakpoint. Reason: '%s' is an invalid path.", bpArguments.source.path)); - return; - } - try { - List res = new ArrayList<>(); - IBreakpoint[] toAdds = this.convertClientBreakpointsToDebugger(sourcePath, bpArguments.breakpoints, context); - IBreakpoint[] added = manager.setBreakpoints(sourcePath, toAdds, bpArguments.sourceModified); - for (int i = 0; i < bpArguments.breakpoints.length; i++) { - // For newly added breakpoint, should install it to debuggee first. - if (toAdds[i] == added[i] && added[i].className() != null) { - added[i].install().thenAccept(bp -> { - Events.BreakpointEvent bpEvent = new Events.BreakpointEvent("new", this.convertDebuggerBreakpointToClient(bp, context)); - context.sendEventAsync(bpEvent); - }); - } else if (toAdds[i].hitCount() != added[i].hitCount() && added[i].className() != null) { - // Update hitCount condition. - added[i].setHitCount(toAdds[i].hitCount()); - } - res.add(this.convertDebuggerBreakpointToClient(added[i], context)); - } - response.body = new Responses.SetBreakpointsResponseBody(res); - } catch (DebugException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE, String.format("Failed to setBreakpoint. Reason: '%s'", e.toString())); - } - } - - private Types.Breakpoint convertDebuggerBreakpointToClient(IBreakpoint breakpoint, IDebugAdapterContext context) { - int id = (int) breakpoint.getProperty("id"); - boolean verified = breakpoint.getProperty("verified") != null && (boolean) breakpoint.getProperty("verified"); - int lineNumber = AdapterUtils.convertLineNumber(breakpoint.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1()); - return new Types.Breakpoint(id, verified, lineNumber, ""); - } - - private IBreakpoint[] convertClientBreakpointsToDebugger(String sourceFile, Types.SourceBreakpoint[] sourceBreakpoints, IDebugAdapterContext context) - throws DebugException { - int[] lines = Arrays.asList(sourceBreakpoints).stream().map(sourceBreakpoint -> { - return AdapterUtils.convertLineNumber(sourceBreakpoint.line, context.isClientLinesStartAt1(), context.isDebuggerLinesStartAt1()); - }).mapToInt(line -> line).toArray(); - ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); - String[] fqns = sourceProvider.getFullyQualifiedName(sourceFile, lines, null); - IBreakpoint[] breakpoints = new IBreakpoint[lines.length]; - for (int i = 0; i < lines.length; i++) { - int hitCount = 0; - try { - hitCount = Integer.parseInt(sourceBreakpoints[i].hitCondition); - } catch (NumberFormatException e) { - hitCount = 0; // If hitCount is an illegal number, ignore hitCount condition. - } - breakpoints[i] = context.getDebugSession().createBreakpoint(fqns[i], lines[i], hitCount); - if (sourceProvider.supportsRealtimeBreakpointVerification() && StringUtils.isNotBlank(fqns[i])) { - breakpoints[i].putProperty("verified", true); - } - } - return breakpoints; - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.ls.debug.DebugException; +import org.eclipse.jdt.ls.debug.IBreakpoint; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.BreakpointManager; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.Events; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.SetBreakpointArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; + +public class SetBreakpointsRequestHandler implements IDebugRequestHandler { + private BreakpointManager manager = new BreakpointManager(); + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SETBREAKPOINTS); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + SetBreakpointArguments bpArguments = (SetBreakpointArguments) arguments; + String clientPath = bpArguments.source.path; + if (AdapterUtils.isWindows()) { + // VSCode may send drive letters with inconsistent casing which will mess up the key + // in the BreakpointManager. See https://github.com/Microsoft/vscode/issues/6268 + // Normalize the drive letter casing. Note that drive letters + // are not localized so invariant is safe here. + String drivePrefix = FilenameUtils.getPrefix(clientPath); + if (drivePrefix != null && drivePrefix.length() >= 2 + && Character.isLowerCase(drivePrefix.charAt(0)) && drivePrefix.charAt(1) == ':') { + drivePrefix = drivePrefix.substring(0, 2); // d:\ is an illegal regex string, convert it to d: + clientPath = clientPath.replaceFirst(drivePrefix, drivePrefix.toUpperCase()); + } + } + String sourcePath = clientPath; + if (bpArguments.source.sourceReference != 0 && context.getSourceUri(bpArguments.source.sourceReference) != null) { + sourcePath = context.getSourceUri(bpArguments.source.sourceReference); + } else { + sourcePath = AdapterUtils.convertPath(clientPath, context.isClientPathsAreUri(), context.isDebuggerPathsAreUri()); + } + + // When breakpoint source path is null or an invalid file path, send an ErrorResponse back. + if (sourcePath == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE, + String.format("Failed to setBreakpoint. Reason: '%s' is an invalid path.", bpArguments.source.path)); + return; + } + try { + List res = new ArrayList<>(); + IBreakpoint[] toAdds = this.convertClientBreakpointsToDebugger(sourcePath, bpArguments.breakpoints, context); + IBreakpoint[] added = manager.setBreakpoints(sourcePath, toAdds, bpArguments.sourceModified); + for (int i = 0; i < bpArguments.breakpoints.length; i++) { + // For newly added breakpoint, should install it to debuggee first. + if (toAdds[i] == added[i] && added[i].className() != null) { + added[i].install().thenAccept(bp -> { + Events.BreakpointEvent bpEvent = new Events.BreakpointEvent("new", this.convertDebuggerBreakpointToClient(bp, context)); + context.sendEventAsync(bpEvent); + }); + } else if (toAdds[i].hitCount() != added[i].hitCount() && added[i].className() != null) { + // Update hitCount condition. + added[i].setHitCount(toAdds[i].hitCount()); + } + res.add(this.convertDebuggerBreakpointToClient(added[i], context)); + } + response.body = new Responses.SetBreakpointsResponseBody(res); + } catch (DebugException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_BREAKPOINT_FAILURE, String.format("Failed to setBreakpoint. Reason: '%s'", e.toString())); + } + } + + private Types.Breakpoint convertDebuggerBreakpointToClient(IBreakpoint breakpoint, IDebugAdapterContext context) { + int id = (int) breakpoint.getProperty("id"); + boolean verified = breakpoint.getProperty("verified") != null && (boolean) breakpoint.getProperty("verified"); + int lineNumber = AdapterUtils.convertLineNumber(breakpoint.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1()); + return new Types.Breakpoint(id, verified, lineNumber, ""); + } + + private IBreakpoint[] convertClientBreakpointsToDebugger(String sourceFile, Types.SourceBreakpoint[] sourceBreakpoints, IDebugAdapterContext context) + throws DebugException { + int[] lines = Arrays.asList(sourceBreakpoints).stream().map(sourceBreakpoint -> { + return AdapterUtils.convertLineNumber(sourceBreakpoint.line, context.isClientLinesStartAt1(), context.isDebuggerLinesStartAt1()); + }).mapToInt(line -> line).toArray(); + ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); + String[] fqns = sourceProvider.getFullyQualifiedName(sourceFile, lines, null); + IBreakpoint[] breakpoints = new IBreakpoint[lines.length]; + for (int i = 0; i < lines.length; i++) { + int hitCount = 0; + try { + hitCount = Integer.parseInt(sourceBreakpoints[i].hitCondition); + } catch (NumberFormatException e) { + hitCount = 0; // If hitCount is an illegal number, ignore hitCount condition. + } + breakpoints[i] = context.getDebugSession().createBreakpoint(fqns[i], lines[i], hitCount); + if (sourceProvider.supportsRealtimeBreakpointVerification() && StringUtils.isNotBlank(fqns[i])) { + breakpoints[i].putProperty("verified", true); + } + } + return breakpoints; + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java index a4b06b119..c3ef43f24 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetExceptionBreakpointsRequestHandler.java @@ -1,49 +1,49 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.lang3.ArrayUtils; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.SetExceptionBreakpointsArguments; -import org.eclipse.jdt.ls.debug.adapter.Types; - -public class SetExceptionBreakpointsRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SETEXCEPTIONBREAKPOINTS); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - String[] filters = ((SetExceptionBreakpointsArguments) arguments).filters; - try { - boolean notifyCaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.CAUGHT_EXCEPTION_FILTER_NAME); - boolean notifyUncaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.UNCAUGHT_EXCEPTION_FILTER_NAME); - - context.getDebugSession().setExceptionBreakpoints(notifyCaught, notifyUncaught); - } catch (Exception ex) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_EXCEPTIONBREAKPOINT_FAILURE, - String.format("Failed to setExceptionBreakpoints. Reason: '%s'", ex.toString())); - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.lang3.ArrayUtils; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.SetExceptionBreakpointsArguments; +import org.eclipse.jdt.ls.debug.adapter.Types; + +public class SetExceptionBreakpointsRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SETEXCEPTIONBREAKPOINTS); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + String[] filters = ((SetExceptionBreakpointsArguments) arguments).filters; + try { + boolean notifyCaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.CAUGHT_EXCEPTION_FILTER_NAME); + boolean notifyUncaught = ArrayUtils.contains(filters, Types.ExceptionBreakpointFilter.UNCAUGHT_EXCEPTION_FILTER_NAME); + + context.getDebugSession().setExceptionBreakpoints(notifyCaught, notifyUncaught); + } catch (Exception ex) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_EXCEPTIONBREAKPOINT_FAILURE, + String.format("Failed to setExceptionBreakpoints. Reason: '%s'", ex.toString())); + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java index 70f3d0dc5..2693a51bf 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SetVariableRequestHandler.java @@ -1,264 +1,264 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.SetVariableArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; -import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.ArrayReference; -import com.sun.jdi.ArrayType; -import com.sun.jdi.ClassNotLoadedException; -import com.sun.jdi.ClassType; -import com.sun.jdi.Field; -import com.sun.jdi.InvalidTypeException; -import com.sun.jdi.LocalVariable; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.ReferenceType; -import com.sun.jdi.StackFrame; -import com.sun.jdi.Type; -import com.sun.jdi.TypeComponent; -import com.sun.jdi.Value; - -public class SetVariableRequestHandler implements IDebugRequestHandler { - private static final String PATTERN = "([a-zA-Z_0-9$]+)\\s*\\(([^)]+)\\)"; - private IDebugAdapterContext context = null; - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SETVARIABLE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - SetVariableArguments setVarArguments = (SetVariableArguments) arguments; - if (setVarArguments.value == null) { - // Just exit out of editing if we're given an empty expression. - return; - } else if (setVarArguments.variablesReference == -1) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "SetVariablesRequest: property 'variablesReference' is missing, null, or empty"); - return; - } else if (StringUtils.isBlank(setVarArguments.name)) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "SetVariablesRequest: property 'name' is missing, null, or empty"); - return; - } - - this.context = context; - Map options = context.getVariableFormatter().getDefaultOptions(); - // This should be false by default(currently true for test). - // User will need to explicitly turn it on by configuring launch.json - boolean showStaticVariables = true; - // TODO: when vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. - boolean showFullyQualifiedNames = true; - if (setVarArguments.format != null && setVarArguments.format.hex) { - options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); - } - if (showFullyQualifiedNames) { - options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); - } - - Object container = context.getRecyclableIdPool().getObjectById(setVarArguments.variablesReference); - // container is null means the stack frame is continued by user manually. - if (container == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, - "Failed to set variable. Reason: Cannot set value because the thread is resumed."); - return; - } - - String name = setVarArguments.name; - Value newValue; - String belongToClass = null; - - if (setVarArguments.name.contains("(")) { - name = setVarArguments.name.replaceFirst(PATTERN, "$1"); - belongToClass = setVarArguments.name.replaceFirst(PATTERN, "$2"); - } - - Object containerObj = ((VariableProxy) container).getProxiedVariable(); - try { - if (containerObj instanceof StackFrame) { - newValue = handleSetValueForStackFrame(name, belongToClass, setVarArguments.value, - showStaticVariables, (StackFrame) containerObj, options); - } else if (containerObj instanceof ObjectReference) { - newValue = handleSetValueForObject(name, belongToClass, setVarArguments.value, - (ObjectReference) containerObj, options); - } else { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, - String.format("SetVariableRequest: Variable %s cannot be found.", setVarArguments.variablesReference)); - return; - } - } catch (IllegalArgumentException | AbsentInformationException | InvalidTypeException - | UnsupportedOperationException | ClassNotLoadedException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, - String.format("Failed to set variable. Reason: %s", e.toString())); - return; - } - int referenceId = 0; - if (newValue instanceof ObjectReference && VariableUtils.hasChildren(newValue, showStaticVariables)) { - long threadId = ((VariableProxy) container).getThreadId(); - String scopeName = ((VariableProxy) container).getScope(); - VariableProxy varProxy = new VariableProxy(threadId, scopeName, (ObjectReference) newValue); - referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy); - } - - int indexedVariables = 0; - if (newValue instanceof ArrayReference) { - indexedVariables = ((ArrayReference) newValue).length(); - } - response.body = new Responses.SetVariablesResponseBody( - context.getVariableFormatter().typeToString(newValue == null ? null : newValue.type(), options), // type - context.getVariableFormatter().valueToString(newValue, options), // value, - referenceId, indexedVariables); - } - - private Value handleSetValueForObject(String name, String belongToClass, String valueString, - ObjectReference container, Map options) throws InvalidTypeException, ClassNotLoadedException { - Value newValue; - if (container instanceof ArrayReference) { - ArrayReference array = (ArrayReference) container; - Type eleType = ((ArrayType) array.referenceType()).componentType(); - newValue = setArrayValue(array, eleType, Integer.parseInt(name), valueString, options); - } else { - if (StringUtils.isBlank(belongToClass)) { - Field field = container.referenceType().fieldByName(name); - if (field != null) { - if (field.isStatic()) { - newValue = this.setStaticFieldValue(container.referenceType(), field, name, valueString, options); - } else { - newValue = this.setObjectFieldValue(container, field, name, valueString, options); - } - } else { - throw new IllegalArgumentException( - String.format("SetVariableRequest: Variable %s cannot be found.", name)); - } - } else { - newValue = setFieldValueWithConflict(container, container.referenceType().allFields(), name, belongToClass, valueString, options); - } - } - return newValue; - } - - private Value handleSetValueForStackFrame(String name, String belongToClass, String valueString, - boolean showStaticVariables, StackFrame container, Map options) - throws AbsentInformationException, InvalidTypeException, ClassNotLoadedException { - Value newValue; - if (name.equals("this")) { - throw new UnsupportedOperationException("SetVariableRequest: 'This' variable cannot be changed."); - } - LocalVariable variable = container.visibleVariableByName(name); - if (StringUtils.isBlank(belongToClass) && variable != null) { - newValue = this.setFrameValue(container, variable, valueString, options); - } else { - if (showStaticVariables && container.location().method().isStatic()) { - ReferenceType type = container.location().declaringType(); - if (StringUtils.isBlank(belongToClass)) { - Field field = type.fieldByName(name); - newValue = setStaticFieldValue(type, field, name, valueString, options); - } else { - newValue = setFieldValueWithConflict(null, type.allFields(), name, belongToClass, - valueString, options); - } - } else { - throw new UnsupportedOperationException( - String.format("SetVariableRequest: Variable %s cannot be found.", name)); - } - } - return newValue; - } - - private Value setValueProxy(Type type, String value, SetValueFunction setValueFunc, Map options) - throws ClassNotLoadedException, InvalidTypeException { - Value newValue = context.getVariableFormatter().stringToValue(value, type, options); - setValueFunc.apply(newValue); - return newValue; - } - - private Value setStaticFieldValue(Type declaringType, Field field, String name, String value, Map options) - throws ClassNotLoadedException, InvalidTypeException { - if (field.isFinal()) { - throw new UnsupportedOperationException( - String.format("SetVariableRequest: Final field %s cannot be changed.", name)); - } - if (!(declaringType instanceof ClassType)) { - throw new UnsupportedOperationException( - String.format("SetVariableRequest: Field %s in interface cannot be changed.", name)); - } - return setValueProxy(field.type(), value, newValue -> ((ClassType) declaringType).setValue(field, newValue), options); - } - - private Value setFrameValue(StackFrame frame, LocalVariable localVariable, String value, Map options) - throws ClassNotLoadedException, InvalidTypeException { - return setValueProxy(localVariable.type(), value, newValue -> frame.setValue(localVariable, newValue), options); - } - - private Value setObjectFieldValue(ObjectReference obj, Field field, String name, String value, Map options) - throws ClassNotLoadedException, InvalidTypeException { - if (field.isFinal()) { - throw new UnsupportedOperationException( - String.format("SetVariableRequest: Final field %s cannot be changed.", name)); - } - return setValueProxy(field.type(), value, newValue -> obj.setValue(field, newValue), options); - } - - private Value setArrayValue(ArrayReference array, Type eleType, int index, String value, Map options) - throws ClassNotLoadedException, InvalidTypeException { - return setValueProxy(eleType, value, newValue -> array.setValue(index, newValue), options); - } - - private Value setFieldValueWithConflict(ObjectReference obj, List fields, String name, String belongToClass, - String value, Map options) throws ClassNotLoadedException, InvalidTypeException { - Field field; - // first try to resolve field by fully qualified name - List narrowedFields = fields.stream().filter(TypeComponent::isStatic) - .filter(t -> t.name().equals(name) && t.declaringType().name().equals(belongToClass)) - .collect(Collectors.toList()); - if (narrowedFields.isEmpty()) { - // second try to resolve field by formatted name - narrowedFields = fields.stream().filter(TypeComponent::isStatic) - .filter(t -> t.name().equals(name) - && context.getVariableFormatter().typeToString(t.declaringType(), options).equals(belongToClass)) - .collect(Collectors.toList()); - } - if (narrowedFields.size() == 1) { - field = narrowedFields.get(0); - } else { - throw new UnsupportedOperationException(String.format("SetVariableRequest: Name conflicted for %s.", name)); - } - return field.isStatic() ? setStaticFieldValue(field.declaringType(), field, name, value, options) - : this.setObjectFieldValue(obj, field, name, value, options); - } - - @FunctionalInterface - interface SetValueFunction { - void apply(Value value) throws InvalidTypeException, ClassNotLoadedException; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.SetVariableArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; +import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.ArrayReference; +import com.sun.jdi.ArrayType; +import com.sun.jdi.ClassNotLoadedException; +import com.sun.jdi.ClassType; +import com.sun.jdi.Field; +import com.sun.jdi.InvalidTypeException; +import com.sun.jdi.LocalVariable; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.ReferenceType; +import com.sun.jdi.StackFrame; +import com.sun.jdi.Type; +import com.sun.jdi.TypeComponent; +import com.sun.jdi.Value; + +public class SetVariableRequestHandler implements IDebugRequestHandler { + private static final String PATTERN = "([a-zA-Z_0-9$]+)\\s*\\(([^)]+)\\)"; + private IDebugAdapterContext context = null; + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SETVARIABLE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + SetVariableArguments setVarArguments = (SetVariableArguments) arguments; + if (setVarArguments.value == null) { + // Just exit out of editing if we're given an empty expression. + return; + } else if (setVarArguments.variablesReference == -1) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + "SetVariablesRequest: property 'variablesReference' is missing, null, or empty"); + return; + } else if (StringUtils.isBlank(setVarArguments.name)) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + "SetVariablesRequest: property 'name' is missing, null, or empty"); + return; + } + + this.context = context; + Map options = context.getVariableFormatter().getDefaultOptions(); + // This should be false by default(currently true for test). + // User will need to explicitly turn it on by configuring launch.json + boolean showStaticVariables = true; + // TODO: when vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. + boolean showFullyQualifiedNames = true; + if (setVarArguments.format != null && setVarArguments.format.hex) { + options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); + } + if (showFullyQualifiedNames) { + options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); + } + + Object container = context.getRecyclableIdPool().getObjectById(setVarArguments.variablesReference); + // container is null means the stack frame is continued by user manually. + if (container == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, + "Failed to set variable. Reason: Cannot set value because the thread is resumed."); + return; + } + + String name = setVarArguments.name; + Value newValue; + String belongToClass = null; + + if (setVarArguments.name.contains("(")) { + name = setVarArguments.name.replaceFirst(PATTERN, "$1"); + belongToClass = setVarArguments.name.replaceFirst(PATTERN, "$2"); + } + + Object containerObj = ((VariableProxy) container).getProxiedVariable(); + try { + if (containerObj instanceof StackFrame) { + newValue = handleSetValueForStackFrame(name, belongToClass, setVarArguments.value, + showStaticVariables, (StackFrame) containerObj, options); + } else if (containerObj instanceof ObjectReference) { + newValue = handleSetValueForObject(name, belongToClass, setVarArguments.value, + (ObjectReference) containerObj, options); + } else { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, + String.format("SetVariableRequest: Variable %s cannot be found.", setVarArguments.variablesReference)); + return; + } + } catch (IllegalArgumentException | AbsentInformationException | InvalidTypeException + | UnsupportedOperationException | ClassNotLoadedException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE, + String.format("Failed to set variable. Reason: %s", e.toString())); + return; + } + int referenceId = 0; + if (newValue instanceof ObjectReference && VariableUtils.hasChildren(newValue, showStaticVariables)) { + long threadId = ((VariableProxy) container).getThreadId(); + String scopeName = ((VariableProxy) container).getScope(); + VariableProxy varProxy = new VariableProxy(threadId, scopeName, (ObjectReference) newValue); + referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy); + } + + int indexedVariables = 0; + if (newValue instanceof ArrayReference) { + indexedVariables = ((ArrayReference) newValue).length(); + } + response.body = new Responses.SetVariablesResponseBody( + context.getVariableFormatter().typeToString(newValue == null ? null : newValue.type(), options), // type + context.getVariableFormatter().valueToString(newValue, options), // value, + referenceId, indexedVariables); + } + + private Value handleSetValueForObject(String name, String belongToClass, String valueString, + ObjectReference container, Map options) throws InvalidTypeException, ClassNotLoadedException { + Value newValue; + if (container instanceof ArrayReference) { + ArrayReference array = (ArrayReference) container; + Type eleType = ((ArrayType) array.referenceType()).componentType(); + newValue = setArrayValue(array, eleType, Integer.parseInt(name), valueString, options); + } else { + if (StringUtils.isBlank(belongToClass)) { + Field field = container.referenceType().fieldByName(name); + if (field != null) { + if (field.isStatic()) { + newValue = this.setStaticFieldValue(container.referenceType(), field, name, valueString, options); + } else { + newValue = this.setObjectFieldValue(container, field, name, valueString, options); + } + } else { + throw new IllegalArgumentException( + String.format("SetVariableRequest: Variable %s cannot be found.", name)); + } + } else { + newValue = setFieldValueWithConflict(container, container.referenceType().allFields(), name, belongToClass, valueString, options); + } + } + return newValue; + } + + private Value handleSetValueForStackFrame(String name, String belongToClass, String valueString, + boolean showStaticVariables, StackFrame container, Map options) + throws AbsentInformationException, InvalidTypeException, ClassNotLoadedException { + Value newValue; + if (name.equals("this")) { + throw new UnsupportedOperationException("SetVariableRequest: 'This' variable cannot be changed."); + } + LocalVariable variable = container.visibleVariableByName(name); + if (StringUtils.isBlank(belongToClass) && variable != null) { + newValue = this.setFrameValue(container, variable, valueString, options); + } else { + if (showStaticVariables && container.location().method().isStatic()) { + ReferenceType type = container.location().declaringType(); + if (StringUtils.isBlank(belongToClass)) { + Field field = type.fieldByName(name); + newValue = setStaticFieldValue(type, field, name, valueString, options); + } else { + newValue = setFieldValueWithConflict(null, type.allFields(), name, belongToClass, + valueString, options); + } + } else { + throw new UnsupportedOperationException( + String.format("SetVariableRequest: Variable %s cannot be found.", name)); + } + } + return newValue; + } + + private Value setValueProxy(Type type, String value, SetValueFunction setValueFunc, Map options) + throws ClassNotLoadedException, InvalidTypeException { + Value newValue = context.getVariableFormatter().stringToValue(value, type, options); + setValueFunc.apply(newValue); + return newValue; + } + + private Value setStaticFieldValue(Type declaringType, Field field, String name, String value, Map options) + throws ClassNotLoadedException, InvalidTypeException { + if (field.isFinal()) { + throw new UnsupportedOperationException( + String.format("SetVariableRequest: Final field %s cannot be changed.", name)); + } + if (!(declaringType instanceof ClassType)) { + throw new UnsupportedOperationException( + String.format("SetVariableRequest: Field %s in interface cannot be changed.", name)); + } + return setValueProxy(field.type(), value, newValue -> ((ClassType) declaringType).setValue(field, newValue), options); + } + + private Value setFrameValue(StackFrame frame, LocalVariable localVariable, String value, Map options) + throws ClassNotLoadedException, InvalidTypeException { + return setValueProxy(localVariable.type(), value, newValue -> frame.setValue(localVariable, newValue), options); + } + + private Value setObjectFieldValue(ObjectReference obj, Field field, String name, String value, Map options) + throws ClassNotLoadedException, InvalidTypeException { + if (field.isFinal()) { + throw new UnsupportedOperationException( + String.format("SetVariableRequest: Final field %s cannot be changed.", name)); + } + return setValueProxy(field.type(), value, newValue -> obj.setValue(field, newValue), options); + } + + private Value setArrayValue(ArrayReference array, Type eleType, int index, String value, Map options) + throws ClassNotLoadedException, InvalidTypeException { + return setValueProxy(eleType, value, newValue -> array.setValue(index, newValue), options); + } + + private Value setFieldValueWithConflict(ObjectReference obj, List fields, String name, String belongToClass, + String value, Map options) throws ClassNotLoadedException, InvalidTypeException { + Field field; + // first try to resolve field by fully qualified name + List narrowedFields = fields.stream().filter(TypeComponent::isStatic) + .filter(t -> t.name().equals(name) && t.declaringType().name().equals(belongToClass)) + .collect(Collectors.toList()); + if (narrowedFields.isEmpty()) { + // second try to resolve field by formatted name + narrowedFields = fields.stream().filter(TypeComponent::isStatic) + .filter(t -> t.name().equals(name) + && context.getVariableFormatter().typeToString(t.declaringType(), options).equals(belongToClass)) + .collect(Collectors.toList()); + } + if (narrowedFields.size() == 1) { + field = narrowedFields.get(0); + } else { + throw new UnsupportedOperationException(String.format("SetVariableRequest: Name conflicted for %s.", name)); + } + return field.isStatic() ? setStaticFieldValue(field.declaringType(), field, name, value, options) + : this.setObjectFieldValue(obj, field, name, value, options); + } + + @FunctionalInterface + interface SetValueFunction { + void apply(Value value) throws InvalidTypeException, ClassNotLoadedException; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java index 8d3755367..fda779a42 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/SourceRequestHandler.java @@ -1,48 +1,48 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.SourceArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; - -public class SourceRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.SOURCE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - int sourceReference = ((SourceArguments) arguments).sourceReference; - if (sourceReference <= 0) { - AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, - "SourceRequest: property 'sourceReference' is missing, null, or empty"); - } else { - String uri = context.getSourceUri(sourceReference); - ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); - response.body = new Responses.SourceResponseBody(sourceProvider.getSourceContents(uri)); - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.SourceArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; + +public class SourceRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.SOURCE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + int sourceReference = ((SourceArguments) arguments).sourceReference; + if (sourceReference <= 0) { + AdapterUtils.setErrorResponse(response, ErrorCode.ARGUMENT_MISSING, + "SourceRequest: property 'sourceReference' is missing, null, or empty"); + } else { + String uri = context.getSourceUri(sourceReference); + ISourceLookUpProvider sourceProvider = context.getProvider(ISourceLookUpProvider.class); + response.body = new Responses.SourceResponseBody(sourceProvider.getSourceContents(uri)); + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java similarity index 98% rename from org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java index 08de6e8a1..245b35b4f 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/StackTraceRequestHandler.java @@ -1,130 +1,130 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.DebugUtility; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.StackTraceArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; -import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.IncompatibleThreadStateException; -import com.sun.jdi.Location; -import com.sun.jdi.Method; -import com.sun.jdi.StackFrame; -import com.sun.jdi.ThreadReference; - -public class StackTraceRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.STACKTRACE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - StackTraceArguments stacktraceArgs = (StackTraceArguments) arguments; - List result = new ArrayList<>(); - if (stacktraceArgs.startFrame < 0 || stacktraceArgs.levels < 0) { - response.body = new Responses.StackTraceResponseBody(result, 0); - return; - } - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), stacktraceArgs.threadId); - int totalFrames = 0; - if (thread != null) { - try { - totalFrames = thread.frameCount(); - if (totalFrames <= stacktraceArgs.startFrame) { - response.body = new Responses.StackTraceResponseBody(result, totalFrames); - return; - } - List stackFrames = stacktraceArgs.levels == 0 - ? thread.frames(stacktraceArgs.startFrame, totalFrames - stacktraceArgs.startFrame) - : thread.frames(stacktraceArgs.startFrame, - Math.min(totalFrames - stacktraceArgs.startFrame, stacktraceArgs.levels)); - for (int i = 0; i < stackFrames.size(); i++) { - StackFrame stackFrame = stackFrames.get(i); - int frameId = context.getRecyclableIdPool().addObject(stackFrame.thread().uniqueID(), - new JdiObjectProxy<>(stackFrame)); - Types.StackFrame clientStackFrame = convertDebuggerStackFrameToClient(stackFrame, frameId, context); - result.add(clientStackFrame); - } - } catch (IncompatibleThreadStateException | IndexOutOfBoundsException | URISyntaxException | AbsentInformationException e) { - // do nothing. - } - } - response.body = new Responses.StackTraceResponseBody(result, totalFrames); - } - - private Types.StackFrame convertDebuggerStackFrameToClient(StackFrame stackFrame, int frameId, IDebugAdapterContext context) - throws URISyntaxException, AbsentInformationException { - Location location = stackFrame.location(); - Method method = location.method(); - Types.Source clientSource = this.convertDebuggerSourceToClient(location, context); - String methodName = method.name(); - int lineNumber = AdapterUtils.convertLineNumber(location.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1()); - if (lineNumber < 0 && method.isNative()) { - // When the current stack frame stops at a native method, the line number is -1. - // Display a tip text "native method" in the Call Stack View. - methodName += "[native method]"; - } - return new Types.StackFrame(frameId, methodName, clientSource, lineNumber, 0); - } - - private Types.Source convertDebuggerSourceToClient(Location location, IDebugAdapterContext context) throws URISyntaxException { - final String fullyQualifiedName = location.declaringType().name(); - String sourceName = ""; - String relativeSourcePath = ""; - try { - // When the .class file doesn't contain source information in meta data, - // invoking Location#sourceName() would throw AbsentInformationException. - sourceName = location.sourceName(); - relativeSourcePath = location.sourcePath(); - } catch (AbsentInformationException e) { - String enclosingType = AdapterUtils.parseEnclosingType(fullyQualifiedName); - sourceName = enclosingType.substring(enclosingType.lastIndexOf('.') + 1) + ".java"; - relativeSourcePath = enclosingType.replace('.', '/') + ".java"; - } - - final String finalRelativeSourcePath = relativeSourcePath; - // use a lru cache for better performance - String uri = context.getSourceLookupCache().computeIfAbsent(fullyQualifiedName, key -> - context.getProvider(ISourceLookUpProvider.class).getSourceFileURI(key, finalRelativeSourcePath) - ); - - if (uri != null) { - String clientPath = AdapterUtils.convertPath(uri, context.isDebuggerPathsAreUri(), context.isClientPathsAreUri()); - if (uri.startsWith("file:")) { - return new Types.Source(sourceName, clientPath, 0); - } else { - return new Types.Source(sourceName, clientPath, context.createSourceReference(uri)); - } - } else { - // If the source lookup engine cannot find the source file, then lookup it in the source directories specified by user. - String absoluteSourcepath = AdapterUtils.sourceLookup(context.getSourcePaths(), relativeSourcePath); - return new Types.Source(sourceName, absoluteSourcepath, 0); - } - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.DebugUtility; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.ISourceLookUpProvider; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.StackTraceArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; +import org.eclipse.jdt.ls.debug.adapter.variables.JdiObjectProxy; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.IncompatibleThreadStateException; +import com.sun.jdi.Location; +import com.sun.jdi.Method; +import com.sun.jdi.StackFrame; +import com.sun.jdi.ThreadReference; + +public class StackTraceRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.STACKTRACE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + StackTraceArguments stacktraceArgs = (StackTraceArguments) arguments; + List result = new ArrayList<>(); + if (stacktraceArgs.startFrame < 0 || stacktraceArgs.levels < 0) { + response.body = new Responses.StackTraceResponseBody(result, 0); + return; + } + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), stacktraceArgs.threadId); + int totalFrames = 0; + if (thread != null) { + try { + totalFrames = thread.frameCount(); + if (totalFrames <= stacktraceArgs.startFrame) { + response.body = new Responses.StackTraceResponseBody(result, totalFrames); + return; + } + List stackFrames = stacktraceArgs.levels == 0 + ? thread.frames(stacktraceArgs.startFrame, totalFrames - stacktraceArgs.startFrame) + : thread.frames(stacktraceArgs.startFrame, + Math.min(totalFrames - stacktraceArgs.startFrame, stacktraceArgs.levels)); + for (int i = 0; i < stackFrames.size(); i++) { + StackFrame stackFrame = stackFrames.get(i); + int frameId = context.getRecyclableIdPool().addObject(stackFrame.thread().uniqueID(), + new JdiObjectProxy<>(stackFrame)); + Types.StackFrame clientStackFrame = convertDebuggerStackFrameToClient(stackFrame, frameId, context); + result.add(clientStackFrame); + } + } catch (IncompatibleThreadStateException | IndexOutOfBoundsException | URISyntaxException | AbsentInformationException e) { + // do nothing. + } + } + response.body = new Responses.StackTraceResponseBody(result, totalFrames); + } + + private Types.StackFrame convertDebuggerStackFrameToClient(StackFrame stackFrame, int frameId, IDebugAdapterContext context) + throws URISyntaxException, AbsentInformationException { + Location location = stackFrame.location(); + Method method = location.method(); + Types.Source clientSource = this.convertDebuggerSourceToClient(location, context); + String methodName = method.name(); + int lineNumber = AdapterUtils.convertLineNumber(location.lineNumber(), context.isDebuggerLinesStartAt1(), context.isClientLinesStartAt1()); + if (lineNumber < 0 && method.isNative()) { + // When the current stack frame stops at a native method, the line number is -1. + // Display a tip text "native method" in the Call Stack View. + methodName += "[native method]"; + } + return new Types.StackFrame(frameId, methodName, clientSource, lineNumber, 0); + } + + private Types.Source convertDebuggerSourceToClient(Location location, IDebugAdapterContext context) throws URISyntaxException { + final String fullyQualifiedName = location.declaringType().name(); + String sourceName = ""; + String relativeSourcePath = ""; + try { + // When the .class file doesn't contain source information in meta data, + // invoking Location#sourceName() would throw AbsentInformationException. + sourceName = location.sourceName(); + relativeSourcePath = location.sourcePath(); + } catch (AbsentInformationException e) { + String enclosingType = AdapterUtils.parseEnclosingType(fullyQualifiedName); + sourceName = enclosingType.substring(enclosingType.lastIndexOf('.') + 1) + ".java"; + relativeSourcePath = enclosingType.replace('.', '/') + ".java"; + } + + final String finalRelativeSourcePath = relativeSourcePath; + // use a lru cache for better performance + String uri = context.getSourceLookupCache().computeIfAbsent(fullyQualifiedName, key -> + context.getProvider(ISourceLookUpProvider.class).getSourceFileURI(key, finalRelativeSourcePath) + ); + + if (uri != null) { + String clientPath = AdapterUtils.convertPath(uri, context.isDebuggerPathsAreUri(), context.isClientPathsAreUri()); + if (uri.startsWith("file:")) { + return new Types.Source(sourceName, clientPath, 0); + } else { + return new Types.Source(sourceName, clientPath, context.createSourceReference(uri)); + } + } else { + // If the source lookup engine cannot find the source file, then lookup it in the source directories specified by user. + String absoluteSourcepath = AdapterUtils.sourceLookup(context.getSourcePaths(), relativeSourcePath); + return new Types.Source(sourceName, absoluteSourcepath, 0); + } + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java index 7d65db84a..009de3e86 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/ThreadsRequestHandler.java @@ -1,154 +1,154 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.jdt.ls.debug.DebugUtility; -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.Events; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.ContinueArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.NextArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.PauseArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.StepInArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.StepOutArguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.ThreadsArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; - -import com.sun.jdi.ThreadReference; -import com.sun.jdi.VMDisconnectedException; - -public class ThreadsRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.THREADS, Command.STEPIN, Command.STEPOUT, Command.NEXT, Command.PAUSE, Command.CONTINUE); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - if (context.getDebugSession() == null) { - AdapterUtils.setErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Debug Session doesn't exist."); - return; - } - switch (command) { - case THREADS: - this.threads((ThreadsArguments) arguments, response, context); - break; - case STEPIN: - this.stepIn((StepInArguments) arguments, response, context); - break; - case STEPOUT: - this.stepOut((StepOutArguments) arguments, response, context); - break; - case NEXT: - this.next((NextArguments) arguments, response, context); - break; - case PAUSE: - this.pause((PauseArguments) arguments, response, context); - break; - case CONTINUE: - this.resume((ContinueArguments) arguments, response, context); - break; - default: - return; - } - } - - private void threads(Requests.ThreadsArguments arguments, Response response, IDebugAdapterContext context) { - ArrayList threads = new ArrayList<>(); - for (ThreadReference thread : DebugUtility.getAllThreadsSafely(context.getDebugSession())) { - Types.Thread clientThread = new Types.Thread(thread.uniqueID(), "Thread [" + thread.name() + "]"); - threads.add(clientThread); - } - response.body = new Responses.ThreadsResponseBody(threads); - } - - private void stepIn(Requests.StepInArguments arguments, Response response, IDebugAdapterContext context) { - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - if (thread != null) { - DebugUtility.stepInto(thread, context.getDebugSession().eventHub()); - checkThreadRunningAndRecycleIds(thread, context); - } - } - - private void stepOut(Requests.StepOutArguments arguments, Response response, IDebugAdapterContext context) { - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - if (thread != null) { - DebugUtility.stepOut(thread, context.getDebugSession().eventHub()); - checkThreadRunningAndRecycleIds(thread, context); - } - } - - private void next(Requests.NextArguments arguments, Response response, IDebugAdapterContext context) { - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - if (thread != null) { - DebugUtility.stepOver(thread, context.getDebugSession().eventHub()); - checkThreadRunningAndRecycleIds(thread, context); - } - } - - private void pause(Requests.PauseArguments arguments, Response response, IDebugAdapterContext context) { - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - if (thread != null) { - thread.suspend(); - context.sendEventAsync(new Events.StoppedEvent("pause", arguments.threadId)); - } else { - context.getDebugSession().suspend(); - context.sendEventAsync(new Events.StoppedEvent("pause", arguments.threadId, true)); - } - } - - private void resume(Requests.ContinueArguments arguments, Response response, IDebugAdapterContext context) { - boolean allThreadsContinued = true; - ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); - /** - * See the jdi doc https://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/ThreadReference.html#resume(), - * suspends of both the virtual machine and individual threads are counted. Before a thread will run again, it must - * be resumed (through ThreadReference#resume() or VirtualMachine#resume()) the same number of times it has been suspended. - */ - if (thread != null) { - allThreadsContinued = false; - DebugUtility.resumeThread(thread); - checkThreadRunningAndRecycleIds(thread, context); - } else { - context.getDebugSession().resume(); - context.getRecyclableIdPool().removeAllObjects(); - } - response.body = new Responses.ContinueResponseBody(allThreadsContinued); - } - - private void checkThreadRunningAndRecycleIds(ThreadReference thread, IDebugAdapterContext context) { - try { - boolean allThreadsRunning = !DebugUtility.getAllThreadsSafely(context.getDebugSession()) - .stream().anyMatch(ThreadReference::isSuspended); - if (allThreadsRunning) { - context.getRecyclableIdPool().removeAllObjects(); - } else { - context.getRecyclableIdPool().removeObjectsByOwner(thread.uniqueID()); - } - } catch (VMDisconnectedException ex) { - context.getRecyclableIdPool().removeAllObjects(); - } - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jdt.ls.debug.DebugUtility; +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.Events; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.ContinueArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.NextArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.PauseArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.StepInArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.StepOutArguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.ThreadsArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; + +import com.sun.jdi.ThreadReference; +import com.sun.jdi.VMDisconnectedException; + +public class ThreadsRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.THREADS, Command.STEPIN, Command.STEPOUT, Command.NEXT, Command.PAUSE, Command.CONTINUE); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + if (context.getDebugSession() == null) { + AdapterUtils.setErrorResponse(response, ErrorCode.EMPTY_DEBUG_SESSION, "Debug Session doesn't exist."); + return; + } + switch (command) { + case THREADS: + this.threads((ThreadsArguments) arguments, response, context); + break; + case STEPIN: + this.stepIn((StepInArguments) arguments, response, context); + break; + case STEPOUT: + this.stepOut((StepOutArguments) arguments, response, context); + break; + case NEXT: + this.next((NextArguments) arguments, response, context); + break; + case PAUSE: + this.pause((PauseArguments) arguments, response, context); + break; + case CONTINUE: + this.resume((ContinueArguments) arguments, response, context); + break; + default: + return; + } + } + + private void threads(Requests.ThreadsArguments arguments, Response response, IDebugAdapterContext context) { + ArrayList threads = new ArrayList<>(); + for (ThreadReference thread : DebugUtility.getAllThreadsSafely(context.getDebugSession())) { + Types.Thread clientThread = new Types.Thread(thread.uniqueID(), "Thread [" + thread.name() + "]"); + threads.add(clientThread); + } + response.body = new Responses.ThreadsResponseBody(threads); + } + + private void stepIn(Requests.StepInArguments arguments, Response response, IDebugAdapterContext context) { + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + if (thread != null) { + DebugUtility.stepInto(thread, context.getDebugSession().eventHub()); + checkThreadRunningAndRecycleIds(thread, context); + } + } + + private void stepOut(Requests.StepOutArguments arguments, Response response, IDebugAdapterContext context) { + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + if (thread != null) { + DebugUtility.stepOut(thread, context.getDebugSession().eventHub()); + checkThreadRunningAndRecycleIds(thread, context); + } + } + + private void next(Requests.NextArguments arguments, Response response, IDebugAdapterContext context) { + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + if (thread != null) { + DebugUtility.stepOver(thread, context.getDebugSession().eventHub()); + checkThreadRunningAndRecycleIds(thread, context); + } + } + + private void pause(Requests.PauseArguments arguments, Response response, IDebugAdapterContext context) { + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + if (thread != null) { + thread.suspend(); + context.sendEventAsync(new Events.StoppedEvent("pause", arguments.threadId)); + } else { + context.getDebugSession().suspend(); + context.sendEventAsync(new Events.StoppedEvent("pause", arguments.threadId, true)); + } + } + + private void resume(Requests.ContinueArguments arguments, Response response, IDebugAdapterContext context) { + boolean allThreadsContinued = true; + ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), arguments.threadId); + /** + * See the jdi doc https://docs.oracle.com/javase/7/docs/jdk/api/jpda/jdi/com/sun/jdi/ThreadReference.html#resume(), + * suspends of both the virtual machine and individual threads are counted. Before a thread will run again, it must + * be resumed (through ThreadReference#resume() or VirtualMachine#resume()) the same number of times it has been suspended. + */ + if (thread != null) { + allThreadsContinued = false; + DebugUtility.resumeThread(thread); + checkThreadRunningAndRecycleIds(thread, context); + } else { + context.getDebugSession().resume(); + context.getRecyclableIdPool().removeAllObjects(); + } + response.body = new Responses.ContinueResponseBody(allThreadsContinued); + } + + private void checkThreadRunningAndRecycleIds(ThreadReference thread, IDebugAdapterContext context) { + try { + boolean allThreadsRunning = !DebugUtility.getAllThreadsSafely(context.getDebugSession()) + .stream().anyMatch(ThreadReference::isSuspended); + if (allThreadsRunning) { + context.getRecyclableIdPool().removeAllObjects(); + } else { + context.getRecyclableIdPool().removeObjectsByOwner(thread.uniqueID()); + } + } catch (VMDisconnectedException ex) { + context.getRecyclableIdPool().removeAllObjects(); + } + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java index c194d2ecc..755c5bf03 100644 --- a/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/handler/VariablesRequestHandler.java @@ -1,194 +1,194 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.handler; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; -import org.eclipse.jdt.ls.debug.adapter.ErrorCode; -import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; -import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; -import org.eclipse.jdt.ls.debug.adapter.Messages.Response; -import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; -import org.eclipse.jdt.ls.debug.adapter.Requests.Command; -import org.eclipse.jdt.ls.debug.adapter.Requests.VariablesArguments; -import org.eclipse.jdt.ls.debug.adapter.Responses; -import org.eclipse.jdt.ls.debug.adapter.Types; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; -import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; -import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.IVariableFormatter; -import org.eclipse.jdt.ls.debug.adapter.variables.Variable; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; -import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.ArrayReference; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.StackFrame; -import com.sun.jdi.Type; -import com.sun.jdi.Value; - -public class VariablesRequestHandler implements IDebugRequestHandler { - - @Override - public List getTargetCommands() { - return Arrays.asList(Command.VARIABLES); - } - - @Override - public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { - IVariableFormatter variableFormatter = context.getVariableFormatter(); - VariablesArguments varArgs = (VariablesArguments) arguments; - - Map options = variableFormatter.getDefaultOptions(); - // This should be false by default(currently true for test). - // User will need to explicitly turn it on by configuring launch.json - boolean showStaticVariables = true; - // TODO: When vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. - boolean showFullyQualifiedNames = true; - if (varArgs.format != null && varArgs.format.hex) { - options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); - } - if (showFullyQualifiedNames) { - options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); - } - - List list = new ArrayList<>(); - Object container = context.getRecyclableIdPool().getObjectById(varArgs.variablesReference); - // vscode will always send variables request to a staled scope, return the empty list is ok since the next - // variable request will contain the right variablesReference. - if (container == null) { - response.body = new Responses.VariablesResponseBody(list); - return; - } - - if (!(container instanceof VariableProxy)) { - AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("VariablesRequest: Invalid variablesReference %d.", varArgs.variablesReference)); - return; - } - - VariableProxy containerNode = (VariableProxy) container; - List childrenList; - if (containerNode.getProxiedVariable() instanceof StackFrame) { - try { - StackFrame frame = (StackFrame) containerNode.getProxiedVariable(); - childrenList = VariableUtils.listLocalVariables(frame); - Variable thisVariable = VariableUtils.getThisVariable(frame); - if (thisVariable != null) { - childrenList.add(thisVariable); - } - if (showStaticVariables && frame.location().method().isStatic()) { - childrenList.addAll(VariableUtils.listStaticVariables(frame)); - } - } catch (AbsentInformationException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("Failed to get variables. Reason: %s", e.toString())); - return; - } - } else { - try { - ObjectReference containerObj = (ObjectReference) containerNode.getProxiedVariable(); - - if (varArgs.count > 0) { - childrenList = VariableUtils.listFieldVariables(containerObj, varArgs.start, varArgs.count); - } else { - childrenList = VariableUtils.listFieldVariables(containerObj, showStaticVariables); - } - } catch (AbsentInformationException e) { - AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, - String.format("Failed to get variables. Reason: %s", e.toString())); - return; - } - } - - // Find variable name duplicates - Set duplicateNames = getDuplicateNames(childrenList.stream().map(var -> var.name) - .collect(Collectors.toList())); - Map variableNameMap = new HashMap<>(); - if (!duplicateNames.isEmpty()) { - Map> duplicateVars = - childrenList.stream() - .filter(var -> duplicateNames.contains(var.name)) - .collect(Collectors.groupingBy(var -> var.name, Collectors.toList())); - - duplicateVars.forEach((k, duplicateVariables) -> { - Set declarationTypeNames = new HashSet<>(); - boolean declarationTypeNameConflict = false; - // try use type formatter to resolve name conflict - for (Variable javaVariable : duplicateVariables) { - Type declarationType = javaVariable.getDeclaringType(); - if (declarationType != null) { - String declarationTypeName = variableFormatter.typeToString(declarationType, options); - String compositeName = String.format("%s (%s)", javaVariable.name, declarationTypeName); - if (!declarationTypeNames.add(compositeName)) { - declarationTypeNameConflict = true; - break; - } - variableNameMap.put(javaVariable, compositeName); - } - } - // If there are duplicate names on declaration types, use fully qualified name - if (declarationTypeNameConflict) { - for (Variable javaVariable : duplicateVariables) { - Type declarationType = javaVariable.getDeclaringType(); - if (declarationType != null) { - variableNameMap.put(javaVariable, String.format("%s (%s)", javaVariable.name, declarationType.name())); - } - } - } - }); - } - for (Variable javaVariable : childrenList) { - Value value = javaVariable.value; - String name = javaVariable.name; - if (variableNameMap.containsKey(javaVariable)) { - name = variableNameMap.get(javaVariable); - } - int referenceId = 0; - if (value instanceof ObjectReference && VariableUtils.hasChildren(value, showStaticVariables)) { - VariableProxy varProxy = new VariableProxy(containerNode.getThreadId(), containerNode.getScope(), value); - referenceId = context.getRecyclableIdPool().addObject(containerNode.getThreadId(), varProxy); - } - Types.Variable typedVariables = new Types.Variable(name, variableFormatter.valueToString(value, options), - variableFormatter.typeToString(value == null ? null : value.type(), options), referenceId, null); - if (javaVariable.value instanceof ArrayReference) { - typedVariables.indexedVariables = ((ArrayReference) javaVariable.value).length(); - } - list.add(typedVariables); - } - response.body = new Responses.VariablesResponseBody(list); - } - - private Set getDuplicateNames(Collection list) { - Set result = new HashSet<>(); - Set set = new HashSet<>(); - - for (String item : list) { - if (!set.contains(item)) { - set.add(item); - } else { - result.add(item); - } - } - return result; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.handler; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.eclipse.jdt.ls.debug.adapter.AdapterUtils; +import org.eclipse.jdt.ls.debug.adapter.ErrorCode; +import org.eclipse.jdt.ls.debug.adapter.IDebugAdapterContext; +import org.eclipse.jdt.ls.debug.adapter.IDebugRequestHandler; +import org.eclipse.jdt.ls.debug.adapter.Messages.Response; +import org.eclipse.jdt.ls.debug.adapter.Requests.Arguments; +import org.eclipse.jdt.ls.debug.adapter.Requests.Command; +import org.eclipse.jdt.ls.debug.adapter.Requests.VariablesArguments; +import org.eclipse.jdt.ls.debug.adapter.Responses; +import org.eclipse.jdt.ls.debug.adapter.Types; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatEnum; +import org.eclipse.jdt.ls.debug.adapter.formatter.NumericFormatter; +import org.eclipse.jdt.ls.debug.adapter.formatter.SimpleTypeFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.IVariableFormatter; +import org.eclipse.jdt.ls.debug.adapter.variables.Variable; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableProxy; +import org.eclipse.jdt.ls.debug.adapter.variables.VariableUtils; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.ArrayReference; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.StackFrame; +import com.sun.jdi.Type; +import com.sun.jdi.Value; + +public class VariablesRequestHandler implements IDebugRequestHandler { + + @Override + public List getTargetCommands() { + return Arrays.asList(Command.VARIABLES); + } + + @Override + public void handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { + IVariableFormatter variableFormatter = context.getVariableFormatter(); + VariablesArguments varArgs = (VariablesArguments) arguments; + + Map options = variableFormatter.getDefaultOptions(); + // This should be false by default(currently true for test). + // User will need to explicitly turn it on by configuring launch.json + boolean showStaticVariables = true; + // TODO: When vscode protocol support customize settings of value format, showFullyQualifiedNames should be one of the options. + boolean showFullyQualifiedNames = true; + if (varArgs.format != null && varArgs.format.hex) { + options.put(NumericFormatter.NUMERIC_FORMAT_OPTION, NumericFormatEnum.HEX); + } + if (showFullyQualifiedNames) { + options.put(SimpleTypeFormatter.QUALIFIED_CLASS_NAME_OPTION, showFullyQualifiedNames); + } + + List list = new ArrayList<>(); + Object container = context.getRecyclableIdPool().getObjectById(varArgs.variablesReference); + // vscode will always send variables request to a staled scope, return the empty list is ok since the next + // variable request will contain the right variablesReference. + if (container == null) { + response.body = new Responses.VariablesResponseBody(list); + return; + } + + if (!(container instanceof VariableProxy)) { + AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, + String.format("VariablesRequest: Invalid variablesReference %d.", varArgs.variablesReference)); + return; + } + + VariableProxy containerNode = (VariableProxy) container; + List childrenList; + if (containerNode.getProxiedVariable() instanceof StackFrame) { + try { + StackFrame frame = (StackFrame) containerNode.getProxiedVariable(); + childrenList = VariableUtils.listLocalVariables(frame); + Variable thisVariable = VariableUtils.getThisVariable(frame); + if (thisVariable != null) { + childrenList.add(thisVariable); + } + if (showStaticVariables && frame.location().method().isStatic()) { + childrenList.addAll(VariableUtils.listStaticVariables(frame)); + } + } catch (AbsentInformationException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, + String.format("Failed to get variables. Reason: %s", e.toString())); + return; + } + } else { + try { + ObjectReference containerObj = (ObjectReference) containerNode.getProxiedVariable(); + + if (varArgs.count > 0) { + childrenList = VariableUtils.listFieldVariables(containerObj, varArgs.start, varArgs.count); + } else { + childrenList = VariableUtils.listFieldVariables(containerObj, showStaticVariables); + } + } catch (AbsentInformationException e) { + AdapterUtils.setErrorResponse(response, ErrorCode.GET_VARIABLE_FAILURE, + String.format("Failed to get variables. Reason: %s", e.toString())); + return; + } + } + + // Find variable name duplicates + Set duplicateNames = getDuplicateNames(childrenList.stream().map(var -> var.name) + .collect(Collectors.toList())); + Map variableNameMap = new HashMap<>(); + if (!duplicateNames.isEmpty()) { + Map> duplicateVars = + childrenList.stream() + .filter(var -> duplicateNames.contains(var.name)) + .collect(Collectors.groupingBy(var -> var.name, Collectors.toList())); + + duplicateVars.forEach((k, duplicateVariables) -> { + Set declarationTypeNames = new HashSet<>(); + boolean declarationTypeNameConflict = false; + // try use type formatter to resolve name conflict + for (Variable javaVariable : duplicateVariables) { + Type declarationType = javaVariable.getDeclaringType(); + if (declarationType != null) { + String declarationTypeName = variableFormatter.typeToString(declarationType, options); + String compositeName = String.format("%s (%s)", javaVariable.name, declarationTypeName); + if (!declarationTypeNames.add(compositeName)) { + declarationTypeNameConflict = true; + break; + } + variableNameMap.put(javaVariable, compositeName); + } + } + // If there are duplicate names on declaration types, use fully qualified name + if (declarationTypeNameConflict) { + for (Variable javaVariable : duplicateVariables) { + Type declarationType = javaVariable.getDeclaringType(); + if (declarationType != null) { + variableNameMap.put(javaVariable, String.format("%s (%s)", javaVariable.name, declarationType.name())); + } + } + } + }); + } + for (Variable javaVariable : childrenList) { + Value value = javaVariable.value; + String name = javaVariable.name; + if (variableNameMap.containsKey(javaVariable)) { + name = variableNameMap.get(javaVariable); + } + int referenceId = 0; + if (value instanceof ObjectReference && VariableUtils.hasChildren(value, showStaticVariables)) { + VariableProxy varProxy = new VariableProxy(containerNode.getThreadId(), containerNode.getScope(), value); + referenceId = context.getRecyclableIdPool().addObject(containerNode.getThreadId(), varProxy); + } + Types.Variable typedVariables = new Types.Variable(name, variableFormatter.valueToString(value, options), + variableFormatter.typeToString(value == null ? null : value.type(), options), referenceId, null); + if (javaVariable.value instanceof ArrayReference) { + typedVariables.indexedVariables = ((ArrayReference) javaVariable.value).length(); + } + list.add(typedVariables); + } + response.body = new Responses.VariablesResponseBody(list); + } + + private Set getDuplicateNames(Collection list) { + Set result = new HashSet<>(); + Set set = new HashSet<>(); + + for (String item : list) { + if (!set.contains(item)) { + set.add(item); + } else { + result.add(item); + } + } + return result; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/IVariableFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/JdiObjectProxy.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/Variable.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/Variable.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/Variable.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/Variable.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatter.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableFormatterFactory.java diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java similarity index 96% rename from org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java index 13f051834..d776102ae 100644 --- a/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableProxy.java @@ -1,70 +1,70 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.variables; - -import java.util.Objects; - -public class VariableProxy { - private final long threadId; - private final String scopeName; - private Object variable; - private int hashCode; - - /** - * Create a variable proxy. - * @param threadId - * the context thread id - * @param scopeName - * the scope name - * @param variable - * the variable object - */ - public VariableProxy(long threadId, String scopeName, Object variable) { - this.threadId = threadId; - this.scopeName = scopeName; - this.variable = variable; - this.hashCode = (int) (threadId & scopeName.hashCode() & variable.hashCode()); - } - - @Override - public String toString() { - return String.format("%s %s", String.valueOf(this.variable), this.scopeName); - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof VariableProxy)) { - return false; - } - final VariableProxy other = (VariableProxy) o; - return this.getThreadId() == other.getThreadId() - && Objects.equals(this.getScope(), other.getScope()) - && Objects.equals(this.getProxiedVariable(), other.getProxiedVariable()); - } - - public long getThreadId() { - return this.threadId; - } - - public String getScope() { - return this.scopeName; - } - - public Object getProxiedVariable() { - return this.variable; - } -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.variables; + +import java.util.Objects; + +public class VariableProxy { + private final long threadId; + private final String scopeName; + private Object variable; + private int hashCode; + + /** + * Create a variable proxy. + * @param threadId + * the context thread id + * @param scopeName + * the scope name + * @param variable + * the variable object + */ + public VariableProxy(long threadId, String scopeName, Object variable) { + this.threadId = threadId; + this.scopeName = scopeName; + this.variable = variable; + this.hashCode = (int) (threadId & scopeName.hashCode() & variable.hashCode()); + } + + @Override + public String toString() { + return String.format("%s %s", String.valueOf(this.variable), this.scopeName); + } + + @Override + public int hashCode() { + return hashCode; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof VariableProxy)) { + return false; + } + final VariableProxy other = (VariableProxy) o; + return this.getThreadId() == other.getThreadId() + && Objects.equals(this.getScope(), other.getScope()) + && Objects.equals(this.getProxiedVariable(), other.getProxiedVariable()); + } + + public long getThreadId() { + return this.threadId; + } + + public String getScope() { + return this.scopeName; + } + + public Object getProxiedVariable() { + return this.variable; + } +} diff --git a/org/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/adapter/variables/VariableUtils.java diff --git a/org/eclipse/jdt/ls/debug/internal/Breakpoint.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Breakpoint.java similarity index 100% rename from org/eclipse/jdt/ls/debug/internal/Breakpoint.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Breakpoint.java diff --git a/org/eclipse/jdt/ls/debug/internal/DebugSession.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/DebugSession.java similarity index 100% rename from org/eclipse/jdt/ls/debug/internal/DebugSession.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/DebugSession.java diff --git a/org/eclipse/jdt/ls/debug/internal/EventHub.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/EventHub.java similarity index 100% rename from org/eclipse/jdt/ls/debug/internal/EventHub.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/EventHub.java diff --git a/org/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java similarity index 100% rename from org/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/JavaDebuggerServerPlugin.java diff --git a/org/eclipse/jdt/ls/debug/internal/Logger.java b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Logger.java similarity index 97% rename from org/eclipse/jdt/ls/debug/internal/Logger.java rename to com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Logger.java index c91ac90f9..4cad01691 100644 --- a/org/eclipse/jdt/ls/debug/internal/Logger.java +++ b/com.microsoft.java.debug.core/src/main/java/org/eclipse/jdt/ls/debug/internal/Logger.java @@ -1,34 +1,34 @@ -/******************************************************************************* - * Copyright (c) 2017 Microsoft Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Microsoft Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jdt.ls.debug.internal; - -import org.eclipse.jdt.ls.debug.internal.JavaDebuggerServerPlugin; - -public class Logger { - /** - * Log the info message with the plugin's logger. - * @param message - * message to log - */ - public static void logInfo(String message) { - JavaDebuggerServerPlugin.logInfo(message); - } - - public static void logException(String message, Exception e) { - JavaDebuggerServerPlugin.logException(message, e); - } - - public static void logError(String error) { - JavaDebuggerServerPlugin.logError(error); - } - -} +/******************************************************************************* + * Copyright (c) 2017 Microsoft Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Microsoft Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jdt.ls.debug.internal; + +import org.eclipse.jdt.ls.debug.internal.JavaDebuggerServerPlugin; + +public class Logger { + /** + * Log the info message with the plugin's logger. + * @param message + * message to log + */ + public static void logInfo(String message) { + JavaDebuggerServerPlugin.logInfo(message); + } + + public static void logException(String message, Exception e) { + JavaDebuggerServerPlugin.logException(message, e); + } + + public static void logError(String error) { + JavaDebuggerServerPlugin.logError(error); + } + +} diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java new file mode 100644 index 000000000..1eea8de7e --- /dev/null +++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebuggerServerPlugin.java @@ -0,0 +1,33 @@ +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package com.microsoft.java.debug.plugin.internal; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class JavaDebuggerServerPlugin implements BundleActivator { + + public static final String PLUGIN_ID = "com.microsoft.java.debug"; + + + @Override + public void start(BundleContext context) throws Exception { + System.out.println("Starting " + PLUGIN_ID); + } + + @Override + public void stop(BundleContext context) throws Exception { + + } + +} + diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java similarity index 97% rename from org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java index 2ff281f80..9feaacdd1 100644 --- a/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java +++ b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/DebugServerFactory.java @@ -1,24 +1,24 @@ -/******************************************************************************* -* Copyright (c) 2017 Microsoft Corporation and others. -* All rights reserved. This program and the accompanying materials -* are made available under the terms of the Eclipse Public License v1.0 -* which accompanies this distribution, and is available at -* http://www.eclipse.org/legal/epl-v10.html -* -* Contributors: -* Microsoft Corporation - initial API and implementation -*******************************************************************************/ - -package org.eclipse.jdt.ls.debug.adapter.jdt; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IExecutableExtensionFactory; - -public class DebugServerFactory implements IExecutableExtensionFactory { - - @Override - public Object create() throws CoreException { - return JavaDebugServer.getInstance(); - } - -} +/******************************************************************************* +* Copyright (c) 2017 Microsoft Corporation and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Microsoft Corporation - initial API and implementation +*******************************************************************************/ + +package org.eclipse.jdt.ls.debug.adapter.jdt; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IExecutableExtensionFactory; + +public class DebugServerFactory implements IExecutableExtensionFactory { + + @Override + public Object create() throws CoreException { + return JavaDebugServer.getInstance(); + } + +} diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JavaDebugServer.java diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtProviderContextFactory.java diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtSourceLookUpProvider.java diff --git a/org/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java b/com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java similarity index 100% rename from org/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java rename to com.microsoft.java.debug.plugin/src/main/java/org/eclipse/jdt/ls/debug/adapter/jdt/JdtVirtualMachineManagerProvider.java