Get all PSI/Virtual Files within a project

Answered

I am writing a small Intellij plugin, and in that I need to get all source code files that are within a specific project as PSI/Virtual file (in my understanding both are interexchangeable so it won't matter which of the two I get). 

Is there any way to do this? 

 

0
6 comments

Hi,

thanks for your answer and as it seems this should work. But I don't know how to get the LanguageFileType. Can you tell me how I can get instances of the LanguageFileType for at least java ? 

0

For Java, it's com.intellij.ide.highlighter.JavaFileType#INSTANCE
You can lookup any others via "Goto Class" and typing "*FileType" to list all classes matching this pattern.

See also https://plugins.jetbrains.com/docs/intellij/explore-api.html

0

What should we import in order to access `JavaFileType` from a test? I have a test file like:
```

class MyPluginTest : BasePlatformTestCase() {
    fun test() {
val fileText: String = """
package com.loma.test

/*
hello hello<caret>
*/
""".trimIndent()
val psiFile = myFixture.configureByText(JavaFileType, fileText)
       assertInstanceOf(psiFile, JavaFileType::class.java)
}

And IntelliJ auto import isn't finding `JavaFileType`, I guess it's not in the classpath. What should I add to my build.gradle?

My project is the template project here, just with this change to the test file https://github.com/JetBrains/intellij-platform-plugin-template

0

Yann Cebron That worked! And, the same approach worked for Kotlin using `org.jetbrains.kotlin`. Thank you very much

0

Please sign in to leave a comment.