Find API replacement for DirectoryIndex getDirectoriesByPackageName

The plugin verifier is hopefully going to become useful in time but at the minute it’s indicating a problem with the Intellij API rather than plugin developers use of the publicly accessible classes and methods that have been made available.

It would be good to get some acknowledgement of the problem from Jetbrains as the current state of things is causing needless headache for the many developers that are working on plugins for the Jetbrains eco-system.

Here’s an example of how annoying this process is:

I have a plugin that currently uses com.intellij.openapi.roots.impl.DirectoryIndex and then calls getDirectoriesByPackageName(qualifiedName, true). The verifier has indicated that I should not use it. It’s marked as @Internal and @Obsolete so I look for the alternative. By looking at the source on intellij-community I can see that I’m expected to use com.intellij.openapi.roots.ProjectFileIndex and other APIs instead. So I take a look at ProjectFileIndex but it doesn’t have the functionality I’m currently using.

Back on DirectoryIndex the Javadoc for getDirectoriesByPackageName indicates that WorkspaceFileIndexEx#getDirectoriesByPackageName(String, boolean) is the alternative. Awesome, or so I thought, because the WorkspaceFileIndexEx approach also results in verification errors (although it isn’t actually annotated as internal). So I looked for another option and found PlatformPackageUtil.getDirectoriesByPackageName(qualifiedName, true, project) but alas this is also marked as internal use only.

This example is just one of many verification errors for which I’ve been digging around to find a solution. Some of the time, after having investigated for a while, I find there’s no available alternative at all.

You seem do not follow documentation for internal usages,

JavaDoc:

  /**
   * Returns a query producing directories which correspond to {@code packageName}.
   * This is an internal function, plugins must use {@link com.intellij.openapi.roots.PackageIndex#getDirsByPackageName} instead.
   */

Usage:

PackageIndex.getInstance(project).getDirectoriesByPackageName(pkgName, false);

Deprecation is not always for plugin usages, this is rather unfortunate, but we deprecate stuff for our internal use as well. Sorry, for missing guidance in that area!

perhaps com.intellij.openapi.roots.PackageIndex is new. It doesn’t exist on the version of Intellij I am targeting.

com.intellij.openapi.roots.PackageIndex is here since 2008.

Packages concept only provided in Java plugin and you need dependency on Java plugin for it - bundledPlugin("com.intellij.java") and <depends>com.intellij.java</depends>

External plugins also use it