Use PsiDocumentManager.getPsiFile(Document) to obtain a PsiFile, use PsiFile.getVirtualFile() to obtain its VirtualFile, then use ProjectRootManager.getFileIndex().getModuleForFile(VirtualFile).
Hope this helps, Friendly, Dmitry
-- Dmitry Lomov Software Developer JetBrains Inc. http://www.jetbrains.com "Develop with pleasure!"
Use PsiDocumentManager.getPsiFile(Document) to obtain a PsiFile, use PsiFile.getVirtualFile() to obtain its VirtualFile, then use ProjectRootManager.getFileIndex().getModuleForFile(VirtualFile).
>
Hope this helps, Friendly, Dmitry
>
-- Dmitry Lomov Software Developer JetBrains Inc. http://www.jetbrains.com "Develop with pleasure!"
>> thx!!!!!!! >> >> and can I get the URL of classes file of Current Java File ?? >> >> >> "Dmitry Lomov (JetBrains)" <Dmitry.Lomov@jetbrains.com> wrote in message >> news:c31et7$t2m$1@is.intellij.net... >> > Dragon wrote: >> > >> > > Module Name or Module ; >> > >> > Use PsiDocumentManager.getPsiFile(Document) to obtain a PsiFile, >> > use PsiFile.getVirtualFile() to obtain its VirtualFile, >> > then use
You should call getOriginalElement() on the psiElement, which should have a nonnull getVirtualFile(). (Completion is implemented by creating a virtual copy of the file.)
Alexei wrote:
How to get current virtual file when code completion occurs? I use CompletionData for the code completion.
The call below returns null: psiElement.getContainingFile().getVirtualFile() (this call resides in the ContextGetter.get(PsiElement psiElement, CompletionContext context) method).
Dragon wrote:
Use PsiDocumentManager.getPsiFile(Document) to obtain a PsiFile,
use PsiFile.getVirtualFile() to obtain its VirtualFile,
then use ProjectRootManager.getFileIndex().getModuleForFile(VirtualFile).
Hope this helps,
Friendly,
Dmitry
--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"
thx!!!!!!!
and can I get the URL of classes file of Current Java File ??
"Dmitry Lomov (JetBrains)" <Dmitry.Lomov@jetbrains.com> wrote in message
news:c31et7$t2m$1@is.intellij.net...
>
>
>
>
ProjectRootManager.getInstance(project).getFileIndex().getClassRootForFile(v
file)
"Dragon" <jbuilder@vip.sina.com> wrote in message
news:c31fns$27b$1@is.intellij.net...
>
>
>
ProjectRootManager.getFileIndex().getModuleForFile(VirtualFile).
>
>
Dragon wrote:
>ProjectRootManager.getInstance(project).getFileIndex().getClassRootForFile(vfile)
No, not exactly. This returns a class root for a class file.
I believe we do not have an OpenAPI functionality for that.
Friendly,
Dmitry
>> thx!!!!!!!
>>
>> and can I get the URL of classes file of Current Java File ??
>>
>>
>> "Dmitry Lomov (JetBrains)" <Dmitry.Lomov@jetbrains.com> wrote in message
>> news:c31et7$t2m$1@is.intellij.net...
>> > Dragon wrote:
>> >
>> > > Module Name or Module ;
>> >
>> > Use PsiDocumentManager.getPsiFile(Document) to obtain a PsiFile,
>> > use PsiFile.getVirtualFile() to obtain its VirtualFile,
>> > then use
>> >
>> > Hope this helps,
>> > Friendly,
>> > Dmitry
>> >
>> > --
>> > Dmitry Lomov
>> > Software Developer
>> > JetBrains Inc.
>> > http://www.jetbrains.com
>> > "Develop with pleasure!"
>>
>>
--
Dmitry Lomov
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"
How to get current virtual file when code completion occurs? I use CompletionData for the code completion.
The call below returns null:
psiElement.getContainingFile().getVirtualFile()
(this call resides in the ContextGetter.get(PsiElement psiElement, CompletionContext context) method).
You should call getOriginalElement() on the psiElement, which should
have a nonnull getVirtualFile(). (Completion is implemented by creating
a virtual copy of the file.)
Alexei wrote:
The call below
psiElement.getContainingFile().getOriginalFile().getVirtualFile()
returns non-null VirtualFile.