[
https://issues.jboss.org/browse/ROASTER-89?page=com.atlassian.jira.plugin...
]
George Gastaldi closed ROASTER-89.
----------------------------------
Assignee: George Gastaldi
Resolution: Done
Fields and methods now implement {{LocationCapable}} with the following methods:
{code:java}
/**
* Returns the character index into the original source file indicating where the
source fragment corresponding to
* this element begins.
*
* @return the 0-based character index, or -1 if no source position information is
recorded for this element
*/
int getStartPosition();
/**
* Returns the character index into the original source file indicating where the
source fragment corresponding to
* this element ends.
*
* @return a (possibly 0) length, or <code>0</code> if no source position
information is recorded for this node
*/
int getEndPosition();
/**
* Returns the line number corresponding to the given source character position in the
original source string. The
* initial line of the compilation unit is numbered 1, and each line extends through
the last character of the
* end-of-line delimiter. The very last line extends through the end of the source
string and has no line delimiter.
* For example, the source string <code>class A\n{\n}</code> has 3 lines
corresponding to inclusive character ranges
* [0,7], [8,9], and [10,10]. Returns -1 for a character position that does not
correspond to any source line, or -2
* if no line number information is available for this compilation unit.
*
* @return the 1-based line number, or <code>-1</code> if the character
position does not correspond to a source line
* in the original source file or <code>-2</code> if line number
information is not known for this
* compilation unit
*/
int getLineNumber();
/**
* Returns the column number corresponding to the given source character position in
the original source string.
* Column number are zero-based. Return <code>-1</code> if it is beyond the
valid range or <code>-2</code> if the
* column number information is unknown.
*
* @return the 0-based column number, or <code>-1</code> if the character
position does not correspond to a source
* line in the original source file or <code>-2</code> if column
number information is unknown for this
* compilation unit
*/
int getColumnNumber();
{code}
Add API to get the line number and absolute position
----------------------------------------------------
Key: ROASTER-89
URL:
https://issues.jboss.org/browse/ROASTER-89
Project: Roaster
Issue Type: Feature Request
Affects Versions: 2.17.4.Final
Reporter: Claus Ibsen
Assignee: George Gastaldi
Fix For: 2.17.5.Final
When using Roaster to parse java source code, you have the various types, such as fields
FieldSource<JavaClassSource> field
MethodSource<JavaClassSource> method
and so on
The backing JDT AST has the position of where those types are in the source code.
It would be good to have an api that can provide
- the absolute position (absolute char position)
- the line number
- the relative position in the line
You can derive the latter two values from the absolute position.
The AST has the absolute start position in code alike:
org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ASTNode#getStartPosition
The need for this is to be able to provide better feedback to the end users, where in the
source code the node is, such as if you use it to parse and validate, or if you want to
build a custom search function etc.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)