Skip to content

Commit 5154e9e

Browse files
committed
Remove unnecessary constants, and add way to request category
re-evaluation.
1 parent fc59a6d commit 5154e9e

4 files changed

Lines changed: 58 additions & 25 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,15 @@ public IJavaVariable findVariable(String variableName)
573573

574574
/**
575575
* @since 3.22
576-
* @return the category of the stack frame, null if it's not yet categorized.
576+
* @return the category of the stack frame.
577577
*/
578-
public Category getCategory();
578+
Category getCategory();
579+
580+
/**
581+
* Request re-evaluation of the category.
582+
*
583+
* @since 3.22
584+
*/
585+
void resetCategory();
579586

580587
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,6 @@ public class JDIDebugPlugin extends Plugin implements IEclipsePreferences.IPrefe
150150
*/
151151
public static final String PREF_INACTIVE_PLATFORM_FRAME_FILTER_LIST = JDIDebugPlugin.getUniqueIdentifier() + ".inactive_platform_frames_filters"; //$NON-NLS-1$
152152

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-
160153
/**
161154
* Extension point for java logical structures.
162155
*
@@ -873,7 +866,7 @@ public IAstEvaluationEngine getEvaluationEngine(IJavaProject project,
873866
*/
874867
public synchronized StackFrameCategorizer getStackFrameCategorizer() {
875868
if (stackFrameCategorizer == null) {
876-
stackFrameCategorizer = new StackFrameCategorizer(Platform.getPreferencesService());
869+
stackFrameCategorizer = new StackFrameCategorizer(Platform.getPreferencesService(), getInstancePreferences());
877870
getInstancePreferences().addPreferenceChangeListener(stackFrameCategorizer);
878871
}
879872
return stackFrameCategorizer;

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

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.ArrayList;
1717
import java.util.EnumMap;
1818
import java.util.List;
19-
import java.util.Map;
19+
import java.util.Set;
2020
import java.util.StringTokenizer;
2121
import java.util.stream.Collectors;
2222

@@ -35,14 +35,7 @@
3535
* Service to help categorize the stack frames into {@link IJavaStackFrame.Category}, based on the internally stored preferences.
3636
*/
3737
public class StackFrameCategorizer implements IPreferenceChangeListener {
38-
private final static Map<String, Category> PREFERENCE_MAPPING = Map.of(JDIDebugPlugin.PREF_COLORIZE_CUSTOM_METHODS, Category.CUSTOM_FILTERED, //
39-
JDIDebugPlugin.PREF_COLORIZE_SYNTHETIC_METHODS, Category.SYNTHETIC, //
40-
JDIDebugPlugin.PREF_COLORIZE_PLATFORM_METHODS, Category.PLATFORM, //
41-
JDIDebugPlugin.PREF_COLORIZE_TEST_METHODS, Category.TEST, //
42-
JDIDebugPlugin.PREF_COLORIZE_PRODUCTION_METHODS, Category.PRODUCTION, //
43-
JDIDebugPlugin.PREF_COLORIZE_LIBRARY_METHODS, Category.LIBRARY);
44-
45-
private final static EnumMap<Category, String> REVERSE_MAPPING = new EnumMap<>(PREFERENCE_MAPPING.entrySet().stream().collect(Collectors.toUnmodifiableMap(Map.Entry::getValue, Map.Entry::getKey)));
38+
private final static String PREFIX = JDIDebugPlugin.getUniqueIdentifier() + ".enable_category_"; //$NON-NLS-1$
4639

4740
/**
4841
* Class to decide if a particular class name is part of a list of classes and list of packages.
@@ -68,13 +61,15 @@ boolean match(String fqcName) {
6861
private Filters custom;
6962
private final EnumMap<Category, Boolean> enabledCategories;
7063
private final IPreferencesService preferenceService;
64+
private final IEclipsePreferences instancePreferences;
7165

72-
public StackFrameCategorizer(IPreferencesService preferenceService) {
66+
public StackFrameCategorizer(IPreferencesService preferenceService, IEclipsePreferences instancePreferences) {
7367
this.preferenceService = preferenceService;
68+
this.instancePreferences = instancePreferences;
7469
enabledCategories = new EnumMap<>(Category.class);
75-
for (var kv : PREFERENCE_MAPPING.entrySet()) {
76-
boolean enabled = preferenceService.getBoolean(JDIDebugPlugin.getUniqueIdentifier(), kv.getKey(), true, null);
77-
enabledCategories.put(kv.getValue(), enabled);
70+
for (var category : Category.values()) {
71+
boolean enabled = preferenceService.getBoolean(JDIDebugPlugin.getUniqueIdentifier(), getNameOfTheFlagToEnable(category), true, null);
72+
enabledCategories.put(category, enabled);
7873
}
7974

8075
platform = createActivePlatformFilters();
@@ -187,9 +182,20 @@ public boolean isEnabled(Category category) {
187182
return Boolean.TRUE.equals(enabledCategories.get(category));
188183
}
189184

185+
private String getNameOfTheFlagToEnable(Category category) {
186+
return PREFIX + category.name();
187+
}
188+
189+
private Category getCategoryFromNameOfTheFlag(String flagName) {
190+
if (flagName.startsWith(PREFIX)) {
191+
return Category.valueOf(flagName.substring(PREFIX.length()));
192+
}
193+
return null;
194+
}
195+
190196
public void setEnabled(Category category, boolean flag) {
191197
enabledCategories.put(category, flag);
192-
JDIDebugPlugin.getInstancePreferences().putBoolean(REVERSE_MAPPING.get(category), flag);
198+
instancePreferences.putBoolean(getNameOfTheFlagToEnable(category), flag);
193199
}
194200

195201
/**
@@ -217,11 +223,33 @@ public void preferenceChange(PreferenceChangeEvent event) {
217223
} else if (JDIDebugPlugin.PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST.equals(prop)) {
218224
custom = createActiveCustomFilters();
219225
} else {
220-
var category = PREFERENCE_MAPPING.get(prop);
226+
var category = getCategoryFromNameOfTheFlag(prop);
221227
if (category != null) {
222228
enabledCategories.put(category, (Boolean) event.getNewValue());
223229
}
224230
}
225231
}
226232

233+
/**
234+
* Adds the given class names to the definition of the active list of custom, highlighted classes.
235+
*
236+
* @param classNames
237+
* name of the classes.
238+
*/
239+
public void addTypesToActiveCustomFilters(Set<String> classNames) {
240+
List<String> actives = new ArrayList<>(List.of(getActiveCustomStackFilter()));
241+
List<String> inactives = new ArrayList<>(List.of(getInactiveCustomStackFilter()));
242+
for (String className : classNames) {
243+
inactives.remove(className);
244+
if (!actives.contains(className)) {
245+
actives.add(className);
246+
}
247+
}
248+
instancePreferences.put(JDIDebugPlugin.PREF_ACTIVE_CUSTOM_FRAME_FILTER_LIST, convert(actives));
249+
instancePreferences.put(JDIDebugPlugin.PREF_INACTIVE_CUSTOM_FRAME_FILTER_LIST, convert(inactives));
250+
}
251+
252+
private String convert(List<String> classNames) {
253+
return classNames.stream().collect(Collectors.joining(",")); //$NON-NLS-1$
254+
}
227255
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,4 +1740,9 @@ public synchronized Category getCategory() {
17401740
}
17411741
return fCategory;
17421742
}
1743+
1744+
@Override
1745+
public synchronized void resetCategory() {
1746+
fCategory = null;
1747+
}
17431748
}

0 commit comments

Comments
 (0)