[java] PackageIndex: a separate method for getPackageName not only by directory but also by file (IDEA-368975)

GitOrigin-RevId: b1d18ecde7b5d9759e3edd196d3b7baf0d49da00
This commit is contained in:
Tagir Valeev
2025-05-19 15:56:41 +00:00
committed by intellij-monorepo-bot
parent 0af7361c24
commit 1d9df9dd02
16 changed files with 60 additions and 30 deletions
@@ -1,6 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.PackageIndex;
import com.intellij.openapi.util.NlsSafe;
@@ -13,6 +14,8 @@ import org.jetbrains.annotations.Nullable;
@ApiStatus.Internal
public final class ProjectPackageIndexImpl extends PackageIndex {
private static final Logger LOG = Logger.getInstance(ProjectPackageIndexImpl.class);
private final DirectoryIndex myDirectoryIndex;
@ApiStatus.Internal
@@ -36,8 +39,16 @@ public final class ProjectPackageIndexImpl extends PackageIndex {
return myDirectoryIndex.getDirectoriesByPackageName(packageName, includeLibrarySources);
}
@Override
public @Nullable String getPackageName(@NotNull VirtualFile fileOrDir) {
return myDirectoryIndex.getPackageName(fileOrDir);
}
@Override
public @Nullable String getPackageNameByDirectory(@NotNull VirtualFile dir) {
if (!dir.isDirectory()) {
LOG.error(dir.getPresentableUrl() + " is not a directory");
}
return myDirectoryIndex.getPackageName(dir);
}
}