override-method for records should suggest all overridable methods
Description
When I want to override toString in a class, Netbeans supports that with a suggestion to override toString, with all the trimmings like the annotation, the method signature and visibility. The is nice.
For record that does not happen.
Use case/motivation
I would like to get the suggestion to also override toString, equals, and hashCode for those cases where the default for record does not cut it.
Related issues
No
Are you willing to submit a pull request?
No
javac api returns those methods as final, which is why NB isn't offering overrides for them:
getClass()java.lang.Class -> [public, final, native]
clone()java.lang.Object -> [protected, native]
notify()void -> [public, final, native]
notifyAll()void -> [public, final, native]
wait()void -> [public, final]
wait(long)void -> [public, final, native]
wait(long,int)void -> [public, final]
finalize()void -> [protected]
toString()java.lang.String -> [public, final]
hashCode()int -> [public, final]
equals(java.lang.Object)boolean -> [public, final]
the "getters" of the record components are seen as already overridden, so those aren't offered either.
https://github.com/apache/netbeans/blob/97fd224c7aefd548207753c6f7fedadfd3440e1c/java/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java#L703
javac api returns those methods as final, which is why NB isn't offering overrides for them: the "getters" of the record components are seen as already overridden, so those aren't offered either.
Yes, but I think NB should request methods from supertype-only, not methods from this class. I guess this problem already existed for enum before the introduction of records, it is totally fine to override toString-method of an enum, but people doesn't do it normally. But for records this becomes a problem, because you do want to override hashCode/equals of a record often-enough.
everything is final in Enum except toString() and NB does offer to override toString().
A record is a final class which extends java.lang.Record. The problem is that javac generates all methods as final unless they are added by the user, then it will skip that method. I don't see a way to distinguish between the generated method and a user provided method just by using the compiler api. But I also don't have a lot of experience with it, maybe there is a query for generated code or something similar.
NB can't only take the supertype into consideration due to various reasons (e.g you don't want to generate the same method twice). I am sure this can be solved but I don't see a elegant way right now.