Skip to content

Feat: 'Default' @ExtensionMethod extensions - #4010

Open
screret wants to merge 3 commits into
projectlombok:masterfrom
screret:default-extension-methods
Open

Feat: 'Default' @ExtensionMethod extensions#4010
screret wants to merge 3 commits into
projectlombok:masterfrom
screret:default-extension-methods

Conversation

@screret

@screret screret commented Feb 12, 2026

Copy link
Copy Markdown

Description

This PR introduces the lombok.extensionMethod.defaultExtensions and lombok.extensionMethod.suppressBaseMethods configuration keys, allowing extension method usage without explicitly applying @ExtensionMethod({MyExtensions.class, MyExtensions2.class, ...}) to every class via lombok.config.
Using the annotation still requires explicitly defining an extension, but it can be left empty if one (for whatever reason) only wants to change the suppressBaseMethods value for a class.

If suppressBaseMethods isn't defined, the configuration value is applied (default: true).
Extensions in the lombok.extensionMethod.suppressBaseMethods configuration are applied in addition to explicitly defined ones. As far as I can tell, defining an extension twice doesn't have any adverse effects.

Changes

  • Added EXTENSION_METHOD_SUPPRESS_BASE_METHODS key in ConfigurationKeys.java.
  • Added EXTENSION_METHOD_DEFAULT_EXTENSIONS key in ConfigurationKeys.java.
  • Made HandleExtensionMethod an AST adapter.

Additional Information

The code is loosely based on HandleFieldDefaults.
I did not fix the Eclipse handler, because I don't know how, and I assume you know better than I do.

Getting the project to compile was surprisingly annoying, though that might just be me not wanting to use Eclipse. IntelliJ wasn't happy with the java 6 requirement and duplicate dependency classes, but I got it working.
Sometimes I had to delete a stub class, recompile, and add the stub back. That made it mysteriously work 10/10 times. It worked, though, so I'm not complaining.

@nealeu

nealeu commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

This is definitely going to need tests.

The lombok.config settings can be varied in the before fixture as done in NonNullWithAssertion.

I'd also be interested in what performance impact there could potentially be having something apply by default.

@Rawi01

Rawi01 commented Feb 25, 2026

Copy link
Copy Markdown
Collaborator

I implemented something similar years ago: Rawi01@516e0c7

If I remember correctly it slows down compilation and @rzwitserloot was not happy about that.

@nealeu

nealeu commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

I implemented something similar years ago: Rawi01@516e0c7

If I remember correctly it slows down compilation and @rzwitserloot was not happy about that.

This is what I would suspect. Doing extension functions is probably way more efficient as part of the compile stage rather than as an annotation processing step.

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