ProjectFileIndex question


I run this on a project content java source file virtual file:
R1 one is empty (no surprise here)
R2 & R3 point to the output root of the project. Is it what a orderEntry is? With a name like orderEntriesForFile I thought it would give me the compiled class file path. Is there a way to do that?
R4 is null! That is a very big surprise. Why would it? Why not have R4 returns the same as R2/R3? Is it supposed to work like that?

Next a question Q1:

is the multiple OrderEntry for multi-module project? Is there at most one OrderEntry per module per file?

Thanks

Jacques

3 comments
Comment actions Permalink

BTW what is the difference between the three type of order type:
CLASSES,
CLASSES_AND_OUTPUT and
COMPILATION_CLASSES?

0
Comment actions Permalink

Jacques,





Jacques Morel wrote:

 ProjectFileIndex index =
> ProjectRootManager.getInstance(project).getFileIndex();
> 
> OrderEntry[] orderEntriesForFile = index.getOrderEntriesForFile(file);
> // (Q1)
> 
> for (int i = 0; i < orderEntriesForFile.length; i++) {
>    OrderEntry orderEntry = orderEntriesForFile+;
>    orderEntry.getFiles(OrderRootType.CLASSES) (R1)
>    orderEntry.getFiles(OrderRootType.CLASSES_AND_OUTPUT) (R2)
>    orderEntry.getFiles(OrderRootType.COMPILATION_CLASSES) (R3)
> }
> 
> VirtualFile classRoot = index.getClassRootForFile(file); (R4)
> 
> ]]>


I run this on a project content java source file virtual file:
R1 one is empty (no surprise here)
R2 & R3 point to the output root of the project. Is it what a orderEntry
is? With a name like orderEntriesForFile I thought it would give me the
compiled class file path. Is there a way to do that? R4 is null! That is a
very big surprise. Why would it? Why not have R4 returns the same as
R2/R3? Is it supposed to work like that?


Yes, it is supposed to wrok like that.

OrderEntry is an abstraction of "an element of a class path" (cf.
ModuleRootManager.getOrder()).
Every module have a collection of OrderEntries that comprise its "Order", or
class path. It has an OrderEntry for any library this module depends on,
for every module this module depends on and for itself.

Now, OrderEntry.getFiles() returns roots for files of various types (cf.
OrderRootType).

FileIndex.getOrderEntriesForFile returns OrderEntries that contains root
that this file resides in.

FileIndex.getClassRootForFile returns class root for a file that is in class
root. That is why R4 returns null: your file is not a class file.
To find where its class file is, get its order entry and take its
CLASSES_AND_OUTPUT files. One of them contains its class file. Be aware
though that output is usually excluded.


Next a question Q1:

is the multiple OrderEntry for multi-module project?

Yes.

Is there at most one OrderEntry per module per file?

Yes.

I hope this helps. If not, do not hesistate to ask further.

Friendly,
Dmitry

--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

As usual thanks Dmitry.

0

Please sign in to leave a comment.