Skip to content

Commit

Permalink
Bug 574170 - Add coloring to the stack frames of the debug thread view
Browse files Browse the repository at this point in the history
  and add an action to enable/disable colorization from the context menu.
  All of the categorize can be switched on or off
  Use separate images for different stack frame categories.
  Update the labels to 'Your Source code', 'Your Test code', 'Highlighted ...'
  • Loading branch information
gzsombor committed Jul 2, 2022
1 parent cc699b9 commit 7a91818
Show file tree
Hide file tree
Showing 20 changed files with 1,320 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
import org.eclipse.jdt.debug.tests.ui.DebugViewTests;
import org.eclipse.jdt.debug.tests.ui.DetailPaneManagerTests;
import org.eclipse.jdt.debug.tests.ui.OpenFromClipboardTests;
import org.eclipse.jdt.debug.tests.ui.StackFramePresentationProviderTest;
import org.eclipse.jdt.debug.tests.ui.ViewManagementTests;
import org.eclipse.jdt.debug.tests.ui.presentation.ModelPresentationTests;
import org.eclipse.jdt.debug.tests.ui.presentation.ModelPresentationTests18;
Expand Down Expand Up @@ -231,6 +232,7 @@ public AutomatedSuite() {
addTest(new TestSuite(StepFilterTests.class));
addTest(new TestSuite(StepIntoSelectionTests.class));
addTest(new TestSuite(InstanceFilterTests.class));
addTest(new TestSuite(StackFramePresentationProviderTest.class));
if (JavaProjectHelper.isJava6Compatible()) {
addTest(new TestSuite(ForceReturnTests.class));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*******************************************************************************
* Copyright (c) 2021 Zsombor Gegesy.
*
* 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:
* Zsombor Gegesy - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.debug.tests.ui;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.jdt.debug.core.IJavaReferenceType;
import org.eclipse.jdt.debug.core.IJavaStackFrame;
import org.eclipse.jdt.debug.tests.AbstractDebugTest;
import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
import org.eclipse.jdt.internal.debug.ui.StackFramePresentationProvider;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceStore;

public class StackFramePresentationProviderTest extends AbstractDebugTest {

public StackFramePresentationProviderTest(String name) {
super(name);
}

private StackFramePresentationProvider provider;
private IPreferenceStore preferenceStore;

private static class LaunchMock implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return null;
}
}
private static class JavaStackFrameMock implements InvocationHandler {

final IJavaReferenceType referenceType;
final boolean synthetic;

public JavaStackFrameMock(IJavaReferenceType referenceType, boolean synthetic) {
this.referenceType = referenceType;
this.synthetic = synthetic;
}

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
var methodName = method.getName();
if ("getReferenceType".equals(methodName)) {
return referenceType;
}
if ("isSynthetic".equals(methodName)) {
return synthetic;
}
if ("getLaunch".equals(methodName)) {
return Proxy.newProxyInstance(StackFramePresentationProviderTest.class.getClassLoader(), new Class[] {
ILaunch.class }, new LaunchMock());

}
return null;
}
}

private static class JavaReferenceTypeMock implements InvocationHandler {

final String name;

public JavaReferenceTypeMock(String name) {
this.name = name;
}

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ("getName".equals(method.getName())) {
return name;
}
return null;
}
}

@Override
protected void setUp() throws Exception {
super.setUp();
preferenceStore = new PreferenceStore();
preferenceStore.setValue(IJDIPreferencesConstants.PREF_ACTIVE_PLATFORM_FRAME_FILTER_LIST, "java.*,javax.*");
preferenceStore.setValue(IJDIPreferencesConstants.PREF_COLORIZE_STACK_FRAMES, true);
preferenceStore.setValue(IJDIPreferencesConstants.PREF_COLORIZE_PLATFORM_METHODS, true);
preferenceStore.setValue(IJDIPreferencesConstants.PREF_COLORIZE_CUSTOM_METHODS, true);
preferenceStore.setValue(IJDIPreferencesConstants.PREF_COLORIZE_SYNTHETIC_METHODS, true);
provider = new StackFramePresentationProvider(preferenceStore);
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
provider.close();
}

