Get contents of editor verbatim

Good morning,

How can one access the current contents of a PSI file verbatim?

Currently I am using the following code:


This, however, always appears to output the file with Unix line separators. In projects containing files with Windows line separators the 'contents' variable is hence incorrect, containing data with Unix rather than Windows separators.

Am I going about this in the right way, or missing something important?

Many thanks for your help!

Cheers,
James

2 comments
Comment actions Permalink

Hello James,

IntelliJ IDEA always stores the current content of a PSI file with Unix line
separators. The line separators are converted to the correct format on save.

How can one access the current contents of a PSI file verbatim?

Currently I am using the following code:

 
> final Document fileDocument =
> PsiDocumentManager.getInstance(manager.getProject()).getDocument(psiFi
> le);
> 
> final String contents = fileDocument.getText();
> 
> ]]>


This, however, always appears to output the file with Unix line
separators. In projects containing files with Windows line separators
the 'contents' variable is hence incorrect, containing data with Unix
rather than Windows separators.

Am I going about this in the right way, or missing something
important?

Many thanks for your help!

Cheers,
James

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Thanks very much!

0

Please sign in to leave a comment.