Search in sources :

Example 16 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.

the class PsiDirectoryNode method navigate.

@Override
public void navigate(final boolean requestFocus) {
    Module module = ModuleUtil.findModuleForPsiElement(getValue());
    if (module != null) {
        final VirtualFile file = getVirtualFile();
        final Project project = getProject();
        ProjectSettingsService service = ProjectSettingsService.getInstance(myProject);
        if (ProjectRootsUtil.isModuleContentRoot(file, project)) {
            service.openModuleSettings(module);
        } else if (ProjectRootsUtil.isLibraryRoot(file, project)) {
            final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(file, module.getProject());
            if (orderEntry != null) {
                service.openLibraryOrSdkSettings(orderEntry);
            }
        } else {
            service.openContentEntriesSettings(module);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectSettingsService(com.intellij.openapi.roots.ui.configuration.ProjectSettingsService) Module(com.intellij.openapi.module.Module)

Example 17 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.

the class DvcsUtil method getVcsRootForLibraryFile.

@Nullable
private static VirtualFile getVcsRootForLibraryFile(@NotNull Project project, @NotNull VirtualFile file) {
    ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
    // for a file inside .jar/.zip consider the .jar/.zip file itself
    VirtualFile root = vcsManager.getVcsRootFor(VfsUtilCore.getVirtualFileForJar(file));
    if (root != null) {
        LOGGER.debug("Found root for zip/jar file: " + root);
        return root;
    }
    // for other libs which don't have jars inside the project dir (such as JDK) take the owner module of the lib
    List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
    Set<VirtualFile> libraryRoots = new HashSet<>();
    for (OrderEntry entry : entries) {
        if (entry instanceof LibraryOrderEntry || entry instanceof JdkOrderEntry) {
            VirtualFile moduleRoot = vcsManager.getVcsRootFor(entry.getOwnerModule().getModuleFile());
            if (moduleRoot != null) {
                libraryRoots.add(moduleRoot);
            }
        }
    }
    if (libraryRoots.size() == 0) {
        LOGGER.debug("No library roots");
        return null;
    }
    // if the lib is used in several modules, take the top module
    // (for modules of the same level we can't guess anything => take the first one)
    Iterator<VirtualFile> libIterator = libraryRoots.iterator();
    VirtualFile topLibraryRoot = libIterator.next();
    while (libIterator.hasNext()) {
        VirtualFile libRoot = libIterator.next();
        if (VfsUtilCore.isAncestor(libRoot, topLibraryRoot, true)) {
            topLibraryRoot = libRoot;
        }
    }
    LOGGER.debug("Several library roots, returning " + topLibraryRoot);
    return topLibraryRoot;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project kotlin by JetBrains.

the class ExternalSystemImportingTestCase method getModuleDep.

@NotNull
private <T> List<T> getModuleDep(@NotNull String moduleName, @NotNull String depName, @NotNull Class<T> clazz) {
    List<T> deps = ContainerUtil.newArrayList();
    for (OrderEntry e : getRootManager(moduleName).getOrderEntries()) {
        if (clazz.isInstance(e) && e.getPresentableName().equals(depName)) {
            deps.add((T) e);
        }
    }
    assertTrue("Dependency '" + depName + "' for module '" + moduleName + "' not found among: " + collectModuleDepsNames(moduleName, clazz), !deps.isEmpty());
    return deps;
}
Also used : ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project intellij-plugins by JetBrains.

the class SwfProjectViewStructureProvider method findDecompiledElement.

@Nullable
private static PsiElement findDecompiledElement(JSQualifiedNamedElement element) {
    if (DumbService.isDumb(element.getProject())) {
        return null;
    }
    JSQualifiedNamedElement mainElement = JSUtils.getMemberContainingClass(element);
    if (mainElement == null) {
        mainElement = element;
    }
    final String qName = mainElement.getQualifiedName();
    if (qName == null) {
        return null;
    }
    VirtualFile elementVFile = mainElement.getContainingFile().getVirtualFile();
    if (elementVFile == null) {
        return null;
    }
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(mainElement.getProject()).getFileIndex();
    GlobalSearchScope searchScope = JSResolveUtil.getResolveScope(mainElement);
    Collection<JSQualifiedNamedElement> candidates = StubIndex.getElements(JSQualifiedElementIndex.KEY, qName.hashCode(), mainElement.getProject(), searchScope, JSQualifiedNamedElement.class);
    List<OrderEntry> sourceFileEntries = projectFileIndex.getOrderEntriesForFile(elementVFile);
    for (JSQualifiedNamedElement candidate : candidates) {
        if (candidate == mainElement || !qName.equals(candidate.getQualifiedName())) {
            continue;
        }
        VirtualFile vFile = candidate.getContainingFile().getVirtualFile();
        if (vFile != null && projectFileIndex.getClassRootForFile(vFile) != null) {
            List<OrderEntry> candidateEntries = projectFileIndex.getOrderEntriesForFile(vFile);
            if (ContainerUtil.intersects(sourceFileEntries, candidateEntries)) {
                if (element == mainElement) {
                    return candidate;
                } else {
                    LOG.assertTrue(candidate instanceof JSClass, candidate);
                    if (element instanceof JSVariable) {
                        return ((JSClass) candidate).findFieldByName(element.getName());
                    } else {
                        LOG.assertTrue(element instanceof JSFunction, element);
                        return ((JSClass) candidate).findFunctionByNameAndKind(element.getName(), ((JSFunction) element).getKind());
                    }
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with OrderEntry

use of com.intellij.openapi.roots.OrderEntry in project kotlin by JetBrains.

the class SourceNavigationHelper method getOriginalClass.

@Nullable
public static PsiClass getOriginalClass(@NotNull KtClassOrObject classOrObject) {
    // Copied from JavaPsiImplementationHelperImpl:getOriginalClass()
    FqName fqName = classOrObject.getFqName();
    if (fqName == null) {
        return null;
    }
    KtFile file = classOrObject.getContainingKtFile();
    VirtualFile vFile = file.getVirtualFile();
    Project project = file.getProject();
    final ProjectFileIndex idx = ProjectRootManager.getInstance(project).getFileIndex();
    if (vFile == null || !idx.isInLibrarySource(vFile))
        return null;
    final Set<OrderEntry> orderEntries = new THashSet<OrderEntry>(idx.getOrderEntriesForFile(vFile));
    return JavaPsiFacade.getInstance(project).findClass(fqName.asString(), new GlobalSearchScope(project) {

        @Override
        public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
            return 0;
        }

        @Override
        public boolean contains(@NotNull VirtualFile file) {
            List<OrderEntry> entries = idx.getOrderEntriesForFile(file);
            for (OrderEntry entry : entries) {
                if (orderEntries.contains(entry))
                    return true;
            }
            return false;
        }

        @Override
        public boolean isSearchInModuleContent(@NotNull Module aModule) {
            return false;
        }

        @Override
        public boolean isSearchInLibraries() {
            return true;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FqName(org.jetbrains.kotlin.name.FqName) List(java.util.List) Module(com.intellij.openapi.module.Module) THashSet(gnu.trove.THashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

OrderEntry (com.intellij.openapi.roots.OrderEntry)54 Module (com.intellij.openapi.module.Module)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)18 Project (com.intellij.openapi.project.Project)14 Library (com.intellij.openapi.roots.libraries.Library)12 ArrayList (java.util.ArrayList)11 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)10 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)10 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)8 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)8 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 ModuleLibraryOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)5 List (java.util.List)5 Sdk (com.intellij.openapi.projectRoots.Sdk)4 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)4 AccessToken (com.intellij.openapi.application.AccessToken)3 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)3 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3