private IJavaReferenceType createReference(String name) {
return (IJavaReferenceType) Proxy.newProxyInstance(StackFramePresentationProviderTest.class.getClassLoader(), new Class[] {
IJavaReferenceType.class }, new JavaReferenceTypeMock(name));
}

private IJavaStackFrame createFrame(IJavaReferenceType refType, boolean syntetic) {
return (IJavaStackFrame) Proxy.newProxyInstance(StackFramePresentationProviderTest.class.getClassLoader(), new Class[] {
IJavaStackFrame.class }, new JavaStackFrameMock(refType, syntetic));
}

private IJavaStackFrame.Category categorize(String refTypeName, boolean syntetic) throws DebugException {
return categorize(createReference(refTypeName), syntetic);
}

private IJavaStackFrame.Category categorize(IJavaReferenceType refType, boolean syntetic) throws DebugException {
return provider.categorize(createFrame(refType, syntetic));
}

public void testFiltering() throws DebugException {
assertEquals(IJavaStackFrame.Category.SYNTHETIC, categorize("org.eclipse.Something", true));
assertEquals(IJavaStackFrame.Category.PLATFORM, categorize("java.lang.String", false));
assertEquals(IJavaStackFrame.Category.UNKNOWN, categorize("org.eclipse.Other", false));
}

public void testUpdateWorks() throws DebugException {
var something = createReference("org.eclipse.Something");
var other = createReference("org.eclipse.Other");
assertEquals(IJavaStackFrame.Category.UNKNOWN, categorize(something, false));
assertEquals(IJavaStackFrame.Category.UNKNOWN, categorize(other, false));
preferenceStore.setValue(IJDIPreferencesConstants.PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST, "org.eclipse.Something");

assertEquals(IJavaStackFrame.Category.CUSTOM_FILTERED, categorize(something, false));
assertEquals(IJavaStackFrame.Category.UNKNOWN, categorize(other, false));
}

public void testSwitchOffPlatform() throws DebugException {
assertEquals(IJavaStackFrame.Category.PLATFORM, categorize("java.lang.String", false));
preferenceStore.setValue(IJDIPreferencesConstants.PREF_COLORIZE_PLATFORM_METHODS, false);
assertEquals(IJavaStackFrame.Category.UNKNOWN, categorize("java.lang.String", false));
}

}
2 changes: 1 addition & 1 deletion org.eclipse.jdt.debug.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.28.0,4.0.0)",
org.eclipse.debug.ui;bundle-version="[3.13.400,4.0.0)",
org.eclipse.jdt.debug;bundle-version="[3.19.0,4.0.0)",
org.eclipse.jdt.debug;bundle-version="[3.20.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="[3.19.0,4.0.0)",
org.eclipse.jdt.ui;bundle-version="[3.26.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.11.0,4.0.0)",
Expand Down
35 changes: 35 additions & 0 deletions org.eclipse.jdt.debug.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ JavaSnippetEditor.label= Scrapbook
javaStepFilterPrefName=Step Filtering
javaDetailFormattersPrefName=Detail Formatters

javaStackFramePrefName=Stack Frames

javaVariableHoverLabel=Variable Values
javaVariableHoverDescription=Shows the value of the selected variable when debugging.

Expand Down Expand Up @@ -178,6 +180,9 @@ showMonitorThreadInfo.tooltip=Show the Thread & Monitor Information
showNullEntriesAction.label=Show &Null Array Entries
showNullEntriesAction.tooltip=Show Null Array Entries

colorizeStackFrames.label=Mark Stack Frames with &Colors
colorizeStackFrames.tooltip=Based on the function mark the stack frames with different colors

stepIntoSelectionHyperlinkDetector.label=Step Into Selection
stepIntoSelectionHyperlinkDetector.description=Performs the step into selection command on demand via a hyperlink

