use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class AddToFavoritesAction method createNodes.
@NotNull
public static Collection<AbstractTreeNode> createNodes(Project project, Module moduleContext, Object object, boolean inProjectView, ViewSettings favoritesConfig) {
if (project == null)
return Collections.emptyList();
ArrayList<AbstractTreeNode> result = new ArrayList<>();
for (FavoriteNodeProvider provider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, project)) {
final AbstractTreeNode treeNode = provider.createNode(project, object, favoritesConfig);
if (treeNode != null) {
result.add(treeNode);
return result;
}
}
final PsiManager psiManager = PsiManager.getInstance(project);
final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
AbstractProjectViewPane pane = ProjectView.getInstance(project).getProjectViewPaneById(currentViewId);
//on psi elements
if (object instanceof PsiElement[]) {
for (PsiElement psiElement : (PsiElement[]) object) {
addPsiElementNode(psiElement, project, result, favoritesConfig);
}
return result;
}
//on psi element
if (object instanceof PsiElement) {
Module containingModule = null;
if (inProjectView && ProjectView.getInstance(project).isShowModules(currentViewId)) {
if (pane != null && pane.getSelectedDescriptor() != null && pane.getSelectedDescriptor().getElement() instanceof AbstractTreeNode) {
AbstractTreeNode abstractTreeNode = ((AbstractTreeNode) pane.getSelectedDescriptor().getElement());
while (abstractTreeNode != null && !(abstractTreeNode.getParent() instanceof AbstractModuleNode)) {
abstractTreeNode = abstractTreeNode.getParent();
}
if (abstractTreeNode != null) {
containingModule = ((AbstractModuleNode) abstractTreeNode.getParent()).getValue();
}
}
}
addPsiElementNode((PsiElement) object, project, result, favoritesConfig);
return result;
}
if (object instanceof VirtualFile[]) {
for (VirtualFile vFile : (VirtualFile[]) object) {
PsiElement element = psiManager.findFile(vFile);
if (element == null)
element = psiManager.findDirectory(vFile);
addPsiElementNode(element, project, result, favoritesConfig);
}
return result;
}
//on form in editor
if (object instanceof VirtualFile) {
final VirtualFile vFile = (VirtualFile) object;
final PsiFile psiFile = psiManager.findFile(vFile);
addPsiElementNode(psiFile, project, result, favoritesConfig);
return result;
}
//on module groups
if (object instanceof ModuleGroup[]) {
for (ModuleGroup moduleGroup : (ModuleGroup[]) object) {
result.add(new ProjectViewModuleGroupNode(project, moduleGroup, favoritesConfig));
}
return result;
}
//on module nodes
if (object instanceof Module)
object = new Module[] { (Module) object };
if (object instanceof Module[]) {
for (Module module1 : (Module[]) object) {
result.add(new ProjectViewModuleNode(project, module1, favoritesConfig));
}
return result;
}
//on library group node
if (object instanceof LibraryGroupElement[]) {
for (LibraryGroupElement libraryGroup : (LibraryGroupElement[]) object) {
result.add(new LibraryGroupNode(project, libraryGroup, favoritesConfig));
}
return result;
}
//on named library node
if (object instanceof NamedLibraryElement[]) {
for (NamedLibraryElement namedLibrary : (NamedLibraryElement[]) object) {
result.add(new NamedLibraryElementNode(project, namedLibrary, favoritesConfig));
}
return result;
}
return result;
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class BookmarkItem method setupRenderer.
public static void setupRenderer(SimpleColoredComponent renderer, Project project, Bookmark bookmark, boolean selected) {
VirtualFile file = bookmark.getFile();
if (!file.isValid()) {
return;
}
PsiManager psiManager = PsiManager.getInstance(project);
PsiElement fileOrDir = file.isDirectory() ? psiManager.findDirectory(file) : psiManager.findFile(file);
if (fileOrDir != null) {
renderer.setIcon(fileOrDir.getIcon(0));
}
String description = bookmark.getDescription();
if (description != null) {
renderer.append(description + " ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
}
FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file);
TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null, null, EffectType.LINE_UNDERSCORE, Font.PLAIN);
renderer.append(file.getName(), SimpleTextAttributes.fromTextAttributes(attributes));
if (bookmark.getLine() >= 0) {
renderer.append(":", SimpleTextAttributes.GRAYED_ATTRIBUTES);
renderer.append(String.valueOf(bookmark.getLine() + 1), SimpleTextAttributes.GRAYED_ATTRIBUTES);
}
renderer.append(" (" + VfsUtilCore.getRelativeLocation(file, project.getBaseDir()) + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
if (!selected) {
FileColorManager colorManager = FileColorManager.getInstance(project);
if (fileOrDir instanceof PsiFile) {
Color color = colorManager.getRendererBackground((PsiFile) fileOrDir);
if (color != null) {
renderer.setBackground(color);
}
}
}
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class AddAllOpenFilesToFavorites method getFilesToAdd.
static ArrayList<PsiFile> getFilesToAdd(Project project) {
ArrayList<PsiFile> result = new ArrayList<>();
final FileEditorManager editorManager = FileEditorManager.getInstance(project);
final PsiManager psiManager = PsiManager.getInstance(project);
for (VirtualFile openFile : editorManager.getOpenFiles()) {
if (!openFile.isValid())
continue;
final PsiFile psiFile = psiManager.findFile(openFile);
if (psiFile != null) {
result.add(psiFile);
}
}
return result;
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class ProjectViewModuleNode method getChildren.
@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
Module module = getValue();
if (module == null || module.isDisposed()) {
// module has been disposed
return Collections.emptyList();
}
final List<VirtualFile> contentRoots = ProjectViewDirectoryHelper.getInstance(myProject).getTopLevelModuleRoots(module, getSettings());
final List<AbstractTreeNode> children = new ArrayList<>(contentRoots.size());
final PsiManager psiManager = PsiManager.getInstance(module.getProject());
for (final VirtualFile contentRoot : contentRoots) {
if (contentRoot.isDirectory()) {
PsiDirectory directory = psiManager.findDirectory(contentRoot);
if (directory != null) {
children.add(new PsiDirectoryNode(getProject(), directory, getSettings()));
}
} else {
PsiFile file = psiManager.findFile(contentRoot);
if (file != null) {
children.add(new PsiFileNode(getProject(), file, getSettings()));
}
}
}
return children;
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class LibraryGroupNode method addLibraryChildren.
public static void addLibraryChildren(final LibraryOrSdkOrderEntry entry, final List<AbstractTreeNode> children, Project project, ProjectViewNode node) {
final PsiManager psiManager = PsiManager.getInstance(project);
VirtualFile[] files = entry instanceof LibraryOrderEntry ? getLibraryRoots((LibraryOrderEntry) entry) : entry.getRootFiles(OrderRootType.CLASSES);
for (final VirtualFile file : files) {
if (!file.isValid())
continue;
if (file.isDirectory()) {
final PsiDirectory psiDir = psiManager.findDirectory(file);
if (psiDir == null) {
continue;
}
children.add(new PsiDirectoryNode(project, psiDir, node.getSettings()));
} else {
final PsiFile psiFile = psiManager.findFile(file);
if (psiFile == null)
continue;
children.add(new PsiFileNode(project, psiFile, node.getSettings()));
}
}
}
Aggregations