Skip to content
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

Add support for method references invoking extension methods #665

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

EotT123
Copy link
Contributor

@EotT123 EotT123 commented Jan 22, 2025

@rsmckinney
Copy link
Member

Looking good! Does it handle all types of method references?

Foo foo = getFoo();
// where
(a, b) -> foo.bar(a, b)
// replaces
foo::bar

@EotT123
Copy link
Contributor Author

EotT123 commented Jan 24, 2025

Yes, there is already a test for that case.
The following code

Map<String, Integer> map = new LinkedHashMap<>();
map.add( "Foo", 1 );
map.add( "Bar", 2 );
assertEquals( Arrays.asList( "Foo1", "Bar2"), 
    map.map( String::concatenate ).collect( Collectors.toList()));

Is replaced by:

Map<String, Integer> map = new LinkedHashMap();
MyMapExt.add(map, "Foo", 1);
MyMapExt.add(map, "Bar", 2);
assertEquals(Arrays.asList("Foo1", "Bar2"), 
    MyMapExt.map(map, (var0, var1) -> MyStringExt.concatenate(var0, var1)).collect(Collectors.toList()));

I've already implemented support for extension methods and structural interfaces.
The remaining tasks are handling methods that return auto and tuples. Since tuples are part of a separate module, I'll need to do some refactoring to make the code reusable across both modules. But I'm not sure if handling auto and tuples is possible?
Since tuples are located in another module, maybe this can be postponed to another PR?

@EotT123 EotT123 force-pushed the #664_method-ref-extensions branch 2 times, most recently from 5861010 to 1f237ce Compare January 24, 2025 19:24
@EotT123 EotT123 force-pushed the #664_method-ref-extensions branch from 1f237ce to ad22565 Compare January 24, 2025 19:25
@EotT123 EotT123 changed the title WIP: Add support for method references invoking extension methods Add support for method references invoking extension methods Jan 24, 2025
@EotT123 EotT123 changed the title Add support for method references invoking extension methods WIP: Add support for method references invoking extension methods Jan 25, 2025
@EotT123 EotT123 changed the title WIP: Add support for method references invoking extension methods Add support for method references invoking extension methods Jan 25, 2025
@EotT123
Copy link
Contributor Author

EotT123 commented Jan 25, 2025

@rsmckinney I believe this PR is ready. I've tested it with a real project, and I didn't encounter any issues.

IntelliJ is still complaining ("Extension method ... must be invoked as a lambda expression here"), but the code is compiling fine. So I guess an update of the IntelliJ plugin is also needed.

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.

2 participants