Community
Participate
Working Groups
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.
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() ?
Jim - do you have an opinion ?
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()
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();
Created attachment 31905 [details] Proposed fix
Created attachment 31906 [details] Regression test
/** * 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
Verified for 3.2 M5 using build I20060215-0010.