2 quick questions

(ideal code snippets candidates for the "OpenAPI online Almanac")



1/
How can I open a project file/class in an editor when I only know its
path/name (and not its module)?


2/
How can I "install" a LvcsLabelListener?


Alain

10 comments

Hello Alain,

AR> 1/
AR> How can I open a project file/class in an editor when I only know
AR> its path/name (and not its module)?

You can use FileEditorManager to open files in editors for given file type.
FileEditorManager.openFile(VirtualFile file);

Thanks!
--
Alexey Efimov, Java Developer
Tops BI
http://www.topsbi.ru

0


Alexey

> You can ..
Thanks.

Now question 2 , sorry for being so blind, but how do I turn a FQN into
a VirtualFile?

String classFQN = "a.Foo";
VirtualFile fooVF = ???

Alain

0

Alain Ravet wrote:


Alexey

> You can ..
Thanks.

Now question 2 , sorry for being so blind, but how do I turn a FQN into
a VirtualFile?

String classFQN = "a.Foo";
VirtualFile fooVF = ???

Alain

psiManager.findClass(classFQN).getContainingFile().getVirtualFile()

--
Maxim Shafirov
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0

psiManager.findClass(classFQN).getContainingFile().getVirtualFile()

Checking for nulls every call out there is a must.

--
Maxim Shafirov
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"

0


3/ How can I find the module, associated to an editor/psiFile?


TIA

Alain

Call me blind, but I couldn't figure this one out. I wish there were a superCompletion tool to help me fill the blank in Module m = aPsiFile. It would visit the tree, breadth first, of variables and methods starting at the source (aPsiFile.), and display all the matches/candidate. ]]>

0

This supercompletion will be of no help here I afraid...

final ProjectFileIndex fileIndex =
ProjectRootManager.getInstance(project).getFileIndex();
final VirtualFile virtualFile = containingFile.getVirtualFile();
return fileIndex.getModuleForFile(virtualFile);


--
regards,
Alexey Kudravtsev
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


"Alain Ravet" <alain.ravet@biz.tiscali.be> wrote in message
news:cqu14u$6lo$1@is.intellij.net...
>

3/ How can I find the module, associated to an editor/psiFile?

>
>

TIA

>

Alain

>

<OT>
Call me blind, but I couldn't figure this one out.
I wish there were a superCompletion tool to help me fill the blank in
Module m = aPsiFile.<caret>

>

It would visit the tree, breadth first, of variables and methods starting
at the source (aPsiFile.), and display all the matches/candidate.
</OT>



0

Alexey

>This supercompletion will be of no help here I afraid...
>

final ProjectFileIndex fileIndex =

>ProjectRootManager.getInstance(project).getFileIndex();

final VirtualFile virtualFile = containingFile.getVirtualFile();
return fileIndex.getModuleForFile(virtualFile);

>


Thanks a lot. It will help me finish the next version of the MiniWiki.
This info/code snippet should be the openAPI javadoc.

Alain

0

Alexey Kudravtsev (JetBrains) wrote:

>This supercompletion will be of no help here I afraid...
>

>

What would be helpful is a way to ask:
"what method has a virtualFile as (one of its) parameter(s), and
returns a module."


Alain

0

Hi, there is a way to ask (but not very easy enough yet:)

class $a$ {
$Module$ $getModule$($BeforeParamType$ $BeforeParamName$, VirtualFile
$parameter$, $AfterParamType$ $AfterParamName$);
}

$Module$ is Module in type hierarchy
$getModule$ is target of the search.
$AfterParamType$, $AfterParamName$, $BeforeParamType$, $BeforeParamName$
0..1000

Alain Ravet wrote:

Alexey Kudravtsev (JetBrains) wrote:

>> This supercompletion will be of no help here I afraid...
>>
>>
>>


What would be helpful is a way to ask:
"what method has a virtualFile as (one of its) parameter(s), and
returns a module."


Alain



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Please sign in to leave a comment.