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()));
}
}
}
use of com.intellij.psi.PsiManager in project intellij-community by JetBrains.
the class PsiFileReferenceHelper method getContextsForModule.
static Collection<PsiFileSystemItem> getContextsForModule(@NotNull Module module, @NotNull String packageName, @Nullable GlobalSearchScope scope) {
List<PsiFileSystemItem> result = null;
Query<VirtualFile> query = DirectoryIndex.getInstance(module.getProject()).getDirectoriesByPackageName(packageName, false);
PsiManager manager = null;
for (VirtualFile file : query) {
if (scope != null && !scope.contains(file))
continue;
if (result == null) {
result = new ArrayList<>();
manager = PsiManager.getInstance(module.getProject());
}
PsiDirectory psiDirectory = manager.findDirectory(file);
if (psiDirectory != null)
result.add(psiDirectory);
}
return result != null ? result : Collections.<PsiFileSystemItem>emptyList();
}
Aggregations