Generate Method Stub Keyboard Shortcut?
Is there a keyboard shortcut to allow me to place my cursor on the method name that doesn't exist yet and have it create a method stub for it quickly? I don't want to use menus, I want to use a refactor shortcut or something. I tried alt + command + M but it didn't do what I wanted, it did something weird.
Example, I want to create a method stub for findCompaniesByCountry to be created off of this line of code:
I tried Refactor (alt + command + M) which gave me this:
I selected global and then I get:
what good does that do for me? I'd expect to see it ask me to create a method stub named findCompaniesByCountry, instead it's showing me some default name of extracted(country)...huh???? Let alone I lost the name, what about the company variable!? where'd that go? So the refactor to method here is useless to me.
请先登录再写评论。
Extract Method refactoring is supposed to be used for creating a new method from selected block; it's normally used to avoid code duplication, isolate independent parts of code, making it more readable and maintainable. And, of course, it's not supposed to be used to fix reference errors in your code by creating missing methods.
to generate missing method stub, you can try using 'Create method' quickfix: hit Alt+Enter on unresolved method name, choose to create a method or function:
Hi,
I have the same question, but when I tried to use Alt+Enter I've seen that instead of generating of method stub, unresolved imports have been resolved. For example I have the line of code text("Some text") and I want to generate stub for method text() but instead of generation import java.awt.SystemColor.text happens. I'm using IntelliJ Idea 2017.2 EAP with Keymap MacOS X 10.5+ and keymap for import optimizing is Ctrl+Alt+O. Could you please help with this problem? Sorry if I've selected wrong thread, in case this is only Idea related problem I of course will post this problem in appropriate section of forum
This is IDEA + Java issue, please post it in IDEA forum