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 User |
|
|
|
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 "";
}
|
|
|
Powered by
FUDForum. Page generated in 0.04176 seconds