Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » ISourceRange question
ISourceRange question [message #250398] Sat, 29 December 2007 21:14
Eclipse UserFriend
Hi,

I'm using this code (see below) to change a method in a class.
It works perfectly.
But if before the method I put any comment (javadoc) it is deleted :/

------------
IBuffer buffer = imethod.getOpenable().getBuffer();
ISourceRange sourceRange = imethod.getSourceRange();
ISourceRange nameRange = imethod.getNameRange();
IScanner scanner = null; // delay initialization

if (sourceRange != null && nameRange != null) {
if (scanner == null) {
scanner = ToolFactory.createScanner(false, false, true, false);
scanner.setSource(buffer.getCharacters());
}
scanner.resetTo(sourceRange.getOffset(), nameRange.getOffset());
}


StringBuffer sourceMethod = new StringBuffer();
//sourceMethod = new method source

buffer.replace(sourceRange.getOffset(), sourceRange.getLength(),
sourceMethod.toString());
imethod.getOpenable().save(null, true);
------------

How to not delete comment?
I believe this problem is in ISourceRange...

imethod -> org.eclipse.jdt.core.IMethod
buffer -> org.eclipse.jdt.core.IBuffer
sourceRange -> org.eclipse.jdt.core.ISourceRange

thanks!!!
Previous Topic:convert interface to abstract class
Next Topic:Q: code template for gettors/settors
Goto Forum:
  


Current Time: Thu Apr 24 09:31:31 EDT 2025

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

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

Back to the top