|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2023 Zsombor Gegesy and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * Zsombor Gegesy - initial API and implementation |
| 13 | + *******************************************************************************/ |
| 14 | +package org.eclipse.jdt.internal.debug.ui.actions; |
| 15 | + |
| 16 | +import java.util.HashSet; |
| 17 | + |
| 18 | +import org.eclipse.debug.core.DebugException; |
| 19 | +import org.eclipse.debug.core.model.IStackFrame; |
| 20 | +import org.eclipse.debug.core.model.IThread; |
| 21 | +import org.eclipse.jdt.debug.core.IJavaStackFrame; |
| 22 | +import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
| 23 | +import org.eclipse.jface.action.IAction; |
| 24 | +import org.eclipse.jface.viewers.IStructuredSelection; |
| 25 | + |
| 26 | +/** |
| 27 | + * Add the current stack frame to the highlighted frames. |
| 28 | + * |
| 29 | + */ |
| 30 | +public class HighlightStackFrameAction extends ObjectActionDelegate { |
| 31 | + |
| 32 | + @Override |
| 33 | + public void run(IAction action) { |
| 34 | + // Make sure there is a current selection |
| 35 | + IStructuredSelection selection = getCurrentSelection(); |
| 36 | + if (selection == null) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + final var stackFrameCategorizer = JDIDebugUIPlugin.getDefault().getStackFrameCategorizer(); |
| 41 | + final var types = new HashSet<String>(); |
| 42 | + final var threads = new HashSet<IThread>(); |
| 43 | + for (Object selected : selection) { |
| 44 | + if (selected instanceof IJavaStackFrame frame) { |
| 45 | + try { |
| 46 | + types.add(frame.getDeclaringTypeName()); |
| 47 | + } catch (DebugException e) { |
| 48 | + JDIDebugUIPlugin.log(e); |
| 49 | + } |
| 50 | + threads.add(frame.getThread()); |
| 51 | + } |
| 52 | + } |
| 53 | + stackFrameCategorizer.addTypesToActiveCustomFilters(types); |
| 54 | + for (IThread thread : threads) { |
| 55 | + try { |
| 56 | + for (IStackFrame frame : thread.getStackFrames()) { |
| 57 | + if (frame instanceof IJavaStackFrame javaFrame) { |
| 58 | + javaFrame.resetCategory(); |
| 59 | + } |
| 60 | + } |
| 61 | + } catch (DebugException e) { |
| 62 | + JDIDebugUIPlugin.log(e); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments