1313 *******************************************************************************/
1414package 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 ;
2016import org .eclipse .jdt .debug .core .IJavaStackFrame ;
21- import org .eclipse .jdt .debug .core .IJavaStackFrame .Category ;
2217import org .eclipse .jdt .internal .ui .JavaPluginImages ;
23- import org .eclipse .jdt .internal .ui .filtertable .FilterManager ;
2418import org .eclipse .jface .preference .IPreferenceStore ;
2519import org .eclipse .jface .resource .ImageDescriptor ;
2620import org .eclipse .jface .util .IPropertyChangeListener ;
3327 */
3428public 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 }
0 commit comments