Expand Down Expand Up @@ -289,6 +294,36 @@ InDeadlockColorDefinition.description=The color used to render deadlocked thread
LabeledObjectColorDefinition.label=Labeled objects
LabeledObjectColorDefinition.description=The color used to render labeled objects in debug views.

CustomFilteredStackFrameFgColorDefinition.label=Highlighted methods
CustomFilteredStackFrameBgColorDefinition.label=Highlighted methods background
CustomFilteredStackFrameFgColorDefinition.description=The color used to render the Highlighted stack frames in the Debug view.
CustomFilteredStackFrameBgColorDefinition.description=The background color used to render the Highlighted stack frames in the Debug view.

SyntheticStackFrameFgColorDefinition.label=Synthetic methods
SyntheticStackFrameBgColorDefinition.label=Synthetic methods background
SyntheticStackFrameFgColorDefinition.description=The color used to render stack frames for synthetic methods in the Debug view.
SyntheticStackFrameBgColorDefinition.description=The background color used to render stack frames for synthetic methods in the Debug view.

PlatformStackFrameFgColorDefinition.label=Platform methods
PlatformStackFrameBgColorDefinition.label=Platform methods background
PlatformStackFrameFgColorDefinition.description=The color used to render stack frames for Platform methods in the Debug view.
PlatformStackFrameBgColorDefinition.description=The background color used to render stack frame for Platform methods in the Debug view.

TestStackFrameFgColorDefinition.label=Your Test code
TestStackFrameBgColorDefinition.label=Your Test code background
TestStackFrameFgColorDefinition.description=The color used to render stack frames for Your Test code in the Debug view.
TestStackFrameBgColorDefinition.description=The background color used to render stack frames for Your Test code in the Debug view.

LibraryStackFrameFgColorDefinition.label=Library code
LibraryStackFrameBgColorDefinition.label=Library code background
LibraryStackFrameFgColorDefinition.description=The color used to render stack frames for Library code in the Debug view.
LibraryStackFrameBgColorDefinition.description=The background color used to render stack frames for Library code in the Debug view.

ProductionStackFrameFgColorDefinition.label=Your Source code
ProductionStackFrameBgColorDefinition.label=Your Source code background
ProductionStackFrameFgColorDefinition.description=The color used used to render stack frames for Your Source code in the Debug view.
ProductionStackFrameBgColorDefinition.description=The background color used to render stack frames for Your Source code in the Debug view.

javaStackTraceConsole.label= Java Stack Trace Console
FormatStackTraceActionDelegate.name= Format
FormatStackTraceActionDelegate.tooltip= Format
Expand Down
118 changes: 118 additions & 0 deletions org.eclipse.jdt.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,15 @@
style="toggle"
menubarPath="org.eclipse.jdt.debug.ui.LaunchView.javaSubmenu/javaPart"
id="org.eclipse.jdt.debug.ui.launchViewActions.ShowMonitorThreadInfo"/>
<action
helpContextId="colorize_stack_frames_action_context"
label="%colorizeStackFrames.label"
tooltip="%colorizeStackFrames.tooltip"
class="org.eclipse.jdt.internal.debug.ui.actions.ColorizeStackFramesAction"
style="toggle"
menubarPath="org.eclipse.jdt.debug.ui.LaunchView.javaSubmenu/javaPart"
id="org.eclipse.jdt.debug.ui.launchViewActions.ColorizeStackFrames"/>

