| Summary: | [1.8][override method] Override / Implement methods should offer to generate default methods | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Lukas Eder <lukas.eder> | ||||
| Component: | UI | Assignee: | Noopur Gupta <noopur_gupta> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | enhancement | ||||||
| Priority: | P3 | CC: | markus.kell.r, noopur_gupta, stephan.herrmann | ||||
| Version: | 4.5 | Flags: | markus.kell.r:
review+
|
||||
| Target Milestone: | 4.5 M6 | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
This one looks simple:
+ import java.util.*;
- interface DefaultSpliterator<T> extends Splitarator<T> {
+ interface DefaultSpliterator<T> extends Spliterator<T> {
$ ecj -1.8 DefaultSpliterator.java
OK.
:)
Tried with 4.4.1 and also with latest in master.
Do you see s.t. different?
That was a typo on my side when I pasted the code into this bug. Don't know how it happened. But it's not relevant to this feature request. Try typing Alt-Shift-S + V, you'll get a message "The Override Methods operation is not applicable to interfaces". This isn't a bug report, but a feature request :) (In reply to Lukas Eder from comment #2) > That was a typo on my side when I pasted the code into this bug. Don't know > how it happened. But it's not relevant to this feature request. > > Try typing Alt-Shift-S + V, you'll get a message "The Override Methods > operation is not applicable to interfaces". > > This isn't a bug report, but a feature request :) Apparently I missed the little hint in the summary, from my compiler p.o.v. I could only think of a bogus compile error... So, that changes several parameters: - let's make it an "enhancement" - move to JDT/UI At a quick look, you want org.eclipse.jdt.ui.actions.OverrideMethodsAction.run() to check for type.isInterface() only at 1.7-. Additionally, in an interface, should we always insert the modifier "default" plus a body? Maybe you want to make a default method fully abstract again? > let's make it an "enhancement" Is that new? > move to JDT/UI True, sorry about that. > Additionally, in an interface, should we always insert the modifier "default" plus a body? Maybe you want to make a default method fully abstract again? I've thought about that, but I guess the "default" plus body use-case is much more interesting. Besides, the "abstract" flag isn't offered when overriding / implementing methods in abstract classes either. Perhaps, that would be a separate feature request. Note that if Eclipse offered this "abstract" flag for overriding, it would make sense for interfaces in 1.7- Java versions, too. I sometimes (rarely) override an abstract interface method to re-define the Javadoc contract. (In reply to Lukas Eder from comment #4) > > let's make it an "enhancement" > > Is that new? No, Bugzilla has had a "Severity" field forever. But it's strange that your "Platform" was set to "Windows NT" initially? Do you really run NT? Or did you use a tool other than the https://bugs.eclipse.org/bugs/ website to open the bug? I support offering "Override/Implement Methods..." for interfaces in Java 8 and later, but I don't think we really need to complicate the dialog by adding a "keep abstract" option. That enhancement can be discussed in bug 211488. > No, Bugzilla has had a "Severity" field forever. Hmm, I guess I just never expected a bug type to be hidden in the severity... > Do you really run NT? No, I'm using Windows 8.1 > Or did you use a tool other than the https://bugs.eclipse.org/bugs/ website to open the bug? No. > I support offering "Override/Implement Methods..." for interfaces in Java 8 and later, but I don't think we really need to complicate the dialog by adding a "keep abstract" option. That enhancement can be discussed in bug 211488. I completely agree. The use-case of re-abstracting is very rare. > No, I'm using Windows 8.1 Thanks, filed bug 460621 for this problem in Bugzilla. Created attachment 251064 [details]
Patch
Attached patch fixes the following:
- Allows "Override/Implement Methods..." for interfaces in Java 8 and later.
- Overrides an abstract method from super interface as default method.
- Creates abstract methods for overriding methods from Object class in interface.
- Does not generate @Override for non-public Object methods in interface.
Added new tests and checked that all existing tests are green.
Markus, please review.
In pre-1.8 projects, content assist in an interface must not try to create default methods. In the past, we created abstract methods in that case. The ActionMessages.OverrideMethodsAction_interface_not_applicable would have to tell that this now only applies to source levels below 1.8. But since we already offer overriding of interface methods via Content Assist, I think we can just open this up and also show the dialog at all source levels. Fixed these issues and released with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=2586520eea42ad7e97773c3bef22574c5df5c1ba |
In Java 8, I may want to define my DefaultSpliterator: ----------------------------------------------- interface DefaultSpliterator<T> extends Splitarator<T> { @Override default Spliterator<T> trySplit() { return null; } // ... } ----------------------------------------------- When implementing the above, I'd like to be able to "override/implement" methods from the super interface(s) as default methods, but this is currently (in 4.5.0 M5) not possible.