Skip to content

Commit 84bc37e

Browse files
committed
Refactor the logic
Instead of the UI manage the preferences and the rules, the JDIDebugPlugin could do that.
1 parent f66ce57 commit 84bc37e

File tree

9 files changed

+314
-181
lines changed

9 files changed

+314
-181
lines changed

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/IJDIPreferencesConstants.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,6 @@ public interface IJDIPreferencesConstants {
8181

8282
public static final String PREF_COLLAPSE_STACK_FRAMES = IJavaDebugUIConstants.PLUGIN_ID + ".collapse_stack_frames"; //$NON-NLS-1$
8383

84-
/**
85-
* List of active filters for custom stack frame categorization. A String containing a comma separated list of fully qualified type
86-
* names/patterns.
87-
*/
88-
public static final String PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST = IJavaDebugUIConstants.PLUGIN_ID + ".active_custom_frames_filters"; //$NON-NLS-1$
89-
90-
/**
91-
* List of inactive filters for custom stack frame categorization. A String containing a comma separated list of fully qualified type
92-
* names/patterns.
93-
*/
94-
public static final String PREF_INACTIVE_CUSTOM_FRAME_FILTER_LIST = IJavaDebugUIConstants.PLUGIN_ID + ".inactive_custom_frames_filters"; //$NON-NLS-1$
95-
96-
/**
97-
* List of active filters for custom stack frame categorization. A String containing a comma separated list of fully qualified type
98-
* names/patterns.
99-
*/
100-
public static final String PREF_ACTIVE_PLATFORM_FRAME_FILTER_LIST = IJavaDebugUIConstants.PLUGIN_ID + ".active_platform_frames_filters"; //$NON-NLS-1$
101-
102-
/**
103-
* List of inactive filters for custom stack frame categorization. A String containing a comma separated list of fully qualified type
104-
* names/patterns.
105-
*/
106-
public static final String PREF_INACTIVE_PLATFORM_FRAME_FILTER_LIST = IJavaDebugUIConstants.PLUGIN_ID + ".inactive_platform_frames_filters"; //$NON-NLS-1$
107-
10884
/**
10985
* List of active step filters. A String containing a comma separated list of fully qualified type names/patterns.
11086
*/

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPreferenceInitializer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
2121
import org.eclipse.jface.preference.IPreferenceStore;
2222
import org.eclipse.jface.util.PropertyChangeEvent;
23-
import org.eclipse.jface.util.Util;
2423

2524
public class JDIDebugUIPreferenceInitializer extends AbstractPreferenceInitializer {
2625

@@ -47,10 +46,6 @@ public void initializeDefaultPreferences() {
4746
store.setDefault(IJDIPreferencesConstants.PREF_INACTIVE_FILTERS_LIST, "com.ibm.*,com.sun.*,java.*,javax.*,jdk.*,jrockit.*,org.omg.*,sun.*,sunw.*"); //$NON-NLS-1$
4847
store.setDefault(IJDIPreferencesConstants.PREF_STEP_THRU_FILTERS, true);
4948

50-
store.setDefault(IJDIPreferencesConstants.PREF_ACTIVE_PLATFORM_FRAME_FILTER_LIST, "java.*,javax.*,jdk.*,sun.*,sunw.*,org.junit.*,org.eclipse.jdt.internal.*"); //$NON-NLS-1$
51-
store.setDefault(IJDIPreferencesConstants.PREF_INACTIVE_PLATFORM_FRAME_FILTER_LIST, Util.ZERO_LENGTH_STRING);
52-
store.setDefault(IJDIPreferencesConstants.PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST, Util.ZERO_LENGTH_STRING);
53-
store.setDefault(IJDIPreferencesConstants.PREF_INACTIVE_CUSTOM_FRAME_FILTER_LIST, Util.ZERO_LENGTH_STRING);
5449
store.setDefault(IJDIPreferencesConstants.PREF_COLLAPSE_STACK_FRAMES, true);
5550

5651
store.setDefault(IDebugUIConstants.ID_VARIABLE_VIEW + "." + IJDIPreferencesConstants.PREF_SHOW_CONSTANTS, false); //$NON-NLS-1$

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/StackFramePresentationProvider.java

Lines changed: 12 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.internal.debug.ui;
1515

16-
import org.eclipse.core.resources.IFile;
17-
import org.eclipse.debug.core.DebugException;
18-
import org.eclipse.jdt.core.IClassFile;
19-
import org.eclipse.jdt.core.JavaCore;
2016
import org.eclipse.jdt.debug.core.IJavaStackFrame;
21-
import org.eclipse.jdt.debug.core.IJavaStackFrame.Category;
2217
import org.eclipse.jdt.internal.ui.JavaPluginImages;
23-
import org.eclipse.jdt.internal.ui.filtertable.FilterManager;
2418
import org.eclipse.jface.preference.IPreferenceStore;
2519
import org.eclipse.jface.resource.ImageDescriptor;
2620
import org.eclipse.jface.util.IPropertyChangeListener;
@@ -33,59 +27,15 @@
3327
*/
3428
public final class StackFramePresentationProvider implements IPropertyChangeListener {
3529

36-
public static final FilterManager PLATFORM_STACK_FRAMES = new FilterManager(IJDIPreferencesConstants.PREF_ACTIVE_PLATFORM_FRAME_FILTER_LIST, IJDIPreferencesConstants.PREF_INACTIVE_PLATFORM_FRAME_FILTER_LIST);
37-
public static final FilterManager CUSTOM_STACK_FRAMES = new FilterManager(IJDIPreferencesConstants.PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST, IJDIPreferencesConstants.PREF_INACTIVE_CUSTOM_FRAME_FILTER_LIST);
38-
39-
/**
40-
* Class to decide if a particular class name is part of a list of classes and list of packages.
41-
*/
42-
record Filters(String[] filters) {
43-
boolean match(String fqcName) {
44-
for (String filter : filters) {
45-
if (filter.endsWith("*")) { //$NON-NLS-1$
46-
if (fqcName.startsWith(filter.substring(0, filter.length() - 1))) {
47-
return true;
48-
}
49-
} else {
50-
if (filter.equals(fqcName)) {
51-
return true;
52-
}
53-
}
54-
}
55-
return false;
56-
}
57-
}
58-
59-
private Filters platform;
60-
private Filters custom;
6130
private final IPreferenceStore store;
6231
private boolean collapseStackFrames;
6332

6433
public StackFramePresentationProvider(IPreferenceStore store) {
6534
this.store = store;
66-
platform = createActivePlatformFilters(store);
67-
custom = createActiveCustomFilters(store);
6835
store.addPropertyChangeListener(this);
6936
collapseStackFrames = store.getBoolean(IJDIPreferencesConstants.PREF_COLLAPSE_STACK_FRAMES);
7037
}
7138

72-
/**
73-
* Create a {@link Filters} object to decide if a class is part of the 'platform'. The platform definition is stored in the
74-
* {@link IPreferenceStore}. By default, this is the classes provided by the JVM.
75-
*
76-
*/
77-
private Filters createActivePlatformFilters(IPreferenceStore store) {
78-
return new Filters(PLATFORM_STACK_FRAMES.getActiveList(store));
79-
}
80-
81-
/**
82-
* Create a {@link Filters} object to decide if a class is considered part of a custom, very important layer, which needs to be highlighted. This
83-
* definition is stored in the {@link IPreferenceStore}. By default, this is an empty list.
84-
*/
85-
private Filters createActiveCustomFilters(IPreferenceStore store) {
86-
return new Filters(CUSTOM_STACK_FRAMES.getActiveList(store));
87-
}
88-
8939
public StackFramePresentationProvider() {
9040
this(JDIDebugUIPlugin.getDefault().getPreferenceStore());
9141
}
@@ -94,90 +44,20 @@ public StackFramePresentationProvider() {
9444
* @return the category specific image for the stack frame, or null, if there is no one defined.
9545
*/
9646
public ImageDescriptor getStackFrameImage(IJavaStackFrame frame) {
97-
var category = getCategory(frame);
98-
if (category != null) {
99-
switch (category) {
100-
case LIBRARY:
101-
case SYNTHETIC:
102-
case PLATFORM:
103-
return JavaPluginImages.DESC_OBJS_JAR;
104-
default:
105-
break;
106-
}
107-
}
108-
return null;
109-
}
110-
111-
/**
112-
* @return the {@link IJavaStackFrame.Category} which matches the rules - and store the category inside the frame, if the category is already
113-
* calculated for the frame this just retrieves that.
114-
*/
115-
public IJavaStackFrame.Category getCategory(IJavaStackFrame frame) {
116-
if (frame.getCategory() != null) {
117-
return frame.getCategory();
118-
}
119-
IJavaStackFrame.Category result = Category.UNKNOWN;
120-
try {
121-
result = categorize(frame);
122-
} catch (DebugException e) {
123-
JDIDebugUIPlugin.log(e);
124-
}
125-
frame.setCategory(result);
126-
return result;
127-
}
128-
129-
private boolean isEnabled(@SuppressWarnings("unused") Category category) {
130-
// Category will be used in subsequent changes.
131-
return true;
132-
}
133-
134-
/**
135-
* Categorize the given {@link IJavaStackFrame} into a {@link Category} based on the rules and filters, and where those classes are in the
136-
* project. For example if in a source folder, in a library or in a test source folder, etc.
137-
*/
138-
public IJavaStackFrame.Category categorize(IJavaStackFrame frame) throws DebugException {
139-
var refTypeName = frame.getReferenceType().getName();
140-
if (isEnabled(Category.CUSTOM_FILTERED) && custom.match(refTypeName)) {
141-
return Category.CUSTOM_FILTERED;
142-
}
143-
if (isEnabled(Category.SYNTHETIC) && frame.isSynthetic()) {
144-
return Category.SYNTHETIC;
145-
}
146-
if (isEnabled(Category.PLATFORM) && platform.match(refTypeName)) {
147-
return Category.PLATFORM;
148-
}
149-
150-
return categorizeSourceElement(frame);
151-
}
152-
153-
/**
154-
* Do the categorization with the help of a {@link org.eclipse.debug.core.model.ISourceLocator} coming from the associated
155-
* {@link org.eclipse.debug.core.ILaunch}. This is how we can find, if the class file is in a jar or comes from a source folder.
156-
*/
157-
private Category categorizeSourceElement(IJavaStackFrame frame) {
158-
var sourceLocator = frame.getLaunch().getSourceLocator();
159-
if (sourceLocator == null) {
160-
return Category.UNKNOWN;
161-
}
162-
var source = sourceLocator.getSourceElement(frame);
163-
if (source == null) {
164-
return Category.UNKNOWN;
165-
}
166-
if (source instanceof IFile file) {
167-
if (isEnabled(Category.TEST)) {
168-
var jproj = JavaCore.create(file.getProject());
169-
var cp = jproj.findContainingClasspathEntry(file);
170-
if (cp != null && cp.isTest()) {
171-
return Category.TEST;
47+
if (collapseStackFrames) {
48+
var category = frame.getCategory();
49+
if (category != null) {
50+
switch (category) {
51+
case LIBRARY:
52+
case SYNTHETIC:
53+
case PLATFORM:
54+
return JavaPluginImages.DESC_OBJS_JAR;
55+
default:
56+
break;
17257
}
17358
}
174-
if (isEnabled(Category.PRODUCTION)) {
175-
return Category.PRODUCTION;
176-
}
177-
} else if (source instanceof IClassFile && isEnabled(Category.LIBRARY)) {
178-
return Category.LIBRARY;
17959
}
180-
return Category.UNKNOWN;
60+
return null;
18161
}
18262

18363
/**
@@ -190,11 +70,7 @@ public void close() {
19070
@Override
19171
public void propertyChange(PropertyChangeEvent event) {
19272
String prop = event.getProperty();
193-
if (IJDIPreferencesConstants.PREF_ACTIVE_PLATFORM_FRAME_FILTER_LIST.equals(prop)) {
194-
platform = createActivePlatformFilters(store);
195-
} else if (IJDIPreferencesConstants.PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST.equals(prop)) {
196-
custom = createActiveCustomFilters(store);
197-
} else if (IJDIPreferencesConstants.PREF_COLLAPSE_STACK_FRAMES.equals(prop)) {
73+
if (IJDIPreferencesConstants.PREF_COLLAPSE_STACK_FRAMES.equals(prop)) {
19874
collapseStackFrames = (Boolean) event.getNewValue();
19975
}
20076
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/monitors/JavaThreadContentProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private List<Object> getStackFrames(IJavaThread thread) throws DebugException {
153153
first = false;
154154
} else {
155155
if (frame instanceof JDIStackFrame javaFrame) {
156-
var category = stackFrameProvider.getCategory(javaFrame);
156+
var category = javaFrame.getCategory();
157157
if (category == null || category == Category.TEST || category == Category.PRODUCTION || category == Category.CUSTOM_FILTERED) {
158158
result.add(javaFrame);
159159
lastGroupping = null;

org.eclipse.jdt.debug/model/org/eclipse/jdt/debug/core/IJavaStackFrame.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,6 @@ public IJavaVariable findVariable(String variableName)
571571
*/
572572
public void forceReturn(IJavaValue value) throws DebugException;
573573

574-
/**
575-
* @since 3.22
576-
* @param category
577-
* the new category of the stack frame.
578-
*/
579-
public void setCategory(Category category);
580-
581574
/**
582575
* @since 3.22
583576
* @return the category of the stack frame, null if it's not yet categorized.

org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/JDIDebugPlugin.java

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,45 @@ public class JDIDebugPlugin extends Plugin implements IEclipsePreferences.IPrefe
118118
public static final String PREF_ENABLE_ADVANCED_SOURCELOOKUP = JDIDebugPlugin
119119
.getUniqueIdentifier() + ".enable_advanced_sourcelookup"; //$NON-NLS-1$
120120

121+
/**
122+
* List of active filters for custom stack frame categorization. A String containing a comma separated list of fully qualified type
123+
* names/patterns.
124+
*
125+
* @since 3.22
126+
*/
127+
public static final String PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST = JDIDebugPlugin.getUniqueIdentifier() + ".active_custom_frames_filters"; //$NON-NLS-1$
128+
129+
/**
130+
* List of inactive filters for custom stack frame categorization. A String containing a comma separated list of fully qualified type
131+
* names/patterns.
132+
*
133+
* @since 3.22
134+
*/
135+
public static final String PREF_INACTIVE_CUSTOM_FRAME_FILTER_LIST = JDIDebugPlugin.getUniqueIdentifier() + ".inactive_custom_frames_filters"; //$NON-NLS-1$
136+
137+
/**
138+
* List of active filters for custom stack frame categorization. A String containing a comma separated list of fully qualified type
139+
* names/patterns.
140+
*
141+
* @since 3.22
142+
*/
143+
public static final String PREF_ACTIVE_PLATFORM_FRAME_FILTER_LIST = JDIDebugPlugin.getUniqueIdentifier() + ".active_platform_frames_filters"; //$NON-NLS-1$
144+
145+
/**
146+
* List of inactive filters for custom stack frame categorization. A String containing a comma separated list of fully qualified type
147+
* names/patterns.
148+
*
149+
* @since 3.22
150+
*/
151+
public static final String PREF_INACTIVE_PLATFORM_FRAME_FILTER_LIST = JDIDebugPlugin.getUniqueIdentifier() + ".inactive_platform_frames_filters"; //$NON-NLS-1$
152+
153+
public static final String PREF_COLORIZE_PLATFORM_METHODS = JDIDebugPlugin.getUniqueIdentifier() + ".colorize_platform_methods"; //$NON-NLS-1$
154+
public static final String PREF_COLORIZE_SYNTHETIC_METHODS = JDIDebugPlugin.getUniqueIdentifier() + ".colorize_synthetic_methods"; //$NON-NLS-1$
155+
public static final String PREF_COLORIZE_LIBRARY_METHODS = JDIDebugPlugin.getUniqueIdentifier() + ".colorize_library_methods"; //$NON-NLS-1$
156+
public static final String PREF_COLORIZE_TEST_METHODS = JDIDebugPlugin.getUniqueIdentifier() + ".colorize_test_methods"; //$NON-NLS-1$
157+
public static final String PREF_COLORIZE_PRODUCTION_METHODS = JDIDebugPlugin.getUniqueIdentifier() + ".colorize_production_methods"; //$NON-NLS-1$
158+
public static final String PREF_COLORIZE_CUSTOM_METHODS = JDIDebugPlugin.getUniqueIdentifier() + ".colorize_custom_methods"; //$NON-NLS-1$
159+
121160
/**
122161
* Extension point for java logical structures.
123162
*
@@ -210,6 +249,8 @@ IStatus.INFO, getUniqueIdentifier(), INFO_EVALUATION_STACK_FRAME,
210249
*/
211250
private BreakpointListenerManager fJavaBreakpointManager;
212251

252+
private StackFrameCategorizer stackFrameCategorizer;
253+
213254
/**
214255
* Returns whether the debug UI plug-in is in trace mode.
215256
*
@@ -308,7 +349,7 @@ public void rollback(ISaveContext c) {
308349

309350
@Override
310351
public void saving(ISaveContext c) throws CoreException {
311-
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(getUniqueIdentifier());
352+
IEclipsePreferences node = getInstancePreferences();
312353
if(node != null) {
313354
try {
314355
node.flush();
@@ -321,12 +362,19 @@ public void saving(ISaveContext c) throws CoreException {
321362
JavaHotCodeReplaceManager.getDefault().startup();
322363
fBreakpointListeners = new ListenerList<>();
323364
fJavaBreakpointManager = new BreakpointListenerManager();
324-
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(getUniqueIdentifier());
365+
IEclipsePreferences node = getInstancePreferences();
325366
if(node != null) {
326367
node.addPreferenceChangeListener(this);
327368
}
328369
}
329370

371+
/**
372+
* @return the plugin's preferences from the InstanceScope.
373+
*/
374+
public static IEclipsePreferences getInstancePreferences() {
375+
return InstanceScope.INSTANCE.getNode(getUniqueIdentifier());
376+
}
377+
330378
/**
331379
* Adds the given hot code replace listener to the collection of listeners
332380
* that will be notified by the hot code replace manager in this plug-in.
@@ -355,9 +403,12 @@ public void removeHotCodeReplaceListener(IJavaHotCodeReplaceListener listener) {
355403
@Override
356404
public void stop(BundleContext context) throws Exception {
357405
try {
358-
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(getUniqueIdentifier());
406+
IEclipsePreferences node = getInstancePreferences();
359407
if(node != null) {
360408
node.removePreferenceChangeListener(this);
409+
if (stackFrameCategorizer != null) {
410+
node.removePreferenceChangeListener(stackFrameCategorizer);
411+
}
361412
}
362413
JavaHotCodeReplaceManager.getDefault().shutdown();
363414
ILaunchManager launchManager = DebugPlugin.getDefault()
@@ -816,4 +867,16 @@ public IAstEvaluationEngine getEvaluationEngine(IJavaProject project,
816867
}
817868
return null;
818869
}
870+
871+
/**
872+
* @return the service that helps categorizing the stack frames.
873+
*/
874+
public synchronized StackFrameCategorizer getStackFrameCategorizer() {
875+
if (stackFrameCategorizer == null) {
876+
stackFrameCategorizer = new StackFrameCategorizer(Platform.getPreferencesService());
877+
getInstancePreferences().addPreferenceChangeListener(stackFrameCategorizer);
878+
}
879+
return stackFrameCategorizer;
880+
}
881+
819882
}

org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/JDIDebugPluginPreferenceInitializer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,10 @@ public void initializeDefaultPreferences() {
5050
node.putBoolean(JDIDebugModel.PREF_SHOW_STEP_RESULT_REMOTE, false);
5151
node.putInt(JDIDebugModel.PREF_SHOW_STEP_TIMEOUT, JDIDebugModel.DEF_SHOW_STEP_TIMEOUT);
5252
node.putBoolean(JDIDebugPlugin.PREF_ENABLE_ADVANCED_SOURCELOOKUP, true);
53+
54+
node.put(JDIDebugPlugin.PREF_ACTIVE_PLATFORM_FRAME_FILTER_LIST, "java.*,javax.*,jdk.*,sun.*,sunw.*,org.junit.*,org.eclipse.jdt.internal.*"); //$NON-NLS-1$
55+
node.put(JDIDebugPlugin.PREF_INACTIVE_PLATFORM_FRAME_FILTER_LIST, ""); //$NON-NLS-1$
56+
node.put(JDIDebugPlugin.PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST, ""); //$NON-NLS-1$
57+
node.put(JDIDebugPlugin.PREF_INACTIVE_CUSTOM_FRAME_FILTER_LIST, ""); //$NON-NLS-1$
5358
}
5459
}

0 commit comments

Comments
 (0)