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

0

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

请先登录再写评论。