Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Re: How to get an IDocument from an IResource? Need to translate lineNo to Char_start
Re: How to get an IDocument from an IResource? Need to translate lineNo to Char_start [message #97583] Tue, 22 July 2003 15:10
Eclipse UserFriend
Originally posted by: bozo.yahoo.com

Beth Tibbitts wrote:

> Short question: How do I get an IDocument from an IResource? Assume it's a
> file.

> Markers use line numbers but to do the squiggles (highlight a section of the
> line, not the whole line), I need char_start and char_end, which I have,
> but my values are relative to the current line. char_start and char_end
> need to be relative to the start of the file, so I need to translate them.

> It looks like there are methods in IDocument to do this calculation, but I
> can't figure out how to get an IDocument from an IFile or an IResource.

> Any ideas?
> Thanks.


Hope the following code helps....

IDocument doc = new Document(getText(file));

// getText() returns the contents of the file
public static String getText(IFile file) {
try {
InputStream in = file.getContents();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int read = in.read(buf);
while (read > 0) {
out.write(buf, 0, read);
read = in.read(buf);
}
return out.toString();
} catch (CoreException e) {
} catch (IOException e) {
}
return "";
}
Previous Topic:These newsgroups.
Next Topic:IResource.copy()
Goto Forum:
  


Current Time: Sun Jul 13 17:37:50 EDT 2025

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

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

Back to the top