I was under the assumption that when eclipse suggests methods, it's in the form
<methodName>(<any parameters>) : <retunType> - <actual class the method will be invoked from>
And it seems to be true for all the methods (but clone()) in the posted picture also.
But for clone()
, eclipse says the method comes from the type of the array (byte
in this case).
It's the same for all arrays of primitive types and arrays of reference types as well.
Eg: For String[]
it gives clone() : String[] - String
What does that mean? Is my understanding wrong? Or is there something else in the clone()
method?
Just to make things clear, my question is Why does eclipse say "clone()" is from byte when it should be from byte[] just like "length".
This can only be answered by looking at the eclipse source code.
The answer for your question is simple and disappointing: The Eclipse UI code which produces the complete proposals builds a faulty display. Note that the complete proposal for the length property of an array shows the correct type (byte[] in your example).
The details:
When you trigger the completion assistant the possible completions are calculated as CompletionProposals.
The property of the CompletionProposals which is used to display the type of a proposed method or field completion is the declaringTypeSignature (see below).
CompletionTests shows that proposal objects for the clone-method and the length-field of a byte array would have a declaringTypeSignature "[B".
Now CompletionProposalLabelProvider takes these proposal objects and builds the view, in the form of a StyledString
. Method #createLabelWithTypeAndDeclaration
does it for field proposals, method #createMethodProposalLabel
for method proposals. They have different implementations for the display of the declaring type.
The method display calls SignatureUtil.stripSignatureToFQN, passing "[B" as signature. The returned result has stripped of all array information and is simply "byte".
The field display calls Signature.getSignatureSimpleName passing "[B". This method does not ignore the array information and returns "byte[]".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With