Skip to content

Add IStructuredSelection.stream(Class) for typed selection access - #4579

Open
vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:issue-1376-typed-selection-list
Open

vogella wants to merge 1 commit into
eclipse-platform:masterfrom
vogella:issue-1376-typed-selection-list

Conversation

@vogella

@vogella vogella commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Getting the selected elements of a specific type out of an IStructuredSelection currently needs a raw-type cast or a stream().filter(type::isInstance).map(type::cast) chain at every call site. This adds a default <T> Stream<T> stream(Class<T> type) method that returns the selected elements of the given type in selection order, so callers can write viewer.getStructuredSelection().stream(IResource.class).toList(), .findFirst(), or collect into any target type.

Since it is a default method, existing implementations pick it up without changes. AbstractSelectionDialog.setResult(ISelection, Class) is simplified to use it as well.

Fixes #1376

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

   867 files  ±0     867 suites  ±0   54m 41s ⏱️ - 10m 33s
 8 607 tests ±0   8 367 ✅ ±0  240 💤 ±0  0 ❌ ±0 
21 690 runs  ±0  21 017 ✅ ±0  673 💤 ±0  0 ❌ ±0 

Results for commit 1cedc74. ± Comparison against base commit 6863d5e.

♻️ This comment has been updated with latest results.

@laeubi laeubi 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.

Why not adding <T> Stream<T> stream(Class<T> type) instead what would allow collection into any type (including toList())?

Otherwise the next one want an generic toArray(), toX ... I though I even have suggested that in the initial design but back then I think @mickaelistria has objected so we ended with a very minimal API.

@vogella
vogella force-pushed the issue-1376-typed-selection-list branch from abc0ead to 89566a4 Compare December 2, 2026 15:19
@vogella vogella changed the title Add IStructuredSelection.toList(Class) for typed selection access Add IStructuredSelection.stream(Class) for typed selection access Dec 2, 2026
@vogella
vogella requested a review from laeubi December 2, 2026 15:19
Returns the selected elements that are instances of the given type as a
Stream in selection order, replacing the common filter and cast stream
idiom and allowing callers to collect into lists, findFirst(), etc.

The added default method is binary compatible, so it is filtered like
the IStructuredSelection.stream() addition and the bundle version stays
a minor bump.

Fixes eclipse-platform#1376

Assisted-by: multiple AI agents and layers of automated tooling 🤖
@vogella
vogella force-pushed the issue-1376-typed-selection-list branch from 89566a4 to 1cedc74 Compare December 3, 2026 07:40
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.

Option to get the StructuredSelection as a typed list

2 participants