Skip to content

[Cocoa] Correct generation for urlForApplicationToOpen[URL|ContentType]#3435

Open
HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:cocoa-fix-URLForApplicationToOpenContentType
Open

[Cocoa] Correct generation for urlForApplicationToOpen[URL|ContentType]#3435
HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:cocoa-fix-URLForApplicationToOpenContentType

Conversation

@HeikoKlare

@HeikoKlare HeikoKlare commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

NSWorkspace.URLForApplicationToOpenURL: and URLForApplicationToOpenContentType:, introduced as a replacement for deprecated file-association API, were hand-written directly in NSWorkspace.java without registering them for MacGenerator. Since UTType.typeWithFilenameExtension: (the other new API involved, UniformTypeIdentifiers framework, macOS 12+) is not declared in any bridgesupport file, MacGenerator had no way to reproduce these methods and silently dropped them on the next regeneration.

  • Declare the two NSWorkspace selectors and a minimal UTType class (one method) in AppKitFull.bridgesupport/.extras by hand, since neither API exists in the SDK version the bridgesupport files were generated from, and UTType's own framework has no dedicated bridgesupport file in this project. This makes both methods regenerable instead of being a permanent manual exception.
  • Rename the two NSWorkspace methods to the casing MacGenerator derives from the Objective-C selector, matching existing conventions elsewhere (e.g. NSURL.URLWithString).
  • Introduce a proper UTType wrapper class instead of passing its handle around as a raw long, consistent with how every other Cocoa object is represented in this codebase; NSWorkspace.URLForApplicationToOpenContentType now takes a typed UTType argument.
  • Update Program.findAppURLForExtension() to use the generated UTType.typeWithFilenameExtension() wrapper instead of manual objc_getClass/objc_msgSend calls.

The changes in generated code were produced by the MacGenerator tool.

I have verified with a file opened by an external program (Excel) in the workspace that with this change the code still works.

Follow-up to #3187

Hint on this was implicitly given by @Phillipus in #3433 (comment)

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Test Results (macos)

   64 files  ±0     64 suites  ±0   10m 15s ⏱️ + 2m 49s
4 584 tests ±0  4 335 ✅ ±0  249 💤 ±0  0 ❌ ±0 
2 226 runs  ±0  2 160 ✅ ±0   66 💤 ±0  0 ❌ ±0 

Results for commit 345cd8d. ± Comparison against base commit 3f4b535.

♻️ This comment has been updated with latest results.

@Phillipus

Phillipus commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Looking at the following:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=502090
https://bugs.eclipse.org/bugs/show_bug.cgi?id=514191
https://github.com/eclipse-platform/eclipse.platform.swt/blob/master/bundles/org.eclipse.swt/Readme.macOS.md

It seems that there have been times when there was a macOS version update where all the bridge support files have been completely regenerated against a new macOS SDK. The last time was here:

b51b906

Should they have been regenerated since then?

@HeikoKlare HeikoKlare force-pushed the cocoa-fix-URLForApplicationToOpenContentType branch from 7fec402 to aa10550 Compare July 14, 2026 11:09
@HeikoKlare

Copy link
Copy Markdown
Contributor Author

It seems that there have been times when there was a macOS version update where all the bridge support files have been completely regenerated against a new macOS SDK.

Good point. Probably we should do that, yes. We just need to clarify against which macOS SDK version we should do that. It seems possible to pass the minimum supported SDK version to the bridge support generation, but you never know what side effects the actual SDK used might have (like we have seen when building the Equinox binaries against the macOS 26 SDK).

@HeikoKlare

HeikoKlare commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

It seems like regenerating the bridgesupport files would be a task of larger effort. I have just generated one of the files (AppKitFull). It looks different in terms of the properties being used and when running the MacGenerator tool on it, it produces a bunch of unexpected output resulting in 2000 compilation errors.

Thus, I propose to have a separate issue for bridgesupport regeneration.

