Netbeans "Refactor/Introduce/Extract Method" creates not-compilable / wrong method declaration in case of parametrized lambda expression
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Apache NetBeans version
Apache NetBeans 18
### What happened
When using Optional/Stream and other monads, netbeans is not able to extract method correctly from lambda expression. Input parameters are missing (in some cases).
I am willing to fix it if you can provide a pointer, which module/java class is responsible for that.
### How to reproduce
Assume following code:
```
public class ExtractMethodDemo {
public static void main(String[] args) {
String first = "hello";
String second = "world";
System.out.println(
java.util.Optional.ofNullable("-")
.map(t -> first + t + second)
.orElseThrow()
);
}
}
```
I would like to move code `t -> first + t + second` to a new method, some kind or parametrized factory, so I select it ALT SHIFT M (extract method)
It creates following not compilable method
```
public class ExtractMethodDemo {
public static void main(String[] args) {
String first = "hello";
String second = "world";
System.out.println(java.util.Optional.ofNullable("-")
.map(factory())
.orElseThrow()
);
}
private static Function factory() {
return t -> first + t + second;
}
}
```
Function lacks input parameters as `Function factory(String first, String second)`
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Ubuntu
### JDK
8/17
### Apache NetBeans packaging
Apache NetBeans binary zip
### Anything else
_No response_
### Are you willing to submit a pull request?
Yes
Contributor guide
Research direction
Start with the Alt+Shift+M Extract Method action and reproduce the parametrized lambda case from the issue on Apache NetBeans 18. Trace the Java refactoring implementation that creates factory(), then verify the completed change produces a compilable declaration including the captured first and second parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100