| Summary: | Generate delegate methods should add @Override when applicable | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Glenview Jeff <junk> |
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
| Status: | RESOLVED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | dominik.gruntz, markus.kell.r |
| Version: | 3.7 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
|
Description
Glenview Jeff
That's actually a feature. An intention of the @Override annotation is to allow a compiler to detect cases where a method is not marked with the annotation but still overrides (or since 1.6 also implements) another method. In your scenario, the overriding could also be inadvertent, so it's good that Generate Delegate Methods doesn't automatically add the annotation. You can use "Source > Clean Up... > Missing Code" to add the @Override annotations in batch if you're sure they should really be there. *** Bug 346872 has been marked as a duplicate of this bug. *** Oops, I forgot I had already submitted this! I'm confused about your explanation that the overriding could be inadvertent. The scenario that I am describing is when the class implements an interface. I just don't see how it would be wrong to generate the @Overrides for the generated methods that implement the interface. How could it ever be correct/intentional behavior to omit @Overrides on an interface implementation method? Code that uses the @Override annotation typically has the "Missing '@Override' annotation" set to warning or error. Now, when a new method overrides another method, there are 2 possibilities:
a) the method should override the other method
=> solution: add @Override (e.g. using the quick fix)
b) the method should not override the other method, but it does so by accident
=> solution: great that the problem was flagged early on, now let's see if we can choose a different name or otherwise restructure the code to avoid a conflict
You're proposing that Eclipse should silently choose (a), thereby taking away the opportunity for you to find a problem early on. It's not always clear that your delegate method really should override the super method.
Example:
class Foo extends File implements Bar {
// generate delegate for bar.getName() => should it override File#getName()?
Bar bar;
}
interface Bar {
// void doit();
String getName();
}
*** Bug 482312 has been marked as a duplicate of this bug. *** |