mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Java: remove duplicated utility method
(cherry picked from commit e539495083603140f3fd4176374ad5a0e01852c1) GitOrigin-RevId: 612d250c0a6550e3ae733cf78f4016013b20d7b8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e1b1b53039
commit
44840c3a42
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.daemon.impl.analysis.JavaModuleGraphUtil;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaFileCodeStyleFacade;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -578,7 +579,7 @@ public final class ImportUtils {
|
||||
if (importReference == null) continue;
|
||||
String referenceName = importReference.getQualifiedName();
|
||||
if (referenceName == null) continue;
|
||||
myStaticImportStatements.put(staticStatement.isOnDemand() ? referenceName : getPackageOrClassName(referenceName),
|
||||
myStaticImportStatements.put(staticStatement.isOnDemand() ? referenceName : StringUtil.getPackageName(referenceName),
|
||||
staticStatement);
|
||||
}
|
||||
else if (anImport instanceof PsiImportModuleStatement moduleStatement) {
|
||||
@@ -592,7 +593,7 @@ public final class ImportUtils {
|
||||
}
|
||||
|
||||
public boolean isImplicitlyImported(String qName, boolean isStatic) {
|
||||
String packageOrClassName = getPackageOrClassName(qName);
|
||||
String packageOrClassName = StringUtil.getPackageName(qName);
|
||||
String className = ClassUtil.extractClassName(qName);
|
||||
if (!isStatic) {
|
||||
for (PsiImportModuleStatement psiImportModuleStatement : myModulesStatements) {
|
||||
@@ -621,11 +622,6 @@ public final class ImportUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static @NotNull String getPackageOrClassName(@NotNull String className){
|
||||
int dotIndex = className.lastIndexOf('.');
|
||||
return dotIndex < 0 ? "" : className.substring(0, dotIndex);
|
||||
}
|
||||
|
||||
private static boolean memberReferenced(PsiMember member, PsiElement context) {
|
||||
final MemberReferenceVisitor visitor = new MemberReferenceVisitor(member);
|
||||
context.accept(visitor);
|
||||
|
||||
@@ -152,7 +152,7 @@ public final class ImportHelper{
|
||||
Object2IntMap<String> packageToCountMap = new Object2IntOpenHashMap<>();
|
||||
Object2IntMap <String> classToCountMap = new Object2IntOpenHashMap<>();
|
||||
for (Import anImport : resultList) {
|
||||
String packageOrClassName = ImportUtils.getPackageOrClassName(anImport.name());
|
||||
String packageOrClassName = StringUtil.getPackageName(anImport.name());
|
||||
if (packageOrClassName.isEmpty()) continue;
|
||||
Object2IntMap<String> map = anImport.isStatic() ? classToCountMap : packageToCountMap;
|
||||
map.put(packageOrClassName, map.getOrDefault(packageOrClassName, 0) + 1);
|
||||
@@ -175,7 +175,7 @@ public final class ImportHelper{
|
||||
PackageEntry[] entries = settings.IMPORT_LAYOUT_TABLE.getEntries();
|
||||
for (int i = 0; i < imports.size(); i++) {
|
||||
Import anImport = imports.get(i);
|
||||
entryForName[i] = findEntryIndex(ImportUtils.getPackageOrClassName(anImport.name()),
|
||||
entryForName[i] = findEntryIndex(StringUtil.getPackageName(anImport.name()),
|
||||
settings.LAYOUT_STATIC_IMPORTS_SEPARATELY && anImport.isStatic(), entries);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public final class ImportHelper{
|
||||
Set<String> namesToUseSingle = new HashSet<>();
|
||||
for (Import anImport : imports) {
|
||||
String name = anImport.name();
|
||||
String prefix = ImportUtils.getPackageOrClassName(name);
|
||||
String prefix = StringUtil.getPackageName(name);
|
||||
if (prefix.isEmpty()) continue;
|
||||
boolean isImplicitlyImported = checker.isImplicitlyImported(name, anImport.isStatic());
|
||||
if (!onDemandImports.contains(prefix) && !isImplicitlyImported) continue;
|
||||
@@ -384,7 +384,7 @@ public final class ImportHelper{
|
||||
for (Import importedName : imports) {
|
||||
String name = importedName.name();
|
||||
boolean isStatic = importedName.isStatic();
|
||||
String packageOrClassName = ImportUtils.getPackageOrClassName(name);
|
||||
String packageOrClassName = StringUtil.getPackageName(name);
|
||||
boolean implicitlyImported = implicitImportContext.isImplicitlyImported(name, isStatic);
|
||||
boolean useOnDemand = implicitlyImported || packagesOrClassesToImportOnDemand.contains(packageOrClassName);
|
||||
Import current = new Import(packageOrClassName, isStatic);
|
||||
@@ -434,7 +434,7 @@ public final class ImportHelper{
|
||||
if (!ImportFilter.shouldImport(file, className)) {
|
||||
return false;
|
||||
}
|
||||
String packageName = ImportUtils.getPackageOrClassName(className);
|
||||
String packageName = StringUtil.getPackageName(className);
|
||||
String shortName = PsiNameHelper.getShortClassName(className);
|
||||
|
||||
PsiImportStatement unusedSingleImport = findUnusedSingleImport(file, shortName, className);
|
||||
@@ -630,7 +630,7 @@ public final class ImportHelper{
|
||||
for (PsiClass ref1 : refs) {
|
||||
String className = ref1.getQualifiedName();
|
||||
if (className == null) continue;
|
||||
if (ImportUtils.getPackageOrClassName(className).equals(packageName)) {
|
||||
if (StringUtil.getPackageName(className).equals(packageName)) {
|
||||
PsiJavaCodeReferenceElement ref = file.findImportReferenceTo(ref1);
|
||||
if (ref != null) {
|
||||
array.add(ref);
|
||||
@@ -834,14 +834,7 @@ public final class ImportHelper{
|
||||
int findEntryIndex(@NotNull PsiImportStatementBase statement) {
|
||||
PsiJavaCodeReferenceElement ref = statement.getImportReference();
|
||||
if (ref == null) return -1;
|
||||
String packageName;
|
||||
if (statement.isOnDemand()) {
|
||||
packageName = ref.getCanonicalText();
|
||||
}
|
||||
else {
|
||||
String className = ref.getCanonicalText();
|
||||
packageName = ImportUtils.getPackageOrClassName(className);
|
||||
}
|
||||
String packageName = statement.isOnDemand() ? ref.getCanonicalText() : StringUtil.getPackageName(ref.getCanonicalText());
|
||||
return findEntryIndex(packageName,
|
||||
mySettings.LAYOUT_STATIC_IMPORTS_SEPARATELY && statement instanceof PsiImportStaticStatement,
|
||||
mySettings.IMPORT_LAYOUT_TABLE.getEntries());
|
||||
|
||||
Reference in New Issue
Block a user