Search in sources :

Example 1 with PsiFileSystemItem

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiElement(com.intellij.psi.PsiElement) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiFileSystemItem

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;
}
Also used : PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 3 with PsiFileSystemItem

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();
}
Also used : MoveHandlerDelegate(com.intellij.refactoring.move.MoveHandlerDelegate) Arrays(java.util.Arrays) ProjectPsiFilesUtils.isNotMovableOrRenameElement(org.stepik.plugin.utils.ProjectPsiFilesUtils.isNotMovableOrRenameElement) MoveCallback(com.intellij.refactoring.move.MoveCallback) MessagesEx(com.intellij.openapi.ui.ex.MessagesEx) Set(java.util.Set) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils.isCanNotBeTarget(org.stepik.plugin.utils.ProjectPsiFilesUtils.isCanNotBeTarget) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils)

Example 4 with PsiFileSystemItem

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);
    }
}
Also used : PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Example 5 with PsiFileSystemItem

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)60 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 Nullable (org.jetbrains.annotations.Nullable)20 PsiElement (com.intellij.psi.PsiElement)18 PsiFile (com.intellij.psi.PsiFile)18 Project (com.intellij.openapi.project.Project)14 PsiDirectory (com.intellij.psi.PsiDirectory)14 NotNull (org.jetbrains.annotations.NotNull)8 Module (com.intellij.openapi.module.Module)7 File (java.io.File)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 ArrayList (java.util.ArrayList)5 PsiManager (com.intellij.psi.PsiManager)4 IProperty (com.intellij.lang.properties.IProperty)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 SearchScope (com.intellij.psi.search.SearchScope)2 QualifiedName (com.intellij.psi.util.QualifiedName)2 XmlFile (com.intellij.psi.xml.XmlFile)2