Bug 148224 - AST API request: have binding for int, need int[], int[][] ....
Summary: AST API request: have binding for int, need int[], int[][] ....
Status: RESOLVED DUPLICATE of bug 150657
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks: 148011
  Show dependency tree
 
Reported: 2006-06-22 10:28 EDT by Martin Aeschlimann CLA
Modified: 2007-03-29 04:59 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix (5.89 KB, patch)
2006-06-24 17:11 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression test (3.22 KB, patch)
2006-06-24 17:11 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression tests (3.22 KB, patch)
2006-06-24 17:19 EDT, Olivier Thomann CLA
no flags Details | Diff
New patch (7.20 KB, patch)
2006-07-10 08:43 EDT, Olivier Thomann CLA
no flags Details | Diff
Better patch (8.26 KB, patch)
2006-07-19 13:04 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression test (5.33 KB, patch)
2006-07-19 13:05 EDT, 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 2006-06-22 10:28:50 EDT
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.
Comment 1 Olivier Thomann CLA 2006-06-22 16:12:02 EDT
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.
Comment 2 Philipe Mulet CLA 2006-06-24 08:29:52 EDT
Until AST is disposed the lookup environment is there anyway
Comment 3 Olivier Thomann CLA 2006-06-24 17:11:34 EDT
Created attachment 45247 [details]
Proposed fix
Comment 4 Olivier Thomann CLA 2006-06-24 17:11:53 EDT
Created attachment 45248 [details]
Regression test
Comment 5 Olivier Thomann CLA 2006-06-24 17:19:30 EDT
Created attachment 45249 [details]
Regression tests
Comment 6 Olivier Thomann CLA 2006-06-25 22:51:57 EDT
Martin,

Could you please review the patch? If it fits your need, I can release.
Comment 7 Martin Aeschlimann CLA 2006-06-26 05:11:00 EDT
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.
Comment 8 Olivier Thomann CLA 2006-06-26 10:15:41 EDT
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.
Comment 9 Markus Keller CLA 2006-06-27 05:57:45 EDT
see also bug 40096
Comment 10 Olivier Thomann CLA 2006-07-10 08:43:48 EDT
Created attachment 46001 [details]
New patch
Comment 11 Olivier Thomann CLA 2006-07-19 13:04:26 EDT
Created attachment 46515 [details]
Better patch

Patch to get binding identity
Comment 12 Olivier Thomann CLA 2006-07-19 13:05:01 EDT
Created attachment 46516 [details]
Regression test

Updated regression test
Comment 13 Olivier Thomann CLA 2006-08-14 20:04:13 EDT
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.
Comment 14 Olivier Thomann CLA 2006-08-15 11:59:19 EDT
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.
Comment 15 Olivier Thomann CLA 2006-08-15 13:56:38 EDT
Released for 3.3 M2.
Comment 16 Martin Aeschlimann CLA 2006-08-16 04:57:33 EDT
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. 

Comment 17 Frederic Fusier CLA 2006-09-08 10:09:16 EDT
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
Comment 18 Markus Keller CLA 2006-09-08 11:43:20 EDT
(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);
Comment 19 Frederic Fusier CLA 2006-09-15 11:20:36 EDT
Need to set a target milestone otherwise, it will be included in 3.3 M2 bugs verification list...
Comment 20 Olivier Thomann CLA 2007-01-30 11:56:40 EST
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 ***
Comment 21 Olivier Thomann CLA 2007-03-20 11:02:38 EDT
Remove target since duplicate bug is not closed for 3.3M6