can I get the Module Name of current file in Editor ?

Module Name or Module ;

and can I get the urls of classes of a Java file ?


7 comments

Dragon wrote:

Module Name or Module ;


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!"

0

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 ProjectRootManager.getFileIndex().getModuleForFile(VirtualFile).

>

Hope this helps,
Friendly,
Dmitry

>

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



0


ProjectRootManager.getInstance(project).getFileIndex().getClassRootForFile(v
file)


"Dragon" <jbuilder@vip.sina.com> wrote in message
news:c31fns$27b$1@is.intellij.net...

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

ProjectRootManager.getFileIndex().getModuleForFile(VirtualFile).

>

Hope this helps,
Friendly,
Dmitry

>

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

>
>


0

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


"Dragon" <jbuilder@vip.sina.com> wrote in message
news:c31fns$27b$1@is.intellij.net...

>> 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

ProjectRootManager.getFileIndex().getModuleForFile(VirtualFile).

>> >
>> > 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!"

0

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).

0

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).

0

The call below
psiElement.getContainingFile().getOriginalFile().getVirtualFile()
returns non-null VirtualFile.

0

Please sign in to leave a comment.