String (@NotNull ViewSettings settings, PsiPackage aPackage, final PsiPackage parentPackageInTree, @NotNull String defaultShortName, boolean isFQNameShown) { final String name; if (isFQNameShown) { name = settings.isAbbreviatePackageNames() ? aPackage == null ? defaultShortName : TreeViewUtil.calcAbbreviatedPackageFQName(aPackage) : aPackage == null ? defaultShortName : aPackage.getQualifiedName(); } else if (parentPackageInTree != null || aPackage != null && aPackage.getParentPackage() != null) { if (parentPackageInTree != null && aPackage != null) { String prefix = parentPackageInTree.getQualifiedName(); String string = aPackage.getQualifiedName(); int length = prefix.length(); if (length == 0) { if (!string.isEmpty()) return string; } else if (string.startsWith(prefix)) { if (length < string.length() && '.' == string.charAt(length)) length++; if (length < string.length()) return string.substring(length); } } PsiPackage parentPackage = aPackage.getParentPackage(); final StringBuilder buf = new StringBuilder(); buf.append(aPackage.getName()); while (parentPackage != null && !parentPackage.equals(parentPackageInTree)) { final String parentPackageName = parentPackage.getName(); if (parentPackageName == null || parentPackageName.isEmpty()) { break; // reached default package } buf.insert(0, "."); buf.insert(0, parentPackageName); parentPackage = parentPackage.getParentPackage(); } name = buf.toString(); } else { name = defaultShortName; } return name; }