Bug 120264 - [api] have array binding X[][][], want X[][] and X[]
Summary: [api] have array binding X[][][], want X[][] and X[]
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-11 06:19 EST by Martin Aeschlimann CLA
Modified: 2006-02-15 09:28 EST (History)
3 users (show)

See Also:


Attachments
Proposed fix (2.09 KB, patch)
2005-12-17 19:36 EST, Olivier Thomann CLA
no flags Details | Diff
Regression test (1.95 KB, patch)
2005-12-17 19:37 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2005-12-11 06:19:05 EST
20051211

There is currently no API to get the component type on an array binding
e.g. if I have an array binding X[][][], I want to get the binding X[][].

In quick fix we have helper code that computes a required type and returns an ITypeBinding. However, we can create any new bindings. Sometimes we have a array binding and want to return an array binding a lesser dimension.
e.g. 

@Annot(attrib={ newVariable})

To guess the type of newVariable we ask the what the type of 'attrib' is and reduce the dimension by one.
Comment 1 Philipe Mulet CLA 2005-12-11 07:57:07 EST
Indeed ITypeBinding#getElementType() answers the leaf component type.
In compiler land, elementType denotes the direct element type, and leafComponentType denotes what DOMAST calls the element type.

Maybe we can define: getImmediateElementType() ? getComponentType() ?
What if we fixed the API using component in place of element ?
Then we deprecate getElementType(), and add:

[@deprecated - use getLeafComponentType instead] getElementType()
[add] getLeafComponentType()
[add] getComponentType()

?
Comment 2 Philipe Mulet CLA 2005-12-11 07:57:28 EST
Jim - do you have an opinion ?
Comment 3 Martin Aeschlimann CLA 2005-12-11 16:33:27 EST
org.eclipse.jdt.core.dom.ArrayType already has the two different variants:

/**
 * Returns the element type of this array type. The element type is
 * never an array type.
 * <p>
 * This is a convenience method that descends a chain of nested array types
 * until it reaches a non-array type. 
 * </p>
 * 
 * @return the component type node
 */ 
public Type getElementType()
-------------------
/**
 * Returns the component type of this array type. The component type
 * may be another array type.
 * 
 * @return the component type node
 */ 
public Type getComponentType()
Comment 4 Olivier Thomann CLA 2005-12-17 16:44:19 EST
I propose to keep the same API on the binding and on the node.
So getElementType() to return the leaf component type of the compiler binding and getComponentType() to return the type with dimension equals to receiver's dimensions - 1.
/**
 * Returns the component type of this array type. The component type
 * may be another array type.
 * Returns the binding representing the component type of this array type,	  * or <code>null</code> if this is not an array type binding. The component
 * type of an array may be another array type.
 * 
 * @return the component type binding, or <code>null</code> if this is
 *   not an array type
 */ 
public ITypeBinding getComponentType();
Comment 5 Olivier Thomann CLA 2005-12-17 19:36:42 EST
Created attachment 31905 [details]
Proposed fix
Comment 6 Olivier Thomann CLA 2005-12-17 19:37:24 EST
Created attachment 31906 [details]
Regression test
Comment 7 Olivier Thomann CLA 2005-12-19 10:21:10 EST
/**
 * Returns the binding representing the component type of this array type,
 * or <code>null</code> if this is not an array type binding. The component
 * type of an array might be an array type.
 *
 * @return the component type binding, or <code>null</code> if this is
 *   not an array type
 */	
public ITypeBinding getComponentType();

Fixed and released in HEAD.
Regression test in org.eclipse.jdt.core.tests.dom.ASTConverter15Test.test0131/0132
Comment 8 Maxime Daniel CLA 2006-02-15 09:28:51 EST
Verified for 3.2 M5 using build I20060215-0010.