Bug 246594 - [model] API request: ITypeParameter#getBoundsSignatures() or #getSignature()
Summary: [model] API request: ITypeParameter#getBoundsSignatures() or #getSignature()
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2008-09-08 10:57 EDT by Markus Keller CLA
Modified: 2010-02-24 09:05 EST (History)
3 users (show)

See Also:
srikanth_sankaran: review+


Attachments
Proposed API (4.54 KB, patch)
2010-02-15 01:15 EST, Jay Arthanareeswaran CLA
no flags Details | Diff
Updated patch (11.29 KB, patch)
2010-02-19 04:57 EST, Jay Arthanareeswaran CLA
no flags Details | Diff
Updated patch (11.32 KB, patch)
2010-02-24 01:08 EST, Jay Arthanareeswaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2008-09-08 10:57:24 EDT
N20080904-2000

API request:
- ITypeParameter#getBoundsSignatures() // returns type signatures of the bounds
- or ITypeParameter#getSignature() // returns type variable signature

ITypeParameter currently only offers getBounds(), which returns only the name of a bound. For correctly rendering the type parameter in Java editor hovers, I need the complete signatures of the bounds, e.g. for:

    class MyList<Element extends Map<String, Integer>> { .. },

... I'd like to display:

    'Element extends Map<String, Integer> - pack.MyList'

... when you hover over 'Element'. The type parameter signatures are already available via ITypeParameter#getDeclaringMember() and then IMethod#getTypeParameterSignatures() or IType#getTypeParameterSignatures(), but this is inelegant, and IMethod#getTypeParameterSignatures() is even deprecated.
Comment 1 Markus Keller CLA 2009-02-02 09:39:08 EST
As a workaround, we currently have to rely on the deprecated org.eclipse.jdt.core.IMethod#getTypeParameterSignatures(), since the signatures of ITypeParameters on methods are otherwise not available.
Comment 2 Olivier Thomann CLA 2009-07-27 09:33:56 EDT
Srikanth, this is important for UI rendering.
Comment 3 Srikanth Sankaran CLA 2010-01-13 00:56:45 EST
Jay, can you investigate this ? Thanks.
Comment 4 Olivier Thomann CLA 2010-01-28 11:42:59 EST
Let's try to get this in place for M6.
Comment 5 Jay Arthanareeswaran CLA 2010-02-15 01:15:06 EST
Created attachment 159088 [details]
Proposed API

Markus, Do you only want the API that returns the whole type parameter or also the API that returns signatures for individual bounds?

The patch has both the APIs. Please let me know this satisfies your requirement.
Comment 6 Markus Keller CLA 2010-02-15 06:15:26 EST
I have no clear preference. For consistency with existing APIs, both are OK, since we already have precedents for both styles, e.g. IMethod#getSignature() and IType#getSuperInterfaceTypeSignatures().

We should only add one of the methods, though.

Both methods would need some polish in the Javadocs, and getBoundsSignatures() needs to be plural.
Comment 7 Jay Arthanareeswaran CLA 2010-02-19 04:57:43 EST
Created attachment 159530 [details]
Updated patch

Updated the documentation and retained only org.eclipse.jdt.core.ITypeParameter#getBoundsSignatures()

A note about the implementation: The current implementation takes the signature from the .class file directly for the binary members (type and method). But it uses org.eclipse.jdt.core.Signature to construct the signature from the individual bounds for the source members. 
While it makes sense to keep it consistent (and use org.eclipse.jdt.core.Signature to construct the signature) for both binary and source members, the bug 303270 does not allow us. Currently the bug 303270 manifests only for the source types and if we use Signature for binary members as well, it will break the existing behavior. Hence, two different codes for extracting the signature depending on whether it's binary or source.
Comment 8 Markus Keller CLA 2010-02-19 06:10:28 EST
(In reply to comment #7)
> Created an attachment (id=159530) [details] [diff]
> Updated patch

The API looks good now.
Comment 9 Jay Arthanareeswaran CLA 2010-02-19 06:32:37 EST
Srikanth, would you have some time to review this patch, please?
Comment 10 Jay Arthanareeswaran CLA 2010-02-22 08:19:19 EST
Olivier, the bug 303270 was already existing with the older API that Markus mentioned in comment 1. Since I didn't want the API changes to be delayed, I captured it in another bug. I think this we can go ahead with this bug.
Comment 11 Srikanth Sankaran CLA 2010-02-23 08:53:03 EST
(In reply to comment #9)
> Srikanth, would you have some time to review this patch, please?

Patch looks good. Some comments:

javadoc on org.eclipse.jdt.core.ITypeParameter.getBoundsSignatures():

- @return the signature for this formal type parameter
should be 
@return the signatures for the bounds of this formal type parameter ??


- For consistency's sake we should say
"if this element does not exist" (instead of "if this element doesn't
exist") (compare javadoc on org.eclipse.jdt.core.ITypeParameter.getBounds())

- In org.eclipse.jdt.core.tests.model.CompilationUnitTests.testBug246594*()
the assert messages are not appropriate (cut & paste ?) and need fixing.
Comment 12 Srikanth Sankaran CLA 2010-02-23 08:56:16 EST
(In reply to comment #10)
> Olivier, the bug 303270 was already existing with the older API that Markus
> mentioned in comment 1. Since I didn't want the API changes to be delayed, I
> captured it in another bug. I think this we can go ahead with this bug.

Yes, I don't think bug#303270 should be considered to be blocking the
current enhancement.
Comment 13 Jay Arthanareeswaran CLA 2010-02-24 01:08:01 EST
Created attachment 160033 [details]
Updated patch

Incorporated the suggestions mentioned in comment # 11.
Comment 14 Jay Arthanareeswaran CLA 2010-02-24 05:46:35 EST
Released in HEAD for 3.6M6
Comment 15 Markus Keller CLA 2010-02-24 09:05:43 EST
Verified in HEAD and updated JDT UI to use the new API.