Alternative for deprecated PsiFile.createPseudoPhysicalCopy() ?

Calling this method seems to be important if one wants to obtain a Document instance for a
manually created PsiFile that's not been backed by a VirtualFile:

PsiFile file = parserDefinition.createFile(project, "foo", s).createPseudoPhysicalCopy();
Document d = PsiDocumentManager.getInstance(project).getDocument(file);

Unless createPseudoPhysicalCopy() is called, the returned Document will be null.

What's the recommended replacement using non-deprecated methods to achieve the effect
described above? The "for IDEA internal use only" hint isn't very helpful unfortunately as
this method seems to serve a purpose that's clearly within the scope of the OpenAPI.

Thanks,
Sascha

2 comments

Hello Sascha,

SW> Calling this method seems to be important if one wants to obtain a
SW> Document instance for a manually created PsiFile that's not been
SW> backed by a VirtualFile:
SW>
SW> PsiFile file = parserDefinition.createFile(project, "foo",
SW> s).createPseudoPhysicalCopy(); Document d =
SW> PsiDocumentManager.getInstance(project).getDocument(file);
SW>
SW> Unless createPseudoPhysicalCopy() is called, the returned Document
SW> will be null.
SW>
SW> What's the recommended replacement using non-deprecated methods to
SW> achieve the effect described above? The "for IDEA internal use only"
SW> hint isn't very helpful unfortunately as this method seems to serve
SW> a purpose that's clearly within the scope of the OpenAPI.

The documentation should have said "for advanced use only", not "for IDEA
internal use only". :) Indeed, this method is used exactly in the cases
that you describe, and there is no replacement for it. I'll remove the deprecated
annotation and document this use of the method.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0

Dmitry Jemerov (JetBrains) wrote:

The documentation should have said "for advanced use only", not "for
IDEA internal use only". :) Indeed, this method is used exactly in the
cases that you describe, and there is no replacement for it. I'll remove
the deprecated annotation and document this use of the method.


Cool, thanks. I don't like to see yellow deprecation warnings in my code ;)

Sascha

0

Please sign in to leave a comment.