@Override public Module getModule() { if (!isValid()) return null; VirtualFile virtualFile = getFile(); if (virtualFile == null) return null; ProjectRootManager projectRootManager = ProjectRootManager.getInstance(getProject()); ProjectFileIndex fileIndex = projectRootManager.getFileIndex(); return fileIndex.getModuleForFile(virtualFile); }
@Override public OrderEntry getLibraryEntry() { if (!isValid()) return null; PsiFile psiFile = getPsiFile(); VirtualFile virtualFile = getFile(); if (virtualFile == null) return null; ProjectRootManager projectRootManager = ProjectRootManager.getInstance(getProject()); ProjectFileIndex fileIndex = projectRootManager.getFileIndex(); if (psiFile instanceof PsiCompiledElement || fileIndex.isInLibrarySource(virtualFile)) { List<OrderEntry> orders = fileIndex.getOrderEntriesForFile(virtualFile); for (OrderEntry order : orders) { if (order instanceof LibraryOrderEntry || order instanceof JdkOrderEntry) { return order; } } } return null; }