-
Notifications
You must be signed in to change notification settings - Fork 821
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
Netbeans "Refactor/Introduce/Extract Method" creates not-compilable / wrong method declaration in case of parametrized lambda expression #6311
Comments
I was able to find a class which is responsible for a such refactoring |
That code is quite hard to understand. So far, I am bit lost. What I discovered is, that no input params is found. I suspect something is nok in ScanStatement, but not sure what. |
So a bit of progress. It seems, all what is needed is to put references to variables into "usedLocalVariable". I made a simple POC, I added the "tempForceUsedLocalVariable" to be able to change the behavior while debugging netbeans: ScanStatement.java
After this modification, input parameters appeared in newly created method. So it seems it points to right direction:
Anyway, I am still a bit confused by the code itself. |
I fought with code base to be able to extract lambda expression with {} but I failed. If I extract from
Netbeans wrongly deduct the return type from method, whic int:
I haven't found a way how to make it working so far :( |
But at least it works for lambda without {} |
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:
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
Function lacks input parameters as
Function<String, String> 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
The text was updated successfully, but these errors were encountered: