IASTFileLocation to IDocument location [message #737211] |
Fri, 14 October 2011 19:44 |
eric.julien+eclipse Messages: 4 Registered: February 2011 |
Junior Member |
|
|
I'm trying to implement a plugin that reformats code (the code style formatter in CDT isn't flexible enough for the coding style I'm trying to enforce) and I have managed to successfully read the AST and generate a string that contains what I'd like to replace a specific node for.
The problem is I'm trying to do a IDocument.replace() with the offset/length specified in the IASTFileLocation returned by node.getFileLocation(). It seems that the node offset doesn't always match the IDocument offset.
In other words, in the following code:
IASTCallExpression call_expr;
ITranslationUnit tu;
IDocument textDocument;
... //tu and textDocument refer to the same file
System.out.println("call_exp=" + textDocument.get(call_exp.getFileLocation().getNodeOffset(), call_exp.getFileLocation().getNodeLength()));
String expStr = new String(tu.getContents());
expStr = expStr.substring(call_exp.getFileLocation().getNodeOffset(), call_exp.getFileLocation().getNodeLength() + call_exp.getFileLocation().getNodeOffset());
System.out.println(expStr);
In the preceding snippet, the first print often has extra white space in the beginning and is missing some characters at the end.
What would be the correct way to find the document location given a AST node location or what would be the correct way to make the changes to my source file?
Thanks,
Eric
[Updated on: Fri, 14 October 2011 19:44] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03314 seconds