Bug 83501 - IBinding#getJavaElement needs better specification
Summary: IBinding#getJavaElement needs better specification
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M7   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 92059
  Show dependency tree
 
Reported: 2005-01-23 08:47 EST by Dirk Baeumer CLA
Modified: 2005-05-12 07:46 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2005-01-23 08:47:20 EST
The current specification is very vague when this method returns null and when
not. I expect the following behaviour:

Types:
- primitive types, including null and void: ==> null
- for wildcard types: ==> null
- for array types the Java element of the element type, or null if the 
  element type is a primitive
- for all other kind of types this method never returns null (even not for local 
  and anonymous types inside a method)
- for Raw type the Java element of the erasure
- for Parameterized types the Java element of the erasure

PackageBinding:
- never returns null

VariableBinding
- never returns null since we have IJavaElements for locals.
Comment 1 Markus Keller CLA 2005-03-22 05:44:50 EST
Note: for parameterized types, getJavaElement() currently returns the unresolved
type. We could consider returning the resolved type in such cases in order to be
consistent with ICodeAssist#codeSelect(..) on a reference such as
    List<Integer> intList;

I don't have a specific use case for this right now; just wanted to mention the
difference before the specification is set in stone.
Comment 2 Markus Keller CLA 2005-04-20 10:20:13 EDT
IVariableBinding#getJavaElement() should return null for an array's 'length'
field (see bug 92059).
Comment 3 Jim des Rivieres CLA 2005-04-20 23:17:34 EDT
Revised the spec as follows.

/**
 * Returns the Java element that corresponds to this binding.
 * Returns <code>null</code> if this binding has no corresponding
 * Java element.
 * <p>
 * For array types, this method returns the Java element that corresponds
 * to the array's element type. For raw and parameterized types, this method
 * returns the Java element of the erasure.
 * </p>
 * <p>
 * Here are the cases where a <code>null</code> should be expected:
 * <ul>
 * <li>primitive types, including void</li>
 * <li>null type</li>
 * <li>wildcard types</li>
 * <li>capture types</li>
 * <li>the "length" field of an array type</li>
 * <li>array types of any of the above</li>
 * </ul>
 * For all other kind of type, method, variable, and package bindings,
 * this method returns non-<code>null</code>.
 * </p>
 * 
 * @return the Java element that corresponds to this binding, 
 * 		or <code>null</code> if none
 * @since 3.1
 */
public IJavaElement getJavaElement();

The implementation should be brought into line with this spec at the same time 
bug 92059 is addressed.
Comment 4 Philipe Mulet CLA 2005-04-21 05:08:58 EDT
Integrated spec changes, and addressed bug 92059.
I believe resolved elements make sense there two when applicable.
Will not close this bug until this is resolved as well.
Comment 5 Jerome Lanneluc CLA 2005-04-22 12:32:52 EDT
Changed implementation of getJavaElement() to return a resolved element when
possible. Use isResolved() to check if it is resolved.
Comment 6 Frederic Fusier CLA 2005-05-12 07:46:00 EDT
Verified for 3.1 M7 using build I20050509-2010 + jdt.core HEAD.
(considering that ASTModelBridge tests all these cases and pass)