Skip to content

Commit 4dfe2e7

Browse files
authored
CHE-6843: Navigate to breakpiont (eclipse-che#6967)
Signed-off-by: Anatoliy Bazko <abazko@redhat.com>
1 parent 156c525 commit 4dfe2e7

25 files changed

Lines changed: 234 additions & 113 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.ide.api.debug;
12+
13+
import org.eclipse.che.api.debug.shared.model.Location;
14+
15+
/**
16+
* Marker to indicate that given implementation can deal with debug {@link Location}.
17+
*
18+
* @author Anatolii Bazko
19+
*/
20+
public interface HasLocation {
21+
Location toLocation(int lineNumber);
22+
}

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/resources/File.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.google.common.annotations.Beta;
1414
import org.eclipse.che.api.promises.client.Promise;
15+
import org.eclipse.che.ide.api.debug.HasLocation;
1516
import org.eclipse.che.ide.api.vcs.HasVcsStatus;
1617
import org.eclipse.che.ide.resource.Path;
1718

@@ -32,7 +33,8 @@
3233
* @since 4.4.0
3334
*/
3435
@Beta
35-
public interface File extends Resource, VirtualFile, ModificationTracker, HasVcsStatus {
36+
public interface File
37+
extends Resource, VirtualFile, ModificationTracker, HasVcsStatus, HasLocation {
3638

3739
/** @see VirtualFile#getDisplayName() */
3840
@Override

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.eclipse.che.ide.api.debug.BreakpointRenderer.LineChangeAction;
3535
import org.eclipse.che.ide.api.debug.BreakpointStorage;
3636
import org.eclipse.che.ide.api.debug.HasBreakpointRenderer;
37+
import org.eclipse.che.ide.api.debug.HasLocation;
3738
import org.eclipse.che.ide.api.editor.EditorAgent;
3839
import org.eclipse.che.ide.api.editor.EditorOpenedEvent;
3940
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
@@ -47,7 +48,6 @@
4748
import org.eclipse.che.ide.api.resources.ResourceChangedEvent;
4849
import org.eclipse.che.ide.api.resources.ResourceDelta;
4950
import org.eclipse.che.ide.api.resources.VirtualFile;
50-
import org.eclipse.che.ide.project.node.SyntheticNode;
5151
import org.eclipse.che.ide.resource.Path;
5252

5353
/**
@@ -102,22 +102,13 @@ public void changeBreakpointState(final int lineNumber) {
102102
if (existedBreakpoint.isPresent()) {
103103
deleteBreakpoint(activeFile, existedBreakpoint.get());
104104
} else {
105-
String project = null;
106-
if (activeFile instanceof SyntheticNode) {
107-
project = ((SyntheticNode) activeFile).getProject().toString();
108-
} else if (activeFile instanceof Resource) {
109-
project = ((Resource) activeFile).getProject().getPath();
110-
}
111-
112-
if (project == null) {
113-
LOG.warning("Impossible to figure out project for: " + activeFile.getLocation().toString());
105+
if (activeFile instanceof HasLocation) {
106+
addBreakpoint(
107+
activeFile, new BreakpointImpl(((HasLocation) activeFile).toLocation(lineNumber + 1)));
108+
} else {
109+
LOG.warning("Impossible to figure debug location for: " + activeFile.getLocation());
114110
return;
115111
}
116-
117-
addBreakpoint(
118-
activeFile,
119-
new BreakpointImpl(
120-
new LocationImpl(activeFile.getLocation().toString(), lineNumber + 1, project)));
121112
}
122113
}
123114

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/resources/impl/FileImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.google.common.base.Optional;
1616
import com.google.inject.Inject;
1717
import com.google.inject.assistedinject.Assisted;
18+
import org.eclipse.che.api.debug.shared.model.Location;
19+
import org.eclipse.che.api.debug.shared.model.impl.LocationImpl;
1820
import org.eclipse.che.api.promises.client.Promise;
1921
import org.eclipse.che.ide.api.resources.File;
2022
import org.eclipse.che.ide.api.resources.marker.Marker;
@@ -159,4 +161,9 @@ public VcsStatus getVcsStatus() {
159161
public void setVcsStatus(VcsStatus vcsStatus) {
160162
this.vcsStatus = vcsStatus;
161163
}
164+
165+
@Override
166+
public Location toLocation(int lineNumber) {
167+
return new LocationImpl(getLocation().toString(), lineNumber, getProject().getPath());
168+
}
162169
}

plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public abstract class AbstractDebugger implements Debugger, DebuggerObservable {
9898
private final DebuggerServiceClient service;
9999
private final LocalStorageProvider localStorageProvider;
100100
private final EventBus eventBus;
101-
private final DebuggerResourceHandlerFactory debuggerResourceHandlerFactory;
101+
private final DebuggerLocationHandlerManager debuggerLocationHandlerManager;
102102
private final DebuggerManager debuggerManager;
103103
private final BreakpointManager breakpointManager;
104104
private final String debuggerType;
@@ -118,15 +118,15 @@ public AbstractDebugger(
118118
NotificationManager notificationManager,
119119
BreakpointManager breakpointManager,
120120
RequestHandlerManager requestHandlerManager,
121-
DebuggerResourceHandlerFactory debuggerResourceHandlerFactory,
121+
DebuggerLocationHandlerManager debuggerLocationHandlerManager,
122122
String type) {
123123
this.service = service;
124124
this.transmitter = transmitter;
125125
this.configurator = configurator;
126126
this.dtoFactory = dtoFactory;
127127
this.localStorageProvider = localStorageProvider;
128128
this.eventBus = eventBus;
129-
this.debuggerResourceHandlerFactory = debuggerResourceHandlerFactory;
129+
this.debuggerLocationHandlerManager = debuggerLocationHandlerManager;
130130
this.debuggerManager = debuggerManager;
131131
this.notificationManager = notificationManager;
132132
this.breakpointManager = breakpointManager;
@@ -170,8 +170,8 @@ public void onWsAgentStarted(WsAgentStateEvent event) {
170170
}
171171

172172
if (currentLocation != null) {
173-
debuggerResourceHandlerFactory
174-
.getOrDefault(getDebuggerType())
173+
debuggerLocationHandlerManager
174+
.getOrDefault(currentLocation)
175175
.find(
176176
currentLocation,
177177
new AsyncCallback<VirtualFile>() {
@@ -230,8 +230,8 @@ private void onEventListReceived(@NotNull DebuggerEventDto event) {
230230
}
231231

232232
private void open(Location location) {
233-
debuggerResourceHandlerFactory
234-
.getOrDefault(getDebuggerType())
233+
debuggerLocationHandlerManager
234+
.getOrDefault(location)
235235
.open(
236236
location,
237237
new AsyncCallback<VirtualFile>() {

plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandler.java renamed to plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerLocationHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
* @see Location#getLineNumber()
2222
* @author Anatoliy Bazko
2323
*/
24-
public interface DebuggerResourceHandler {
24+
public interface DebuggerLocationHandler {
25+
26+
/** Indicates if handler can deal with the given location. */
27+
boolean isSuitedFor(Location location);
2528

2629
/**
2730
* Opens resource is being debugged and scrolls to the position {@link Location#getLineNumber()}.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.plugin.debugger.ide.debug;
12+
13+
import com.google.inject.Inject;
14+
import com.google.inject.Singleton;
15+
import java.util.HashSet;
16+
import java.util.Set;
17+
import org.eclipse.che.api.debug.shared.model.Location;
18+
19+
/** @author Anatolii Bazko */
20+
@Singleton
21+
public class DebuggerLocationHandlerManager {
22+
23+
private final Set<DebuggerLocationHandler> handlers;
24+
private final DebuggerLocationHandler defaultHandler;
25+
26+
@Inject
27+
public DebuggerLocationHandlerManager(FileResourceLocationHandler defaultHandler) {
28+
this.handlers = new HashSet<>();
29+
this.defaultHandler = defaultHandler;
30+
}
31+
32+
/** Returns handler for the given location. */
33+
public DebuggerLocationHandler getOrDefault(Location location) {
34+
for (DebuggerLocationHandler handler : handlers) {
35+
if (handler.isSuitedFor(location)) {
36+
return handler;
37+
}
38+
}
39+
return defaultHandler;
40+
}
41+
42+
public void register(DebuggerLocationHandler handler) {
43+
handlers.add(handler);
44+
}
45+
}

plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class DebuggerPresenter extends BasePresenter
8282
private final DebuggerView view;
8383
private final DebuggerManager debuggerManager;
8484
private final WorkspaceAgent workspaceAgent;
85-
private final DebuggerResourceHandlerFactory resourceHandlerManager;
85+
private final DebuggerLocationHandlerManager locationHandlerManager;
8686
private final BreakpointContextMenuFactory breakpointContextMenuFactory;
8787

8888
private List<Variable> variables;
@@ -102,15 +102,15 @@ public DebuggerPresenter(
102102
final @DebuggerWatchToolBar ToolbarPresenter watchToolbar,
103103
final DebuggerManager debuggerManager,
104104
final WorkspaceAgent workspaceAgent,
105-
final DebuggerResourceHandlerFactory resourceHandlerManager,
105+
final DebuggerLocationHandlerManager locationHandlerManager,
106106
final BreakpointContextMenuFactory breakpointContextMenuFactory) {
107107
this.view = view;
108108
this.debuggerResources = debuggerResources;
109109
this.debuggerToolbar = debuggerToolbar;
110110
this.watchToolbar = watchToolbar;
111111
this.debuggerManager = debuggerManager;
112112
this.workspaceAgent = workspaceAgent;
113-
this.resourceHandlerManager = resourceHandlerManager;
113+
this.locationHandlerManager = locationHandlerManager;
114114
this.view.setDelegate(this);
115115
this.view.setTitle(TITLE);
116116
this.constant = constant;
@@ -203,8 +203,7 @@ public void onSelectedFrame(int frameIndex) {
203203
protected void open(Location location) {
204204
Debugger debugger = debuggerManager.getActiveDebugger();
205205
if (debugger != null) {
206-
DebuggerResourceHandler handler =
207-
resourceHandlerManager.getOrDefault(debugger.getDebuggerType());
206+
DebuggerLocationHandler handler = locationHandlerManager.getOrDefault(location);
208207

209208
handler.open(
210209
location,
@@ -527,4 +526,20 @@ public void onBreakpointContextMenu(int clientX, int clientY, Breakpoint breakpo
527526
.scheduleDeferred(
528527
() -> breakpointContextMenuFactory.newContextMenu(breakpoint).show(clientX, clientY));
529528
}
529+
530+
@Override
531+
public void onBreakpointDoubleClick(Breakpoint breakpoint) {
532+
Location location = breakpoint.getLocation();
533+
locationHandlerManager
534+
.getOrDefault(location)
535+
.open(
536+
location,
537+
new AsyncCallback<VirtualFile>() {
538+
@Override
539+
public void onFailure(Throwable caught) {}
540+
541+
@Override
542+
public void onSuccess(VirtualFile result) {}
543+
});
544+
}
530545
}

plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandlerFactory.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ interface ActionDelegate extends BaseActionDelegate {
4949
/** Breakpoint context menu is invoked. */
5050
void onBreakpointContextMenu(int clientX, int clientY, Breakpoint breakpoint);
5151

52+
void onBreakpointDoubleClick(Breakpoint breakpoint);
53+
5254
/**
5355
* Performs any actions appropriate in response to the user having pressed the expand button in
5456
* variables tree.

0 commit comments

Comments
 (0)