cleanup [java-psi]: PsiFormatUtil.getPackageDisplayName i18n, docs

GitOrigin-RevId: 89f3c0fb0a3dfcb652fd0b4d9044d3141b31d989
This commit is contained in:
Tagir Valeev
2025-11-07 08:32:51 +00:00
committed by intellij-monorepo-bot
parent c14e322043
commit e9cedba1cc
2 changed files with 14 additions and 4 deletions
@@ -219,3 +219,6 @@ annotation.target.TYPE=type
annotation.target.TYPE_PARAMETER=type parameter
# suppress inspection "UnusedProperty"
annotation.target.TYPE_USE=type use
local.class=local class
default.package=default package
type.parameter.of=type parameter of {0}
@@ -11,6 +11,7 @@ import com.intellij.util.ExceptionUtil;
import com.intellij.util.ObjectUtils;
import com.intellij.util.VisibilityUtil;
import org.intellij.lang.annotations.MagicConstant;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -466,7 +467,12 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
return builder.toString();
}
public static String getPackageDisplayName(@NotNull PsiClass psiClass) {
/**
* @param psiClass class to get the package name from
* @return user-friendly additional information about class location. Usually, a package name,
* but could be also a containing class of a type parameter or something like "local class".
*/
public static @Nls String getPackageDisplayName(@NotNull PsiClass psiClass) {
if (psiClass instanceof PsiTypeParameter) {
PsiTypeParameterListOwner owner = ((PsiTypeParameter)psiClass).getOwner();
String ownerName = null;
@@ -479,17 +485,18 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
else if (owner instanceof PsiMethod) {
ownerName = owner.getName();
}
return ownerName == null ? "type parameter" : "type parameter of " + ownerName;
return ownerName == null ? JavaPsiBundle.message("element.type.parameter") :
JavaPsiBundle.message("type.parameter.of", ownerName);
}
if (PsiUtil.isLocalClass(psiClass)) {
return "local class";
return JavaPsiBundle.message("local.class");
}
String packageName = psiClass.getQualifiedName();
packageName = packageName == null || packageName.lastIndexOf('.') <= 0 ? "" : packageName.substring(0, packageName.lastIndexOf('.'));
if (packageName.isEmpty()) {
packageName = "default package";
packageName = JavaPsiBundle.message("default.package");
}
return packageName;
}