3

I am aware of 'Must Override a Superclass Method' Errors after importing a project into Eclipse (my issue is the opposite, I need to remove the @Overrides) and I understand the reason the error occurs.

My question

Is there an easy way to remove all of those errors, or remove all the errors of the same kind in one swoop? Kind of like solving all imports...

Thanks for any tips to help save time.

Community
  • 1
  • 1
TryTryAgain
  • 7,632
  • 11
  • 46
  • 82

4 Answers4

5

I do not know better way than find and replace all @Override by empty string. Eclipse can do it globally: press Cnrtl/H, write text @Override and leave the target empty. Then press "replace all" and pray... :(

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • Can you please elaborate. Pressing CTRL+H brings up many options. And when you say Global, that means all files in the project? All projects, or just that file? Thanks – TryTryAgain Jan 03 '12 at 14:46
  • Or you can use Search -> File and use the Replace button at the bottom. It's too bad you are not going the other way, Source -> Cleanup is the way to go, but they don't have an option to suppress the overrides. – Francis Upton IV Jan 03 '12 at 16:26
  • @AlexR ?? Any further info? Please – TryTryAgain Jan 03 '12 at 22:53
  • Ctrl+H, then choose "File Search" tab. Unless you specify working set the search is performed for all projects in workspace. – AlexR Jan 05 '12 at 07:22
5

Solution:

If you imported a Java 6 project and have Eclipse complaining about @Override annotations because you are compiling with Java 5...

  • Make sure you have a file from the project open and selected in your workspace
  • CTRL+H
  • Change the Tab at the top from Java Search to File Search
  • In Containing Text enter @Override
  • In File name patterns enter *
  • Select Enclosing Projects for your Scope
  • Press Search to do a dry run to see what happens and what it finds

Then, if all looks good, proceed with:

  • CTRL+H
  • Change the Tab at the top from Java Search to File Search
  • All your values should be remembered, if not follow the steps above from the dry run
  • Press Replace

Example Replace

Replacing 92 matches in 18 files

  • Replace: field should have carried over @Override
  • Remove anything/everything from the With: field
  • Press OK

Awesome...no laborious removing of @Overrides ever again.

Please NOTE: Occasionally, for me at least, when pressing CTRL+H the File Search wont allow me to choose Enclosing Projects as a Scope or it will automatically search the entire Workspace as opposed to the project. This is resolved by ensuring a file from your project is open and focused in Eclipse.

Hope this helps others. Thanks

TryTryAgain
  • 7,632
  • 11
  • 46
  • 82
4

After removing all instances of "@Override", you can also add back the non-interface overrides using "Clean Up".

Steps (search/replace, then add back):

  1. Select the projects or folders containing your source files.
  2. Go to "Search > Search..." (Ctrl-H) to bring up the Search dialog.
  3. Go to the "File Search" tab.
  4. Enter "@Override" in "Containing text" and "*.java" in "File name patterns". Click "Replace...", then "OK", to remove all instances of "@Override".
  5. Go to "Window > Preferences > Java > Code Style > Clean Up" and create a new profile.
  6. Edit the profile, and uncheck everything except "Missing Code > Add missing Annotations > @Override". Make sure "Implementations of interface methods" is unchecked.
  7. Select the projects or folders containing your source files.
  8. Select "Source > Clean Up..." (Alt+Shift+s, then u), then "Finish" to add back the non-interface overrides.
Peter Tseng
  • 13,613
  • 4
  • 67
  • 57
2

Eclipse->Window->Preferences->Java->Compiler->Compiler compliance level ----> choose 1.6. JAVA JRE 1.5 override is only superclass

Fr099y
  • 734
  • 7
  • 15