Bug 69021 - [1.5][dom] provide API to ask for super/subtypes
Summary: [1.5][dom] provide API to ask for super/subtypes
Status: RESOLVED DUPLICATE of bug 73676
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-30 11:08 EDT by Adam Kiezun CLA
Modified: 2004-11-18 13:12 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Kiezun CLA 2004-06-30 11:08:11 EDT
3.0
in java 1.5 the type domain is infinite even without array types
so the traditional type hierarchy is less useful to use (programatically) -
there is possibly an infinite number of subtypes or supertypes for a given type.

but many analyses need that kind of information - refactoring is one but pretty
much anybody who does anything interesting will be in need of that info.
with generics these things become pretty complicated, e.g.:
List<? extends Integer> is a subtype of List<? extends Number> but
List<? super Integer>   is a supertype of List<? super Number>.

So we would have 1 place that contains that kind of code. Jdt core seems to be
the natural location for that kind of logic (the type checker need that anyway).
So the request is for API that would allow questions of kind 'isSuperTypeOf'
Comment 1 Philipe Mulet CLA 2004-07-05 18:49:19 EDT
List<? extends Integer> is NOT a subtype of List<? extends Number>
and List<? super Integer> is NOT a supertype of List<? super Number>

The old fashion type hierarchies are good enough to resolve type declaration 
hierarchies. The only refinements would occur when using parameterized 
supertypes, where in theory, AbstractList<Object> should not be mistaken as a 
supertype of List<String>.
Comment 2 Adam Kiezun CLA 2004-07-06 09:23:20 EDT
"List<? extends Integer> is NOT a subtype of List<? extends Number>"

Strange, last time i saw the spec it was. (it's also that way in the Torgersen 
paper).
you can assign only one way and every instance of List<? extends Integer> is 
also a List<? extends Number> so i think the former is a subtype of the latter. 

Can you clarify what you meant when you said it was not?

The api request is for a situation like this: i have 2 bindings in hand, i need 
to check if one is a subtype of the other. Currently i have to walk all 
superbindings myself but thay does not cover cases like arrays being subtypes 
of Cloneable or interfaces being subtypes of Object - i have (and other people 
too) workarounds for these. But the typechecker must be using some information 
of that sort as well. Exposing it would save a lot of effort on the client side.
Also, because there are infinitely many supertypes of something like "List<? 
super Vector>", the naive walking up the supertype hierarchy is not enough. But 
again, the typechecker must have that logic already. This request is for 
exposing that logic via API.
Comment 3 Philipe Mulet CLA 2004-07-22 11:54:47 EDT
Sorry I misread your request. I considered subtype to mean 
subclass/subinterface.

Type compatibility rules are indeed far from trivial, and we could expose some 
functionality to surface TypeBinding.isCompatibleWith(TypeBinding) from our 
internals.
Comment 4 Markus Keller CLA 2004-08-30 12:04:35 EDT
+1 for a central authority for subtype relationship queries.
Comment 5 Dirk Baeumer CLA 2004-11-18 13:12:20 EST

*** This bug has been marked as a duplicate of 73676 ***