Summary: | Requesting CompilationUnit.columnNumber() & CompilationUnit.getPosition(int, int) | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Theodora Yeung <tyeung> | ||||
Component: | Core | Assignee: | Olivier Thomann <Olivier_Thomann> | ||||
Status: | RESOLVED FIXED | QA Contact: | |||||
Severity: | enhancement | ||||||
Priority: | P3 | CC: | jeem, philippe_mulet | ||||
Version: | 3.1 | ||||||
Target Milestone: | 3.2 | ||||||
Hardware: | PC | ||||||
OS: | Windows XP | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Theodora Yeung
2005-05-31 20:09:08 EDT
Post 3.1. Indeed makes sense, since we do not expose the line separator table. Olivier - can you confirm this ? Yes, I can confirm that we don't expose the line end table. Therefore it is pretty expensive to compute it. Would it be better to expose it, or to provide these APIs ? Created attachment 22243 [details]
CompilationUnit.java with implementation of proposed API.
My original thought was that it would be non-trivial to explain to dom clients the content/format of the line separation table and hence the proposed API. In the attachment was my implementation of the proposed API. The proposed APIs are sound. I assume these changes are destined for the APT branch which will eventually be integrated into the 3.2 stream. Accordingly, please ensure that all API additions are tagged @since 3.2 so that we don't lose track of where they came in. Typo: "coloumn" Style: The putative audience of the specs is the caller of the method rather than the implementor. Hence "returns" rather than "return". Here's how I would reword the spec for the 2nd method: /** * Given a line number and column number, returns the corresponding * position in the original source string. * Returns 0 if no line number information is available for this * compilation unit or the requested line number is less than one. * Returns the total size of the source string if <code>line</code> * is greater than the actual number lines in the unit. * Returns 0 if <code>column</code> is less than 0, * or the position of the last character of the line if <code>column</code> * is beyond the legal range. * * @param line the one-based line number * @param column the zero-based column number * @return the 0-based character position in the source string; * returns <code>0</code> if line/column number information is not known * for this compilation unit or the inputs are not valid * @since 3.2 */ public int getPosition(int line, int column); I will review them, add tests and release them in the APT branch. I suggest returning -1 when line/column information are invalid. 0 is potentially the position of the first character when line = 1 and column = 0. Then it is not possible to make the distinction between an invalid call and a valid one. The proposed implementation doesn't return 0 when line/column are invalid. I will fix this and add tests. What about positions in the middle of a line break? On windows a line break takes two characters. So it would be possible to give position in the middle. I don't think this position can be passed to an editor for example. Fixed and released in APT_BRANCH. I kept 0 for the column number and for the positions if arguments are invalid. This is consistent with the way we fail for the line number. New tests have been added into org.eclipse.jdt.core.tests.dom.ASTPositionsTest. |