Bug 116472 - Ambigous API definition on CompilationUnit.getPosition()
Summary: Ambigous API definition on CompilationUnit.getPosition()
Status: VERIFIED FIXED
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: 3.2 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 116471 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-11-15 13:19 EST by Martin Aeschlimann CLA
Modified: 2005-12-12 11:25 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2005-11-15 13:19:08 EST
20051115

If I understand right, CompilationUnit.getPosition() returns a character index
given line and colunm.

The spec says that '0' is returned when e.g. arguments are invalid or no line
number available or out of range.

But isn't 0 also a valid character index? (for getPosition(1, 0)). How would I
tell apart? Why not using -1 as the 'invalid' result as it is more common in
Eclipse?

Also nasty is the clause 'if no line information is available'. How can I tell?
Is this API really useful if I can't rely on it?
Comment 1 Martin Aeschlimann CLA 2005-11-15 13:19:25 EST
*** Bug 116471 has been marked as a duplicate of this bug. ***
Comment 2 Olivier Thomann CLA 2005-11-15 18:25:05 EST
What do you suggest for the second issue with the clause 'if no line information
is available'?
I agree that -1 is a better value when arguments are invalid. We could also
throw an IllegalArgumentException.
This API is a push down from the apt branch. So I need to make sure this is
allright to make changes.
Comment 3 Olivier Thomann CLA 2005-11-15 18:27:41 EST
Theodora,

Any suggestion?
Comment 4 Theodora Yeung CLA 2005-11-15 18:51:12 EST
The "return 0" for invalid argument is just to line up with the behavior of 
columnNumber(int) and lineNumber(int), which also return 0 if the parameter is 
invalid or no line number information is available. 

We could return -1 for invalid argument and -2 if the line number information 
is not available. If that's the case, I would like to see columNumber(int) and 
lineNumber(int) behave in a similar manner. 

Comment 5 Olivier Thomann CLA 2005-11-15 19:03:46 EST
We cannot change lineNumber(int). This would be an API breakage, but it is
possible  to change the two other APIs.
Martin?
Comment 6 Martin Aeschlimann CLA 2005-11-16 04:25:42 EST
I know that lineNumber has been around since the beginning of the AST, but we
never used it in JDT UI. Mostly also as the usage of '1' for invalid arguments 
makes it difficult to use.

What about marking lineNumber as deprecated and replace it with a nicer variant?

-> getLineNumber(int): -1 if the index is out of bounds, -2 if no line number
information is available

-> getColumnNumber(int, int): -1 if the index is out of bounds, -2 if no line
number information is available

...
Comment 7 Olivier Thomann CLA 2005-11-16 09:36:28 EST
Jim, any comment?
Comment 8 Olivier Thomann CLA 2005-11-16 13:17:13 EST
Theodora, would the three new APIs be fine for you?
I would move them to the apt branch if they are released in HEAD to be consistent.
Comment 9 Olivier Thomann CLA 2005-11-17 10:19:31 EST
I will release the changes suggested by Martin in comment 6.
If you have anything to say, please speak up.
Comment 10 Olivier Thomann CLA 2005-11-17 11:07:27 EST
New API are released in HEAD only for now.
Please review them. If ok, then I will close this PR as FIXED and port them to
the APT branch.
Comment 11 Olivier Thomann CLA 2005-11-18 09:22:19 EST
Consider ok.
Fixed and released in HEAD.
I will port them to the APT branch.
Theodora, could you please then use these new API?
I'll deprecated the old API in the APT branch.
Comment 12 Olivier Thomann CLA 2005-11-18 09:32:36 EST
Merged into APT_32 branch. Theodora, could you please take care of the changes
required after this change?
This mostly requires additional bounds check on the value is returned (-1 or -2).
Comment 13 Theodora Yeung CLA 2005-11-18 14:43:15 EST
Currently, I don't think we have branched the APT plugin to work with the 
jdt.core in the APT_32 branch. Is there any plans on pushing it into the APT 
branch (the one with the 3.1.1 jdt.core)? 

Comment 14 Frederic Fusier CLA 2005-12-12 11:25:28 EST
Verified for 3.2 M4 using build I20051212-0010