Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » IASTFileLocation to IDocument location
IASTFileLocation to IDocument location [message #737211] Fri, 14 October 2011 19:44
eric.julien+eclipse is currently offline eric.julien+eclipseFriend
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

Previous Topic:stack memory full?!? PLEASE REPLY
Next Topic:Linking SDL in Mac OS X
Goto Forum:
  


Current Time: Sat Apr 27 02:53:03 GMT 2024

Powered by FUDForum. Page generated in 0.03314 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top