Why is psiFile.getVirtualFile().getFileType() sometimes RegExpFileType for the same java file?


I develop a LocalInspectionTool and override the checkFile method like this:

public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) { 
       psiFile.getVirtualFile().getFileType() instanceof RegExpFileType // is sometimes true, sometimes false, because it is JavaFileType

I verified that this is exactly the same file which is a java file! The exactly the same file is checked by different LocalInspectionTool's, but the FileType may change.

The question is, why is the fileType sometimes wrong? Actually the main issue about this is that


returns the wrong value (null) for a RegExpFileType and a valid path if it is JavaFileType.
Without correct source root for a file my plugin cannot handle it correctly.

If you know how to get correct source for a root file with RegExFileType it would be helpful in my situation as well.

Intellij Version: Ultimate 12.1.6

Thx !


Please post registration tag content of this inspection from your plugin.xml


The LocalInspectionTool's are created dynamicly during startup like this:


where the InspectionToolProvider is registered this way in plugins.xml:


what I do is just running all those inspections for the one same file.


I assume this is some injected RegExp fragment "file" located in Java File. Could you verify what text content that file has?







VirtualFileWindow in /my/path/MyClass.java // file name is changed

actually this reg expr is really part of the java file.
Why does it happen? How do I ensure that each inspection is run for the file? Not every inspection get's the correct java psiFile and this way it is not handled!
I don't expect in checkFile that I get sub parts of a file!



VirtualFileWindow means that you are in injected fragment and there is no physical file on disc. You should rather use containing file to get information you need or check for a language (org.intellij.lang.regexp.RegExpLanguage), even register the inspection for the corresponding language in plugin.xml (language="RegExp")


first many thx for fast answers! :)

the java file I am analysing looks like:

Class {
   private String myReg = "^(\\d+-)?(\\d+)$";

What I do is :
run analyse
scope: current file
profile: all generated Inspections
of course this file exists on disc!
Actually the same happens if the scope is more then one file, but then it is just harder to understand what is going on ;)

the question is: why does intellij provides such regex fragments instead of the java file, and why it does not happen for some Inspections and why not for others?
The only difference between the Inspection classes is the description, rule key etc. Also all Inspections are java inspections (but well I did not defined it anywhere in intellij)


for the file MyClass.java exists 2 PsiFiles: one java file and one injected file with RegEx language. Both files should be passed to your inspection. Are you sure that only one of them is passed?


yes I am sure
actually this explains why I see the violations twice in phpstorm ;)
but not in intelliij :-(


The code is the same which run the inspections. You may see difference when IntelliLang plugin is not enabled in one of the cases or injection is disabled.


thank you very much, I'll check it on monday!


checked it today
unfortunatelly the plugin itself depends on intellij lang plugin, so it cannot run without


well the main difference between phpstorm and intellij is at least that phpstorm does not know anything about the JavaFileType ;-)
still cannot resolve this issue
how do I ensure that every physical file (does not matter which language!) is passed to each inspection?


Please sign in to leave a comment.