Skip to content

Refactor Image for Readability #1667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

amartya4256
Copy link
Contributor

This contribution refactors the Image class to improve readability. The following refactoring have been done:

  1. Encapsulating Image metadata, i.e. Handle, width, height and zoom information per zoom level.
  2. Abstracting ImageProviders, i.e. ImageDataProvider, ImageFileNameProvider.

contributes to #62 and #127

Copy link
Contributor

github-actions bot commented Dec 16, 2024

Test Results

   382 files  ±0     382 suites  ±0   6m 44s ⏱️ - 1m 1s
 4 251 tests ±0   4 239 ✅  - 2   9 💤 ±0  1 ❌ ±0  2 🔥 +2 
12 305 runs  ±0  12 211 ✅  - 2  91 💤 ±0  1 ❌ ±0  2 🔥 +2 

For more details on these failures and errors, see this check.

Results for commit 231cd1e. ± Comparison against base commit 62ad8d9.

♻️ This comment has been updated with latest results.

@amartya4256 amartya4256 force-pushed the imageMetadata branch 2 times, most recently from 22e154f to 035b5c4 Compare December 16, 2024 15:37
This commit refactors usage of ImageDataProvider and
ImageFilenameProvider to make the code more readable.

contributes to eclipse-platform#62 and eclipse-platform#127
- Rename AbstractImageProvider to AbstractImageProviderWrapper
- Changed equals implemenation (made it shorter)
- Added Objects.requireNonNull to constructors in subclasses of
AbstractImageProviderWrapper
- Changed return type of method createCopy(...) in subclasses
- Remove class StaticZoomUpdater
Copy link
Contributor

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

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

@amartya4256 I made some changes in 2 extra commits so you can review it better.

Here are my changes:

  • Rename AbstractImageProvider to AbstractImageProviderWrapper

  • Changed equals implemenation (made it shorter)

  • Added Objects.requireNonNull to constructors in subclasses of AbstractImageProviderWrapper

  • Changed return type of method createCopy(...) in subclasses

  • Remove class StaticZoomUpdater (separate commit)

The part I would like you to check and validate/revert is the one about adding Objects.requireNonNull(...) to constructors since I can only assume that the providers that the subclasses hold are never null. My assumption is merely based on the fact that you didn't check for null in the equals(...) / hashCode() methods in those subclasses, but if you are not sure about this then please add null-checks to those methods and remove Objects.requireNonNull(...) from the constructors.

The ball is on your side again and therefore I marked this PR as "changes requested" ;-)

@amartya4256
Copy link
Contributor Author

@amartya4256 I made some changes in 2 extra commits so you can review it better.

Here are my changes:

  • Rename AbstractImageProvider to AbstractImageProviderWrapper
  • Changed equals implemenation (made it shorter)
  • Added Objects.requireNonNull to constructors in subclasses of AbstractImageProviderWrapper
  • Changed return type of method createCopy(...) in subclasses
  • Remove class StaticZoomUpdater (separate commit)

The part I would like you to check and validate/revert is the one about adding Objects.requireNonNull(...) to constructors since I can only assume that the providers that the subclasses hold are never null. My assumption is merely based on the fact that you didn't check for null in the equals(...) / hashCode() methods in those subclasses, but if you are not sure about this then please add null-checks to those methods and remove Objects.requireNonNull(...) from the constructors.

The ball is on your side again and therefore I marked this PR as "changes requested" ;-)

It looks good to go.

@fedejeanne
Copy link
Contributor

Ignoring the usual suspects: #1676 and #1564

@fedejeanne fedejeanne merged commit 37314de into eclipse-platform:master Dec 19, 2024
5 of 10 checks passed
fedejeanne added a commit to fedejeanne/eclipse.platform.swt that referenced this pull request Dec 20, 2024
fedejeanne added a commit to fedejeanne/eclipse.platform.swt that referenced this pull request Dec 20, 2024
In inner classes of Image.

Fixes eclipse-platform#1667
@fedejeanne
Copy link
Contributor

These 2 tests in Test_org_eclipse_swt_graphics_Image failed with a NPE in yesterday's I-BUILD:

  • test_ConstructorLorg_eclipse_swt_graphics_Device_ImageDataProvider
  • test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvider

The exception is:

java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:233)
at org.eclipse.swt.graphics.Image$ImageDataProviderWrapper.<init>(Image.java:2114)
at org.eclipse.swt.graphics.Image.<init>(Image.java:592)
...

I created a PR to fix them: #1688

fedejeanne added a commit that referenced this pull request Dec 20, 2024
In inner classes of Image.

Fixes #1667
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.

Extract image data provider details into internal subclasses
2 participants