Bug 26363 - [ast/dom] type bindings that return null for superclass
Summary: [ast/dom] type bindings that return null for superclass
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 2.1 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-14 11:48 EST by Jim des Rivieres CLA
Modified: 2003-02-07 08:06 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 Jim des Rivieres CLA 2002-11-14 11:48:57 EST
Tim Halloran asks on jdt-core-dev@eclipse.org:

If one walks up the type hierarchy using ITypeBindings it appears a bit
difficult to figure out you are at the top (e.g., you get null from an
getSuperclass() method call).  The problem is "null" from this call can
reasonably mean a few other things as well.

I've compared the fully qualified name to "java.lang.Object" but I'm
wondering if there is a better way?

Should there be a "boolean isJavaLangObject()" method that returns true
if the type is "java.lang.Object", and false otherwise?

Thoughts?


Jim des Rivieres replies:

Since java.lang.Object is the only genuine class without a
superclass, you could also use
      typeBinding.isClass() && typeBinding.getSuperclass() == null

Philippe Mulet adds:

I suspect though that if the superclass is missing, the binding superclass
will also be null.

==========

The upshot is that we need to investigate further.
(a) How are classes with missing superclasses handled? Is the superclass 
binding null, or is it a stand-in? Spec does not suggest that there are 
any "holes" in the binding graph?
(b) How about other places? E.g, method bindings with missing parameter types?
(c) Should we add "boolean isJavaLangObject()" to ITypeBinding?
Comment 1 Martin Aeschlimann CLA 2002-11-14 12:21:34 EST
You can look at the qualified name of the type binding. If it 
if 'java.lang.Object' you found it.
Comment 2 Timothy Halloran CLA 2002-11-14 13:29:01 EST
(From the jdt-core-dev mailing list) a good approach that maybe should be
wrapped into a convience API method...Tim

Jim des Rivieres <Jim_des_Rivieres@oti.com>
To:jdt-core-dev@eclipse.org
Subject:[jdt-core-dev] ITypeBinding - How to tell your at "java.lang.Object"?
Date:13 Nov 2002 19:17:46 -0500	

Tim,
Since java.lang.Object is the only genuine class without a superclass, you could
also use
      typeBinding.isClass() && typeBinding.getSuperclass() == null
---jim
Comment 3 Timothy Halloran CLA 2002-11-14 13:30:48 EST
Another idea:

From: Dirk Baeumer <Dirk_Baeumer@oti.com>
To: jdt-core-dev@eclipse.org
Subject: Re: [jdt-core-dev] ITypeBinding - How to tell your at "java.lang.Object"?
Date: 14 Nov 2002 18:45:49 +0100

Another idea is to compare the binding with the binding returned from
AST#resolveWellKnownType("java.lang.Object");

Dirk
Comment 4 Philipe Mulet CLA 2003-01-20 04:13:14 EST
The latter suggestion should be added to the superclass API.
Comment 5 Olivier Thomann CLA 2003-01-20 10:49:50 EST
Jim - please update the API
Comment 6 Jim des Rivieres CLA 2003-01-20 18:04:22 EST
Added the following para to javadoc for ITypeBinding.getSuperclass():

"Loops that ascend the class hierarchy need a suitable termination test.
Rather than test the superclass for <code>null</code>, it is more 
transparent to check whether the class is <code>Object</code>, by 
comparing whether the class binding is identical to 
<code>ast.resolveWellKnownType("java.lang.Object")</code>."
Comment 7 Philipe Mulet CLA 2003-01-21 06:19:36 EST
Closing. Doc fixed.
Comment 8 David Audel CLA 2003-02-07 08:06:26 EST
Verified.