Why doesn't Eclipse add @Override annotations in "Generate Delegate Methods" refactoring?
Asked Answered
S

3

10

In Eclipse, if I try to apply a "Generate Delegate Methods" refactoring to a Java class like the following:

class Foo implements Bar {
   Bar bar;
}

Eclipse doesn't generate @Override annotations for the generated methods. Is this a bug or is there a good reason for this?

Speaks answered 23/5, 2011 at 2:45 Comment(0)
F
4

No good reason, but not a "bug", per se; just a shortcoming. Probably the refactoring is just older than @Override -- older than annotations in general, of course -- and has never been updated.

Frosting answered 23/5, 2011 at 2:55 Comment(2)
Thanks Ernest, I reported this to Eclipse's Bugzilla.Speaks
The Bugzilla report can be found here.Speaks
B
31

This doesn't answer your question of why it doesn't add the @Override annotation when you generate delegate methods, but you can add a save action to do it for you upon saving the file. Go to

Window -> Preferences -> Java -> Editor -> Save Actions

Eclipse Save Actions

Notice the entries for @Override in the Additional actions section. If those are missing for you, click the Configure... button and select the Missing Code tab and select those options:

enter image description here

If you want to add the annotations to an entire project or package in bulk, select the project or package (or multiples), right-click, and choose Source > Clean up...

In the Clean Up dialog, you can configure a custom profile that includes adding missing annotations.

Blindstory answered 23/5, 2011 at 3:4 Comment(0)
F
4

No good reason, but not a "bug", per se; just a shortcoming. Probably the refactoring is just older than @Override -- older than annotations in general, of course -- and has never been updated.

Frosting answered 23/5, 2011 at 2:55 Comment(2)
Thanks Ernest, I reported this to Eclipse's Bugzilla.Speaks
The Bugzilla report can be found here.Speaks
H
1

Sometimes settings in Window -> Preferences -> Java -> Editor -> Save Actions cause undesired effects especially on XML files while developing Android applications (been there, experienced that). IMHO better solution is to use +1 or right click on package (or class etc...) and then choose Source -> Clean up to add all of your missing @Override annotations.

Hiro answered 7/12, 2014 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.