diff --git a/project_model/META-INF/plugin.xml b/project_model/META-INF/plugin.xml index 79b2d2a00..4f8fa8ffa 100644 --- a/project_model/META-INF/plugin.xml +++ b/project_model/META-INF/plugin.xml @@ -1,45 +1,55 @@ - org.jetbrains.plugins.sample.ProjectModel - Editor basics - 1.0 - JetBrains + org.jetbrains.plugins.sample.ProjectModel + Editor basics + 1.0 + JetBrains - Project model illustration + Project model illustration - Initial commit + Initial commit - - - com.intellij.modules.lang + + + com.intellij.modules.lang - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project_model/src/com/intellij/plugins/project/model/LibrariesAction.java b/project_model/src/com/intellij/plugins/project/model/LibrariesAction.java new file mode 100644 index 000000000..85caba27f --- /dev/null +++ b/project_model/src/com/intellij/plugins/project/model/LibrariesAction.java @@ -0,0 +1,62 @@ +package com.intellij.plugins.project.model; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.*; +import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.pom.Navigatable; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiFile; + +/** + * @author Anna Bulenkova + */ +public class LibrariesAction extends AnAction { + @Override + public void update(final AnActionEvent event) { + Project project = event.getProject(); + if (project == null) return; + Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); + if (element instanceof PsiClass) { + PsiFile psiFile = ((PsiClass) element).getContainingFile(); + if (psiFile == null) return; + VirtualFile virtualFile = psiFile.getVirtualFile(); + if (virtualFile == null) return; + event.getPresentation().setEnabledAndVisible(true); + } + } + + @Override + public void actionPerformed(AnActionEvent event) { + Project project = event.getProject(); + if (project == null) return; + Navigatable element = event.getData(CommonDataKeys.NAVIGATABLE); + if (element instanceof PsiClass) { + PsiFile psiFile = ((PsiClass) element).getContainingFile(); + if (psiFile == null) return; + VirtualFile virtualFile = psiFile.getVirtualFile(); + if (virtualFile == null) return; + final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); + StringBuilder jars = new StringBuilder(); + for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) { + if (orderEntry instanceof LibraryOrderEntry) { + final LibraryOrderEntry libraryEntry = (LibraryOrderEntry) orderEntry; + final Library library = libraryEntry.getLibrary(); + if (library == null) continue; + VirtualFile[] files = library.getFiles(OrderRootType.CLASSES); + if (files.length == 0) continue; + for (VirtualFile jar : files) { + jars.append(jar.getName()).append(", "); + } + } + } + if (jars.length() > 0) { + Messages.showInfoMessage("Libraries for file " + virtualFile.getName() + ": " + jars.toString(), "Libraries Info"); + } + } + } +}