mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 00:20:55 +07:00
global inspections: try to get rid of long read lock (IDEA-226784)
GitOrigin-RevId: ed2c7e44b9f037d892379ab96d4732bedd10f51a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
960cc4c1fe
commit
3f5dd8da98
@@ -250,6 +250,11 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadActionNeeded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInspection(@NotNull final AnalysisScope scope,
|
||||
@NotNull InspectionManager manager,
|
||||
|
||||
@@ -40,6 +40,11 @@ public class InconsistentLanguageLevelInspection extends GlobalInspectionTool {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadActionNeeded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity,
|
||||
|
||||
@@ -19,13 +19,13 @@ package com.intellij.codeInspection.unusedLibraries;
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.reference.RefEntity;
|
||||
import com.intellij.codeInspection.reference.RefGraphAnnotator;
|
||||
import com.intellij.codeInspection.reference.RefManager;
|
||||
import com.intellij.codeInspection.reference.RefModule;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.*;
|
||||
@@ -71,60 +71,75 @@ public class UnusedLibrariesInspection extends GlobalInspectionTool {
|
||||
return new UnusedLibraryGraphAnnotator(refManager);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity,
|
||||
@NotNull AnalysisScope scope,
|
||||
@NotNull InspectionManager manager,
|
||||
@NotNull GlobalInspectionContext globalContext,
|
||||
@NotNull ProblemDescriptionsProcessor processor) {
|
||||
if (refEntity instanceof RefModule) {
|
||||
final RefModule refModule = (RefModule)refEntity;
|
||||
final Module module = refModule.getModule();
|
||||
|
||||
VirtualFile[] givenRoots =
|
||||
OrderEnumerator.orderEntries(module).withoutSdk()
|
||||
.withoutModuleSourceEntries()
|
||||
.withoutDepModules()
|
||||
.classes()
|
||||
.getRoots();
|
||||
public boolean isReadActionNeeded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (givenRoots.length == 0) return null;
|
||||
|
||||
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
|
||||
final Set<VirtualFile> usedRoots = refModule.getUserData(UnusedLibraryGraphAnnotator.USED_LIBRARY_ROOTS);
|
||||
|
||||
if (usedRoots != null) {
|
||||
appendUsedRootDependencies(usedRoots, givenRoots);
|
||||
}
|
||||
|
||||
final List<CommonProblemDescriptor> result = new ArrayList<>();
|
||||
for (OrderEntry entry : moduleRootManager.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry &&
|
||||
!((LibraryOrderEntry)entry).isExported() &&
|
||||
((LibraryOrderEntry)entry).getScope() != DependencyScope.RUNTIME) {
|
||||
final Set<VirtualFile> files = ContainerUtil.set(((LibraryOrderEntry)entry).getRootFiles(OrderRootType.CLASSES));
|
||||
boolean allRootsUnused = usedRoots == null || !files.removeAll(usedRoots);
|
||||
if (allRootsUnused) {
|
||||
String message = InspectionsBundle.message("unused.library.problem.descriptor", entry.getPresentableName());
|
||||
result.add(manager.createProblemDescriptor(message, module, new RemoveUnusedLibrary(entry.getPresentableName(), null)));
|
||||
}
|
||||
else if (!files.isEmpty() && !IGNORE_LIBRARY_PARTS) {
|
||||
final String unusedLibraryRoots = StringUtil.join(files, file -> file.getPresentableName(), ",");
|
||||
String message =
|
||||
InspectionsBundle.message("unused.library.roots.problem.descriptor", unusedLibraryRoots, entry.getPresentableName());
|
||||
CommonProblemDescriptor descriptor =
|
||||
((LibraryOrderEntry)entry).isModuleLevel()
|
||||
? manager.createProblemDescriptor(message, module, new RemoveUnusedLibrary(entry.getPresentableName(), files))
|
||||
: manager.createProblemDescriptor(message);
|
||||
result.add(descriptor);
|
||||
@Override
|
||||
public void runInspection(@NotNull AnalysisScope scope,
|
||||
@NotNull InspectionManager manager,
|
||||
@NotNull GlobalInspectionContext globalContext,
|
||||
@NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
|
||||
RefManager refManager = globalContext.getRefManager();
|
||||
for (Module module : ModuleManager.getInstance(globalContext.getProject()).getModules()) {
|
||||
if (scope.containsModule(module)) {
|
||||
RefModule refModule = refManager.getRefModule(module);
|
||||
if (refModule != null) {
|
||||
CommonProblemDescriptor[] descriptors = getDescriptors(manager, refModule, module);
|
||||
if (descriptors != null) {
|
||||
problemDescriptionsProcessor.addProblemElement(refModule, descriptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.isEmpty() ? null : result.toArray(CommonProblemDescriptor.EMPTY_ARRAY);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CommonProblemDescriptor[] getDescriptors(@NotNull InspectionManager manager,
|
||||
RefModule refModule,
|
||||
Module module) {
|
||||
VirtualFile[] givenRoots =
|
||||
OrderEnumerator.orderEntries(module).withoutSdk()
|
||||
.withoutModuleSourceEntries()
|
||||
.withoutDepModules()
|
||||
.classes()
|
||||
.getRoots();
|
||||
|
||||
if (givenRoots.length == 0) return null;
|
||||
|
||||
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
|
||||
final Set<VirtualFile> usedRoots = refModule.getUserData(UnusedLibraryGraphAnnotator.USED_LIBRARY_ROOTS);
|
||||
|
||||
if (usedRoots != null) {
|
||||
appendUsedRootDependencies(usedRoots, givenRoots);
|
||||
}
|
||||
|
||||
final List<CommonProblemDescriptor> result = new ArrayList<>();
|
||||
for (OrderEntry entry : moduleRootManager.getOrderEntries()) {
|
||||
if (entry instanceof LibraryOrderEntry &&
|
||||
!((LibraryOrderEntry)entry).isExported() &&
|
||||
((LibraryOrderEntry)entry).getScope() != DependencyScope.RUNTIME) {
|
||||
final Set<VirtualFile> files = ContainerUtil.set(((LibraryOrderEntry)entry).getRootFiles(OrderRootType.CLASSES));
|
||||
boolean allRootsUnused = usedRoots == null || !files.removeAll(usedRoots);
|
||||
if (allRootsUnused) {
|
||||
String message = InspectionsBundle.message("unused.library.problem.descriptor", entry.getPresentableName());
|
||||
result.add(manager.createProblemDescriptor(message, module, new RemoveUnusedLibrary(entry.getPresentableName(), null)));
|
||||
}
|
||||
else if (!files.isEmpty() && !IGNORE_LIBRARY_PARTS) {
|
||||
final String unusedLibraryRoots = StringUtil.join(files, file -> file.getPresentableName(), ",");
|
||||
String message =
|
||||
InspectionsBundle.message("unused.library.roots.problem.descriptor", unusedLibraryRoots, entry.getPresentableName());
|
||||
CommonProblemDescriptor descriptor =
|
||||
((LibraryOrderEntry)entry).isModuleLevel()
|
||||
? manager.createProblemDescriptor(message, module, new RemoveUnusedLibrary(entry.getPresentableName(), files))
|
||||
: manager.createProblemDescriptor(message);
|
||||
result.add(descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.isEmpty() ? null : result.toArray(CommonProblemDescriptor.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
private static void appendUsedRootDependencies(@NotNull Set<VirtualFile> usedRoots,
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.intellij.codeInspection.ex.EntryPointsManager;
|
||||
import com.intellij.codeInspection.ex.EntryPointsManagerBase;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -501,7 +502,7 @@ public final class VisibilityInspection extends GlobalJavaBatchInspectionTool {
|
||||
final EntryPointsManager entryPointsManager = globalContext.getEntryPointsManager(manager);
|
||||
for (RefElement entryPoint : entryPointsManager.getEntryPoints(manager)) {
|
||||
//don't ignore entry points with explicit visibility requirements
|
||||
if (entryPoint instanceof RefJavaElement && getMinVisibilityLevel((RefJavaElement)entryPoint) > 0) {
|
||||
if (entryPoint instanceof RefJavaElement && ReadAction.compute(() -> getMinVisibilityLevel((RefJavaElement)entryPoint)) > 0) {
|
||||
continue;
|
||||
}
|
||||
ignoreElement(processor, entryPoint);
|
||||
|
||||
Reference in New Issue
Block a user