use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class UnnecessaryModuleDependencyInspection method checkElement.
@Override
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull final GlobalInspectionContext globalContext) {
if (refEntity instanceof RefModule) {
final RefModule refModule = (RefModule) refEntity;
final Module module = refModule.getModule();
if (module.isDisposed() || !scope.containsModule(module))
return CommonProblemDescriptor.EMPTY_ARRAY;
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
final OrderEntry[] declaredDependencies = moduleRootManager.getOrderEntries();
final Module[] declaredModuleDependencies = moduleRootManager.getDependencies();
List<CommonProblemDescriptor> descriptors = new ArrayList<>();
final Set<Module> modules = refModule.getUserData(UnnecessaryModuleDependencyAnnotator.DEPENDENCIES);
Graph<Module> graph = myGraph.get();
if (graph == null) {
graph = ModuleManager.getInstance(globalContext.getProject()).moduleGraph();
myGraph = new SoftReference<>(graph);
}
final RefManager refManager = globalContext.getRefManager();
for (final OrderEntry entry : declaredDependencies) {
if (entry instanceof ModuleOrderEntry) {
final Module dependency = ((ModuleOrderEntry) entry).getModule();
if (dependency != null) {
if (modules == null || !modules.contains(dependency)) {
List<String> dependenciesThroughExported = null;
if (((ModuleOrderEntry) entry).isExported()) {
final Iterator<Module> iterator = graph.getOut(module);
while (iterator.hasNext()) {
final Module dep = iterator.next();
final RefModule depRefModule = refManager.getRefModule(dep);
if (depRefModule != null) {
final Set<Module> neededModules = depRefModule.getUserData(UnnecessaryModuleDependencyAnnotator.DEPENDENCIES);
if (neededModules != null && neededModules.contains(dependency)) {
if (dependenciesThroughExported == null) {
dependenciesThroughExported = new ArrayList<>();
}
dependenciesThroughExported.add(dep.getName());
}
}
}
}
if (modules != null) {
List<String> transitiveDependencies = new ArrayList<>();
final OrderEntry[] dependenciesOfDependencies = ModuleRootManager.getInstance(dependency).getOrderEntries();
for (OrderEntry secondDependency : dependenciesOfDependencies) {
if (secondDependency instanceof ModuleOrderEntry && ((ModuleOrderEntry) secondDependency).isExported()) {
final Module mod = ((ModuleOrderEntry) secondDependency).getModule();
if (mod != null && modules.contains(mod) && ArrayUtil.find(declaredModuleDependencies, mod) < 0) {
transitiveDependencies.add(mod.getName());
}
}
}
if (!transitiveDependencies.isEmpty()) {
final String exported = StringUtil.join(transitiveDependencies, ", ");
descriptors.add(manager.createProblemDescriptor(InspectionsBundle.message("unnecessary.module.dependency.exported.problem.descriptor1", module.getName(), dependency.getName(), exported)));
continue;
}
}
descriptors.add(createDescriptor(scope, manager, module, dependency, dependenciesThroughExported));
}
}
}
}
return descriptors.isEmpty() ? null : descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
}
return null;
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class MavenProjectImporter method removeUnusedProjectLibraries.
private boolean removeUnusedProjectLibraries() {
Set<Library> unusedLibraries = new HashSet<>();
Collections.addAll(unusedLibraries, myModelsProvider.getAllLibraries());
for (ModuleRootModel eachModel : collectModuleModels()) {
for (OrderEntry eachEntry : eachModel.getOrderEntries()) {
if (eachEntry instanceof LibraryOrderEntry) {
unusedLibraries.remove(((LibraryOrderEntry) eachEntry).getLibrary());
}
}
}
boolean removed = false;
for (Library each : unusedLibraries) {
if (!isDisposed(each) && MavenRootModelAdapter.isMavenLibrary(each) && !MavenRootModelAdapter.isChangedByUser(each)) {
myModelsProvider.removeLibrary(each);
removed = true;
}
}
return removed;
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class MvcUpgradeAction method removeOldMvcSdk.
public static void removeOldMvcSdk(MvcFramework framework, ModifiableRootModel model) {
final LibraryPresentationManager presentationManager = LibraryPresentationManager.getInstance();
for (OrderEntry entry : model.getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
final Library library = ((LibraryOrderEntry) entry).getLibrary();
final LibrariesContainer container = LibrariesContainerFactory.createContainer(model);
if (library != null) {
final VirtualFile[] files = container.getLibraryFiles(library, OrderRootType.CLASSES);
if (presentationManager.isLibraryOfKind(Arrays.asList(files), framework.getLibraryKind())) {
model.removeOrderEntry(entry);
}
}
}
}
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class MavenAttachSourcesProvider method getMavenProjects.
private static Collection<MavenProject> getMavenProjects(PsiFile psiFile) {
Project project = psiFile.getProject();
Collection<MavenProject> result = new ArrayList<>();
for (OrderEntry each : ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(psiFile.getVirtualFile())) {
MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(each.getOwnerModule());
if (mavenProject != null)
result.add(mavenProject);
}
return result;
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class PsiFileNode method navigate.
@Override
public void navigate(boolean requestFocus) {
final VirtualFile jarRoot = getJarRoot();
final Project project = getProject();
if (requestFocus && jarRoot != null && project != null && ProjectRootsUtil.isLibraryRoot(jarRoot, project)) {
final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(jarRoot, project);
if (orderEntry != null) {
ProjectSettingsService.getInstance(project).openLibraryOrSdkSettings(orderEntry);
return;
}
}
super.navigate(requestFocus);
}
Aggregations