Community
Participate
Working Groups
3.2 We need somthing like ast.resolveArrayType(ITypeBinding binding, int extraDimensions) that returns an array type binding using the given base type and the dimension. In quick fix we have functionality that guesses the type of a method or variable by looking how it is used and has to add more dimensions for example after array accesses. For example see bug 148011.
This would require to keep a lookup environment around in order to preserve the identity of bindings inside the same cluster. Also the lookup environment is used to get the elements type of the new array binding.
Until AST is disposed the lookup environment is there anyway
Created attachment 45247 [details] Proposed fix
Created attachment 45248 [details] Regression test
Created attachment 45249 [details] Regression tests
Martin, Could you please review the patch? If it fits your need, I can release.
Thanks for the quick response, great. Problem that I have is that just for primitive array types isn't enough. Could this be extended to all types? I guess it has to be defined if the argument can also be an array type itself, so the method just adds more dimensions. What I'm also was think is that you might have to check if the type binding passed in is from the same AST (and throw a execption if not). Do you have this information? Maybe it would make sense to offer getAST on IBinding. We definitly would like to bring up the topic of access/creations to bidnings at the JDT summit.
Ok, then I leave it as is till the JDT summit. I made it only for primitive types since this seemed to be what you wanted. For non-primitive type, I would need to be able to get the compiler binding for the corresponding ITypeBinding. Same issue for arrays. At least this is on the right track.
see also bug 40096
Created attachment 46001 [details] New patch
Created attachment 46515 [details] Better patch Patch to get binding identity
Created attachment 46516 [details] Regression test Updated regression test
Fixed and released in HEAD. Regression test added org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2#test0654. Markus, let me know if this meets your needs.
The API has been move to ITypeBinding. /** * Answer an array type binding using the receiver and the given * dimension. * * <p>If the receiver is an array binding, then the resulting dimension is the given dimension * plus the dimension of the receiver. Otherwise the resulting dimension is the given * dimension.</p> * * @param dimension the given dimension * @return an array type binding * @throws IllegalArgumentException:<ul> * <li>if the receiver represents the void type</li> * <li>if the resulting dimensions is lower than one or greater than 255</li> * </ul> * @since 3.3 */ public ITypeBinding createArrayType(int dimension); Fixed and released in HEAD. Same regression test updated.
Released for 3.3 M2.
Sorry if I come late (was on vacation the last two days): Can we discuss again where to put this method? I'd rather not put it on ITypeBinding as so far all methods on type binding are just accessors. 'create' sounds strange here. I think the correct place would be the 'BindingEnvironment' as discussed in bug 150657. As there are similar 'create binding' requests as mentioned in bug 40096 I think it would be better to have them all together. Shall we agree that we move the API when BindingEnvironment is ready? In fact I would suggest to put it on AST again so that in the end for 3.3 it will be on AST _and_ BindingEnvironment.
Olivier, I reopen this bug as last Martin's comment would imply that implementation needed to be changed. In case you do not agree please argue and put back to FIXED state. Thanks
(In reply to comment #16) I agree that BindingEnvironment would be the best place for this API. I disagree that the API should be at two places in the end, and I don't think that AST is a good home for it either. There are bindings for which there's no corresponding or originating DOM AST, e.g. from ASTParser#createBindings(..). I also have some nitpickings on the wording of the javadoc (to align it with others in ITypeBinding). My proposal: /** * Returns an array type binding composed of this type binding and the given * dimension. * * <p>If this type is an array type binding, then the dimension of the result * is the given dimension plus the dimension of this type. Otherwise, the * dimension of the result is the given dimension.</p> * * <p>Note: this API is provisional and will probably be moved during the 3.3 * cycle, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=148224 .</p> * * @param dimensions the additional dimensions * @return an array type binding * @throws IllegalArgumentException:<ul> * <li>if this type represents the void type</li> * <li>if the resulting dimensions is lower than one or greater than 255</li> * </ul> * @since 3.3 */ public ITypeBinding createArrayType(int dimensions);
Need to set a target milestone otherwise, it will be included in 3.3 M2 bugs verification list...
Closing as a dup of bug 150657 since this is one of the API requested for the new Binding Environment. *** This bug has been marked as a duplicate of bug 150657 ***
Remove target since duplicate bug is not closed for 3.3M6