How to prevent cursor re-positioning? [message #251828] |
Mon, 03 March 2008 09:34  |
Eclipse User |
|
|
|
Originally posted by: topgun.in.gmail.com
I created a sample plug-in to change the access modifier of a method from
a pop up menu. Every time I right click and select an option to change the
modifier, the access modifier is changed as required, but once I apply the
changes the cursor runs to beginning of the source. How do I prevent that?
I use ASTRewrite to modify the ast and Document object to commit the
modified ast. I believe the changes should be applied in some what
different manner. AT present it is as follows :-
code snippet :
...
Document document = null;
try {
document = new Document(cu.getBuffer().getContents());
} catch (JavaModelException e) {
e.printStackTrace();
}
TextEdit edits = astRewrite.rewriteAST(document,
cu.getJavaProject().
getOptions(true));
try {
edits.apply(document);
String newSource = document.get();
cu.getBuffer().setContents(newSource);
} catch (MalformedTreeException e) {
e.printStackTrace();
}
...
Thanks,
Pushkar
|
|
|
|
Re: How to prevent cursor re-positioning? [message #251994 is a reply to message #251891] |
Tue, 11 March 2008 10:37  |
Eclipse User |
|
|
|
Originally posted by: topgun.in.gmail.com
Hello Benno,
I now apply the changes in the following manner,
ITextFileBufferManager bufferManager =
FileBuffers.getTextFileBufferManager();
IPath path = cu.getPath();
bufferManager.connect(path, null, null);
ITextFileBuffer textFileBuffer =
bufferManager.getTextFileBuffer(path, LocationKind.IFILE);
IDocument document = textFileBuffer.getDocument();
TextEdit edits =
astRewrite.rewriteAST(document, cu.getJavaProject().getOptions(true));
edits.apply(document);
This works. Thanks Benno.
Pushkar
|
|
|
Powered by
FUDForum. Page generated in 0.03965 seconds