blob: 1db82aa0a43747eb4e331f81a651f5b4357035a3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*******************************************************************************
* Copyright (c) 2006, 2013 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.internal.core.commands;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.commands.IDebugCommandRequest;
import org.eclipse.debug.core.commands.IStepFiltersHandler;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStepFilters;
/**
* Default toggle step filters command for the standard debug model.
*
* @since 3.3
*/
public class StepFiltersCommand extends ForEachCommand implements IStepFiltersHandler {
@Override
protected Object getTarget(Object element) {
IDebugTarget[] targets = getDebugTargets(element);
if (targets.length > 0) {
IStepFilters[] filters = new IStepFilters[targets.length];
for (int i = 0; i < targets.length; i++) {
IDebugTarget target = targets[i];
if (target instanceof IStepFilters) {
filters[i] = (IStepFilters) target;
} else {
filters[i] = (IStepFilters) getAdapter(element, IStepFilters.class);
}
if (filters[i] == null) {
return null;
}
}
return filters;
}
return null;
}
private IDebugTarget[] getDebugTargets(Object element) {
if (element instanceof IDebugElement) {
IDebugElement debugElement = (IDebugElement) element;
return new IDebugTarget[] { debugElement.getDebugTarget() };
} else if (element instanceof ILaunch) {
ILaunch launch = (ILaunch) element;
return launch.getDebugTargets();
} else if (element instanceof IProcess) {
IProcess process = (IProcess) element;
return process.getLaunch().getDebugTargets();
} else {
return new IDebugTarget[0];
}
}
@Override
protected void execute(Object target) throws CoreException {
if (target == null) {
return;
}
IStepFilters[] filters = (IStepFilters[]) target;
for (int i = 0; i < filters.length; i++) {
IStepFilters filter = filters[i];
filter.setStepFiltersEnabled(DebugPlugin.isUseStepFilters());
}
}
@Override
protected boolean isExecutable(Object target) {
IStepFilters[] filters = (IStepFilters[]) target;
for (int i = 0; i < filters.length; i++) {
IStepFilters filter = filters[i];
if (filter == null || !filter.supportsStepFilters()) {
return false;
}
}
return true;
}
@Override
protected Object getEnabledStateJobFamily(IDebugCommandRequest request) {
return IStepFiltersHandler.class;
}
}
|