Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-core-dev] How to obtain line and/or column from parsed java source from Eclipse JDT Parser from all nodes?

Did you try this:

unit.getLineNumber(methodDeclaration.getStartPosition())

Where unit is the CompilationUnit containing the method declaration?

Regards,
Jay



From:        Carlos Andrade <carlosviansi@xxxxxxxxx>
To:        jdt-core-dev@xxxxxxxxxxx
Date:        08/17/2012 02:34 AM
Subject:        [jdt-core-dev] How to obtain line and/or column from parsed java source from Eclipse JDT Parser from all nodes?
Sent by:        jdt-core-dev-bounces@xxxxxxxxxxx




Dears,

I've been playing for quite a while now with ASTs and was trying to get the line and column information associated to a given node parsed on this plugin from eclipse. According to the documented api here I found that the method getStartPosition() can give me the position on the characters of the file that was parsed, but this is not what I wanted.
I went on the CompilationUnit class api documentation to find out the methods getLineNumber(int position) and getColumnNumber(int position) which from my understanding can do the trick. the position paramater is nothing less than what the getStartPosition() method returns, by doing node.getStartPosition().
Now, the problem is the two methods that get line and column on source file doesn't seems to be available for all nodes. For instance, the method declaration nodes don't have them!
How can I get such information on all the tree? I know this is not impossible since I was able to use parsers for other languages that for every ast node had a line and column associated with it. In fact, I was able to do that with javaparser which is one of them for java, since the class contains attributes for line and column hardcoded. Seeing Eclipse JDT seemed to me much more robust to me and being there for quite a while, I would be surprised that such information would not be possible to acquire.
An exact replica of this question was posted on stack overflow (http://stackoverflow.com/questions/11911185/how-to-obtain-line-and-or-column-from-parsed-java-source-from-eclipse-jdt-parser) by me few days ago but to my surprise no reply was offered.
I very much appreciate your time on helping me on this question.
Thank you.


Carlos Andrade

http://carlosandrade.co
_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jdt-core-dev


Back to the top