Search in sources :

Example 56 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by JetBrains.

the class FileReferenceSetHelper method addWebDirectoryAndCurrentNamespaceAsRoots.

/**
   * Adds all {@link WebDirectoryElement}s as well as web-directory with name of given current namespace
   * (if not "root" namespace) as possible content roots.
   *
   * @param psiElement Current element.
   * @param namespace  Current namespace.
   * @param webFacet   Module.
   * @param set        FRS to patch.
   */
public static void addWebDirectoryAndCurrentNamespaceAsRoots(final PsiElement psiElement, final String namespace, final WebFacet webFacet, final FileReferenceSet set) {
    final WebDirectoryUtil directoryUtil = WebDirectoryUtil.getWebDirectoryUtil(psiElement.getProject());
    set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, file -> {
        final List<PsiFileSystemItem> basePathRoots = new ArrayList<>();
        final List<WebRoot> webRoots = webFacet.getWebRoots(true);
        for (final WebRoot webRoot : webRoots) {
            final String webRootPath = webRoot.getRelativePath();
            final WebDirectoryElement webRootBase = directoryUtil.findWebDirectoryElementByPath(webRootPath, webFacet);
            ContainerUtil.addIfNotNull(basePathRoots, webRootBase);
        }
        if (!Comparing.equal(namespace, StrutsPackage.DEFAULT_NAMESPACE)) {
            final WebDirectoryElement packageBase = directoryUtil.findWebDirectoryElementByPath(namespace, webFacet);
            ContainerUtil.addIfNotNull(basePathRoots, packageBase);
        }
        return basePathRoots;
    });
}
Also used : WebRoot(com.intellij.javaee.web.WebRoot) WebDirectoryUtil(com.intellij.psi.impl.source.jsp.WebDirectoryUtil) ArrayList(java.util.ArrayList) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) WebDirectoryElement(com.intellij.psi.jsp.WebDirectoryElement)

Example 57 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by JetBrains.

the class SendToMayaAction method getPythonFile.

@Nullable
private static PyFile getPythonFile(AnActionEvent e) {
    VirtualFile vFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    if (project != null && vFile != null) {
        final PsiManager psiManager = PsiManager.getInstance(project);
        PsiFileSystemItem fsItem = vFile.isDirectory() ? psiManager.findDirectory(vFile) : psiManager.findFile(vFile);
        if (fsItem instanceof PyFile) {
            return (PyFile) fsItem;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiManager(com.intellij.psi.PsiManager) PyFile(com.jetbrains.python.psi.PyFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Nullable(org.jetbrains.annotations.Nullable)

Example 58 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by JetBrains.

the class KarmaRunConfigurationProducer method setup.

@Nullable
private static Pair<KarmaRunSettings, PsiElement> setup(@Nullable PsiElement element, @NotNull KarmaRunSettings templateSettings) {
    JSFile file = ObjectUtils.tryCast(element != null ? element.getContainingFile() : null, JSFile.class);
    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
    if (virtualFile == null) {
        return null;
    }
    if (!(element instanceof PsiFileSystemItem)) {
        Pair<KarmaRunSettings, PsiElement> suiteOrTestConfiguration = setupAsSuiteOrTest(file, virtualFile, element, templateSettings);
        if (suiteOrTestConfiguration != null) {
            return suiteOrTestConfiguration;
        }
    }
    if (KarmaUtil.isKarmaConfigFile(virtualFile.getNameSequence(), false)) {
        return Pair.create(templateSettings.toBuilder().setScopeKind(KarmaScopeKind.ALL).setConfigPath(virtualFile.getPath()).build(), file);
    }
    if (file.getTestFileType() != null) {
        KarmaRunSettings settings = guessConfigFileIfNeeded(templateSettings, virtualFile, element.getProject());
        return Pair.create(settings.toBuilder().setScopeKind(KarmaScopeKind.TEST_FILE).setTestFilePath(virtualFile.getPath()).build(), file);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSFile(com.intellij.lang.javascript.psi.JSFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 59 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by StepicOrg.

the class ProjectPsiFilesUtils method isNotMovableOrRenameElement.

public static boolean isNotMovableOrRenameElement(@NotNull PsiElement element, @NotNull Set<Class<? extends PsiElement>> acceptableClasses) {
    Project project = element.getProject();
    StudyNode root = StepikProjectManager.getProjectRoot(project);
    if (root == null) {
        return false;
    }
    if (notAccept(element, acceptableClasses)) {
        return false;
    }
    PsiFileSystemItem file = getFile(element);
    if (file == null) {
        return false;
    }
    String path = getRelativePath(file);
    return ProjectFilesUtils.isNotMovableOrRenameElement(root, path);
}
Also used : Project(com.intellij.openapi.project.Project) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 60 with PsiFileSystemItem

use of com.intellij.psi.PsiFileSystemItem in project intellij-plugins by StepicOrg.

the class ProjectPsiFilesUtils method isCanNotBeTarget.

public static boolean isCanNotBeTarget(@Nullable PsiElement target, @NotNull Set<Class<? extends PsiElement>> acceptableClasses) {
    if (target == null) {
        return false;
    }
    Project project = target.getProject();
    if (!StepikProjectManager.isStepikProject(project)) {
        return false;
    }
    if (notAccept(target, acceptableClasses)) {
        return false;
    }
    PsiFileSystemItem item = getFile(target);
    if (item == null) {
        return false;
    }
    String targetPath = getRelativePath(item);
    return ProjectFilesUtils.isCanNotBeTarget(targetPath);
}
Also used : Project(com.intellij.openapi.project.Project) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

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