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);
}
}
}
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;
}
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;
}
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;
}
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;
}
});
}
Aggregations