<menu
id="org.eclipse.jdt.debug.ui.LaunchView.javaSubmenu"
label="%LaunchViewJavaSubmenu.label"
Expand Down Expand Up @@ -2484,6 +2493,13 @@
id="org.eclipse.jdt.debug.ui.JavaDebugPreferencePage">
<keywordReference id="org.eclipse.jdt.debug.ui.general"/>
</page>
<page
name="%javaStackFramePrefName"
category="org.eclipse.jdt.debug.ui.JavaDebugPreferencePage"
class="org.eclipse.jdt.internal.debug.ui.JavaStackFramePreferencePage"
id="org.eclipse.jdt.debug.ui.JavaStackFramePreferencePage">
<keywordReference id="org.eclipse.jdt.debug.ui.stepFilters"/>
</page>
<page
name="%javaStepFilterPrefName"
category="org.eclipse.jdt.debug.ui.JavaDebugPreferencePage"
Expand Down Expand Up @@ -3595,6 +3611,108 @@ M4 = Platform-specific fourth key
value="COLOR_RED">
<description>%LabeledObjectColorDefinition.description</description>
</colorDefinition>

<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.CustomFilteredStackFrameFgColor"
isEditable="true"
label="%CustomFilteredStackFrameFgColorDefinition.label"
value="COLOR_LIST_FOREGROUND">
<description>%CustomFilteredStackFrameFgColorDefinition.description</description>
</colorDefinition>
<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.CustomFilteredStackFrameBgColor"
isEditable="true"
label="%CustomFilteredStackFrameBgColorDefinition.label"
value="252,226,186">
<description>%CustomFilteredStackFrameBgColorDefinition.description</description>
</colorDefinition>

<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.SyntheticStackFrameFgColor"
isEditable="true"
label="%SyntheticStackFrameFgColorDefinition.label"
value="202,130,130">
<description>%SyntheticStackFrameFgColorDefinition.description</description>
</colorDefinition>
<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.SyntheticStackFrameBgColor"
isEditable="true"
label="%SyntheticStackFrameBgColorDefinition.label"
value="COLOR_LIST_BACKGROUND">
<description>%SyntheticStackFrameBgColorDefinition.description</description>
</colorDefinition>

<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.PlatformStackFrameFgColor"
isEditable="true"
label="%PlatformStackFrameFgColorDefinition.label"
value="151,203,155">
<description>%PlatformStackFrameFgColorDefinition.description</description>
</colorDefinition>
<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.PlatformStackFrameBgColor"
isEditable="true"
label="%PlatformStackFrameBgColorDefinition.label"
value="COLOR_LIST_BACKGROUND">
<description>%PlatformStackFrameBgColorDefinition.description</description>
</colorDefinition>

<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.TestStackFrameFgColor"
isEditable="true"
label="%TestStackFrameFgColorDefinition.label"
value="COLOR_LIST_FOREGROUND">
<description>%TestStackFrameFgColorDefinition.description</description>
</colorDefinition>
<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.TestStackFrameBgColor"
isEditable="true"
label="%TestStackFrameBgColorDefinition.label"
value="229,253,204">
<description>%TestStackFrameBgColorDefinition.description</description>
</colorDefinition>

<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.ProductionStackFrameFgColor"
isEditable="true"
label="%ProductionStackFrameFgColorDefinition.label"
value="52,101,164">
<description>%ProductionStackFrameFgColorDefinition.description</description>
</colorDefinition>
<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.ProductionStackFrameBgColor"
isEditable="true"
label="%ProductionStackFrameBgColorDefinition.label"
value="COLOR_LIST_BACKGROUND">
<description>%ProductionStackFrameBgColorDefinition.description</description>
</colorDefinition>

<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.LibraryStackFrameFgColor"
isEditable="true"
label="%LibraryStackFrameFgColorDefinition.label"
value="205,167,251">
<description>%LibraryStackFrameFgColorDefinition.description</description>
</colorDefinition>
<colorDefinition
categoryId="org.eclipse.debug.ui.presentation"
id="org.eclipse.jdt.debug.ui.LibraryStackFrameBgColor"
isEditable="true"
label="%LibraryStackFrameBgColorDefinition.label"
value="COLOR_LIST_BACKGROUND">
<description>%LibraryStackFrameBgColorDefinition.description</description>
</colorDefinition>
</extension>
<extension
point="org.eclipse.debug.ui.variableValueEditors">
Expand Down
Loading

0 comments on commit 7a91818

Please sign in to comment.