tags:

views:

56

answers:

2

When I use Eclipse 3.5 to auto-create methods for me (for example, by calling a method that does not yet exist, then using Quickfix to create the method), Eclipse creates the method with private scope.

I'd like to change that so that it's created with protected scope by default. How can I do so?

A: 

You might have a look at: Eclipse templates, but what you want to do, can only be done by changing the "private_method" template, if and only if that template is used by the fix suggestion logic, and I'm not sure that you can change that logic. Plus, if this would work, then the template would not represent the true meaning of having private methods... for all cases.

Hans Doggen
Thank you. That's where I started, but I couldn't figure out which template was the correct one. I tried searching the prefs pane for "private", but none of the templates showed. So then I tried guessing and changed the "private_method" template to be protected, but the next time I let eclipse create a method for me it still came out private. Any further suggestions?
Mike
+1  A: 

Already in 2002

I've just discovered the Quick Fix feature in the F2 build. It's really cool.
One question: Is there a way to change the way it creates methods for you? I would like the new methods to be protected instead of private.

there's no way to do this now.
Please enter a feature request a.

Ouch. And 7 years later, for the 3.5 edition, it does not seem to have changed one bit. In fact, other quick fixes produce incorrect private methods (in another context though, like bug 271551)

Arguably, in this instance, the generation of private method could be view as a "good practice", forcing the developer to explicitly raise the visibility level of said method (with the adequate javadoc saying why this method could be sub-classed or is even a public one)

VonC
IMO using private is a bad practice and protected is a good practice in most cases (although definitely not all), but I suppose this isn't the place to argue ideology. Sigh, if only I could return to IntelliJ. Thanks for the response
Mike
IntelliJ has just announced an open source community edition. Since it is free, would your manager approve?
Thorbjørn Ravn Andersen
Licensing isn't actually the problem in this case, I actually already have a license for 8. It's more that Android development on IntelliJ isn't quite up to par just yet.
Mike