But with respect to this PR: the freshly created AppKitFull.bridgesupport contains the methods I add in this PR with a matching definition:

<method selector='URLForApplicationToOpenContentType:'>
<arg declared_type64='UTType*' index='0' name='contentType' type64='@'/>
<retval declared_type64='NSURL*' type64='@24@0:8@16'/>
</method>
<method selector='URLForApplicationToOpenURL:'>
<arg declared_type64='NSURL*' index='0' name='url' type64='@'/>
<retval declared_type64='NSURL*' type64='@24@0:8@16'/>
</method>

Also the UTType is generated and looks similar (except for different null checks because of the NonNull/Nullable annotations missing in the above declaration).

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

Ensures the macOS Cocoa bindings for NSWorkspace.URLForApplicationToOpenURL: / URLForApplicationToOpenContentType: and UTType.typeWithFilenameExtension: are fully reproducible by MacGenerator, avoiding silent loss of hand-written bindings during regeneration.

Changes:

  • Adds a generated UTType wrapper and uses it from Program.findAppURLForExtension() instead of raw handle-based Objective-C calls.
  • Renames NSWorkspace Java methods to match MacGenerator’s selector-derived casing and updates call sites accordingly.
  • Extends the bridgesupport inputs to include the missing NSWorkspace selectors and a minimal UTType class so MacGenerator can regenerate these APIs.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java Switches extension→app resolution to use the generated UTType wrapper and updated NSWorkspace method names.
bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/UTType.java Introduces a Cocoa object wrapper for UTType with typeWithFilenameExtension.
bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java Keeps selector enum aligned with generated bindings for the added/renamed selectors.
bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java Adds class_UTType and reorders selector constants to match the selector enum.
bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSWorkspace.java Replaces hand-written methods with generator-aligned method names and a typed UTType parameter.
bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport.extras Adds generator input entries for missing NSWorkspace selectors and a minimal UTType class.
bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/AppKitFull.bridgesupport Contains regenerated bridgesupport output reflecting the new selectors/class.

@HeikoKlare HeikoKlare force-pushed the cocoa-fix-URLForApplicationToOpenContentType branch from aa10550 to 3d2270d Compare July 14, 2026 20:18
NSWorkspace.URLForApplicationToOpenURL: and
URLForApplicationToOpenContentType:, introduced as a replacement for
deprecated file-association API, were hand-written directly in
NSWorkspace.java without registering them for MacGenerator. Since
UTType.typeWithFilenameExtension: (the other new API involved,
UniformTypeIdentifiers framework, macOS 12+) is not declared in any
bridgesupport file, MacGenerator had no way to reproduce these methods
and silently dropped them on the next regeneration.

- Declare the two NSWorkspace selectors and a minimal UTType class (one
  method) in AppKitFull.bridgesupport/.extras by hand, since neither
  API exists in the SDK version the bridgesupport files were generated
  from, and UTType's own framework has no dedicated bridgesupport file
  in this project. This makes both methods regenerable instead of being
  a permanent manual exception.
- Rename the two NSWorkspace methods to the casing MacGenerator derives
  from the Objective-C selector, matching existing conventions
  elsewhere (e.g. NSURL.URLWithString).
- Introduce a proper UTType wrapper class instead of passing its handle
  around as a raw long, consistent with how every other Cocoa object is
  represented in this codebase;
NSWorkspace.URLForApplicationToOpenContentType
  now takes a typed UTType argument.
- Update Program.findAppURLForExtension() to use the generated
  UTType.typeWithFilenameExtension() wrapper instead of manual
  objc_getClass/objc_msgSend calls.

Follow-up to
eclipse-platform#3187
@HeikoKlare HeikoKlare force-pushed the cocoa-fix-URLForApplicationToOpenContentType branch from 3d2270d to 345cd8d Compare July 14, 2026 20:27
@HeikoKlare HeikoKlare marked this pull request as ready for review July 14, 2026 20:27
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.

3 participants