use of com.intellij.psi.PsiFileSystemItem in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRunUtil method getContextElement.
@Nullable
public static PsiElement getContextElement(@Nullable ConfigurationContext context) {
if (context == null) {
return null;
}
PsiElement psiElement = context.getPsiLocation();
if (psiElement == null || !psiElement.isValid()) {
return null;
}
FileIndexFacade indexFacade = FileIndexFacade.getInstance(psiElement.getProject());
PsiFileSystemItem psiFile = psiElement instanceof PsiFileSystemItem ? (PsiFileSystemItem) psiElement : psiElement.getContainingFile();
VirtualFile file = psiFile != null ? psiFile.getVirtualFile() : null;
if (file != null && file.getFileType() != ScratchFileType.INSTANCE && (!indexFacade.isInContent(file) || indexFacade.isExcludedFile(file))) {
return null;
}
return psiElement;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by StepicOrg.
the class StepikTreeStructureProvider method isHidden.
private boolean isHidden(@NotNull Project project, @Nullable Object value) {
if (StepikProjectManager.isAdaptive(project)) {
if (!(value instanceof PsiFileSystemItem)) {
return false;
}
String relativePath = getRelativePath((PsiFileSystemItem) value);
StudyNode root = StepikProjectManager.getProjectRoot(project);
if (root == null) {
return false;
}
StudyNode node = StudyUtils.getStudyNode(root, relativePath);
if (node == null) {
return false;
}
StudyNode<?, ?> selected = StepikProjectManager.getSelected(project);
if (selected == null) {
return true;
}
String selectedPath = selected.getPath();
String nodePath = node.getPath();
if (!selectedPath.startsWith(nodePath) && selected.getParent() != node.getParent()) {
return true;
}
}
return false;
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by StepicOrg.
the class AbstractMoveHandlerDelegate method doMove.
@Override
public void doMove(Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
List<PsiFileSystemItem> sources = Arrays.stream(elements).filter(psiElement -> isNotMovableOrRenameElement(psiElement, acceptableClasses)).map(ProjectPsiFilesUtils::getFile).filter(Objects::nonNull).collect(Collectors.toList());
StringBuilder message = new StringBuilder();
if (sources.size() > 1) {
message.append("You can not move the following elements:");
} else {
PsiFileSystemItem source = sources.get(0);
message.append("You can not move the ").append(source.isDirectory() ? "directory" : "file").append(":");
}
for (PsiFileSystemItem file : sources) {
message.append("\n").append(file.getVirtualFile().getPath());
}
MessagesEx.error(project, message.toString(), "Move").showNow();
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by StepicOrg.
the class NavigationUtils method updateProjectView.
private static void updateProjectView(@NotNull Project project, @NotNull VirtualFile shouldBeActive) {
PsiFileSystemItem file;
if (shouldBeActive.isDirectory()) {
file = PsiManager.getInstance(project).findDirectory(shouldBeActive);
} else {
file = PsiManager.getInstance(project).findFile(shouldBeActive);
FileEditorManager.getInstance(project).openFile(shouldBeActive, false);
if (file != null) {
file = file.getParent();
}
}
if (file != null) {
if (file.canNavigate()) {
file.navigate(true);
}
collapseNonSelected(file);
}
}
use of com.intellij.psi.PsiFileSystemItem in project intellij-community by JetBrains.
the class HtmlFileReferenceHelper method getContexts.
@NotNull
@Override
public Collection<PsiFileSystemItem> getContexts(Project project, @NotNull VirtualFile vFile) {
final PsiFile file = PsiManager.getInstance(project).findFile(vFile);
final Module module = file != null ? ModuleUtilCore.findModuleForPsiElement(file) : null;
if (module == null || !(file instanceof XmlFile))
return Collections.emptyList();
final String basePath = HtmlUtil.getHrefBase((XmlFile) file);
if (basePath != null && !HtmlUtil.hasHtmlPrefix(basePath)) {
for (VirtualFile virtualFile : getBaseRoots(module)) {
final VirtualFile base = virtualFile.findFileByRelativePath(basePath);
final PsiDirectory result = base != null ? PsiManager.getInstance(project).findDirectory(base) : null;
if (result != null) {
return Collections.<PsiFileSystemItem>singletonList(result);
}
}
}
return Collections.emptyList();
}
Aggregations