Skip to content

Implements a StyleProcessor class to allow access to a list of set styles for a widget in String format. - #2392

Open
neilcabanilla wants to merge 11 commits into
eclipse-platform:masterfrom
neilcabanilla:processor
Open

Implements a StyleProcessor class to allow access to a list of set styles for a widget in String format.#2392
neilcabanilla wants to merge 11 commits into
eclipse-platform:masterfrom
neilcabanilla:processor

Conversation

@neilcabanilla

Copy link
Copy Markdown

This PR allows us to fix issues with the CSS Spy in Eclipse PDE, detailed in Issue #611 Completed with @WillPeltz

Changes
-StyleProcessor class
Parses styles that can be set based on context, checks relevant styles against integer bitmask to see which are actually set, and converts them into String list

-getStyles method in Text and Button classes
Returns a list of styles currently set for a given widget in String format, allowing for style inspection at runtime

-Static function using instance of StyleProcessor in Text and Button classes
Clearly defines which styles can be set for a widget based on context, in a human-readable way.

Motivation

Currently, there is no built-in way to view a widget’s set styles in a human-readable format, leading to projects like Eclipse PDE implementing complex and limited parsers for UI elements like the CSS Spy tool. This PR makes this process much simpler and easier, without requiring much upkeep. It should be quite simple to add support for and update widget classes.

Notes
-Since this implementation only focuses on Text and Button classes, other widget classes should be revised incrementally to use the StyleProcessor class.

-Backwards compatible; existing behavior is unchanged.
Having both getStyles and checkStyle is a bit redundant, so merging them at some point in the future might be a good idea if it can be done without breaking existing behavior too much in downstream projects.

@merks merks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the implementation details I see, could this not all be done externally without introducing APIs in SWT?

* @return ArrayList<String> styles
* @since 3.131
*/
public ArrayList<String> getStyles() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One would never want to surface the List implementation class in any API; elsewhere too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @merks,

Answering to your question...

Given the implementation details I see, could this not all be done externally without introducing APIs in SWT?

We initially explored other approaches such as implementing it in a utility class or using annotations, however based on the comments and guidance that we got Issue #611. We were advised to directly change the SWT repository, specifically the widget classes instead. That being said, we are flexible and happy to revise the implementation.

One would never want to surface the List implementation class in any API; elsewhere too.

You are right with what you've said. My teammate and I are planning to change this ArrayList to List instead and avoiding making the method public. We've only did it this way for testing purposes to see if it works and get feedback.

Thank you so much!
Teammate - @WillPeltz


import org.eclipse.swt.*;

public class StyleProcessor {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this really become public API or can it just be package protected?

@neilcabanilla neilcabanilla Aug 11, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @merks,

You're absolutely right, we actually intended for StyleProcessor to be package private, so that it can only be accessed within the widgets package. My teammate and I forgot that part, thank you for clarifying.

Thank you so much!
Teammate - @WillPeltz

@laeubi

laeubi commented Aug 8, 2025

Copy link
Copy Markdown
Contributor

The recommendation was to access this reflectively and not to make any public API here.

@WillPeltz

Copy link
Copy Markdown

Hi @laeubi @merks,

Just wanted to follow up on our PR. @neilcabanilla and I took your feedback and made some fixes, so we would really appreciate if you could take another look when you have the chance. Thank you for your time.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces a new StyleProcessor utility intended to turn a widget’s integer style bitmask into a human-readable List<String> of active SWT style names, to support runtime style inspection (e.g., Eclipse PDE CSS Spy).

Changes:

  • Added a Win32-local StyleProcessor class that defines “one-of” and “some-of” style rules and evaluates them against a widget’s style bitmask.
  • Added Win32-only getStyles() methods to Text and Button that return the processed style names.
  • Added static STYLE_PROCESSOR configurations in Text and Button to describe which styles are relevant per widget/context.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java Adds a Win32 STYLE_PROCESSOR configuration and a getStyles() accessor for Text styles.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java Adds a Win32 STYLE_PROCESSOR configuration and a getStyles() accessor for Button styles.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/StyleProcessor.java Introduces the StyleProcessor rule engine used to produce a String list of active SWT style constants.
Comments suppressed due to low confidence (4)

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/StyleProcessor.java:93

  • Avoid writing to stdout from SWT library code and avoid silently continuing after a programmer error. These style names are compile-time constants, so an invalid field should fail fast (e.g., throw IllegalArgumentException).
	    for (String s : someOfArr) {
	        try {
	            if ((style & SWT.class.getField(s).getInt(null)) != 0) {
	                finalList.add(s);
	            }
	        } catch (NoSuchFieldException | IllegalAccessException e) {
	            System.out.println("Invalid Style: " + s);
	        }

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/StyleProcessor.java:108

  • Avoid writing to stdout from SWT library code and avoid silently continuing after a programmer error. If a condition style constant is invalid, fail fast so the bad rule definition is caught during development.
	            try {
	                int flag = SWT.class.getField(condition).getInt(null);
	                if ((style & flag) != 0) {
	                    matched = true;
	                    break;
	                }
	            } catch (NoSuchFieldException | IllegalAccessException e) {
	                System.out.println("Invalid condition: " + condition);
	            }

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/StyleProcessor.java:121

  • Avoid writing to stdout from SWT library code and avoid silently continuing after a programmer error. If a thenOneOf style constant is invalid, fail fast.
	                try {
	                    int flag = SWT.class.getField(s).getInt(null);
	                    if ((style & flag) != 0) {
	                        finalList.add(s);
	                        break;
	                    }
	                } catch (NoSuchFieldException | IllegalAccessException e) {
	                    System.out.println("Invalid thenOneOf: " + s);
	                }

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/StyleProcessor.java:132

  • Avoid writing to stdout from SWT library code and avoid silently continuing after a programmer error. Also, remove the extra trailing semicolon.
	                try {
	                    int flag = SWT.class.getField(s).getInt(null);
	                    if ((style & flag) != 0) {
	                        finalList.add(s);
	                    }
	                } catch (NoSuchFieldException | IllegalAccessException e) {
	                    System.out.println("Invalid thenSomeOf: " + s);;
	                }

}

static int checkStyle (int style) {
System.out.println(STYLE_PROCESSOR.process(style));
Comment on lines 14 to 17
package org.eclipse.swt.widgets;


import java.util.List;
import java.util.*;

Comment on lines 15 to 18
package org.eclipse.swt.widgets;

import java.util.List;
import java.util.*;

Comment on lines +666 to +668
List<String> getStyles() {
return STYLE_PROCESSOR.process(this.style);
}
Comment on lines +291 to 293
List<String> getStyles() {
return STYLE_PROCESSOR.process(this.style);
}
Comment on lines +80 to +82
} catch (NoSuchFieldException | IllegalAccessException e) {
System.out.println("Invalid Style: " + s);
}
@github-actions

Copy link
Copy Markdown
Contributor

Test Results (win32)

   33 files  ±0     33 suites  ±0   4m 49s ⏱️ -27s
4 861 tests ±0  4 785 ✅ ±0  76 💤 ±0  0 ❌ ±0 
1 390 runs  ±0  1 366 ✅ ±0  24 💤 ±0  0 ❌ ±0 

Results for commit 31e6c5f. ± Comparison against base commit 7b3acfd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants