Extract method default modifier
Answered
When I extract some code to method by Ctrl + Alt + M (windows), IDEA creates a method with private access modifier.
Is it possible to configure IDEA in a way that new method will have protected access modifier?
Note: Early I could see dialog when I can changed access modifier, but it default value was private. Why IDEA don't show me the dialog and can I change default access modifier value?
Note 2: If it isn't possible, I would like IDEA team to add this feature in future.
Please sign in to leave a comment.
The dialog to change access modifier (https://i.imgur.com/5SVr1xg.png) could be called via this button (or alt+shift+O) after extracting:
Konstantin, hi! Thank you for fast answer, but my question was not how to change access modifier. My question is how to set DEFAULT access modifier value, e.i. for every time I use this feature.
There is no default value in fact. It is being calculated every time the refactoring is called based on the context of the selected snippet. IDE is trying to be smart here.
May you share your code sample where we did not suggest to you the expected access modifier?
There isn't specific code sample, I just get private access every time.
In fact, I often change code in parent classes for add possibility to override some part of code in child classes
Okay, I see your answer. Can you please inform IDE team to add possibility to change this value? I mean user could be able to configure what he want: use IDE smart suggestion or use default access modifier.
May you try to change the visibility for the refactoring to protected (https://i.imgur.com/5SVr1xg.png) and perform one more refactoring after that?
IDE should save default visibility for method extracted from public one, so all further refactorings will have protected visibility set.
For me it is possible to have protected be suggested when I use `crtl + alt + M`. However, when I use `alt + Enter > Add method`, always `private` is used by default. If the idea is to be smart about this suggestion too, I would consider this a bug.
Robin Bastiaan there's an open issue for this, you can follow and vote for it here: https://youtrack.jetbrains.com/issue/IDEA-272395