Search in sources :

Example 1 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project folding-plugin by dmytrodanylyk.

the class ProjectStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings viewSettings) {
    List<AbstractTreeNode> resultList = new ArrayList<>();
    if (parent.getValue() instanceof PsiDirectory) {
        PsiDirectory directory = (PsiDirectory) parent.getValue();
        String path = directory.getVirtualFile().getPath();
        if (SettingsManager.isComposed(path)) {
            resultList.addAll(createComposedFiles(children, viewSettings));
        } else {
            resultList.addAll(children);
        }
    } else {
        resultList.addAll(children);
    }
    return resultList;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project folding-plugin by dmytrodanylyk.

the class ComposeAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent actionEvent) {
    Object nav = actionEvent.getData(CommonDataKeys.NAVIGATABLE);
    if (nav instanceof PsiDirectory) {
        PsiDirectory directory = (PsiDirectory) nav;
        String path = directory.getVirtualFile().getPath();
        if (SettingsManager.isComposed(path)) {
            SettingsManager.removeComposedFolder(path);
        } else {
            SettingsManager.addComposedFolder(path);
        }
        Project project = actionEvent.getData(CommonDataKeys.PROJECT);
        if (project != null) {
            ProjectView.getInstance(project).refresh();
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory)

Example 3 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project buck by facebook.

the class BuckCopyPasteProcessor method referenceNameToBuckFile.

private VirtualFile referenceNameToBuckFile(Project project, String reference) {
    // First test if it is a absolute path of a file.
    File tryFile = new File(reference);
    if (tryFile != null) {
        VirtualFile file = VfsUtil.findFileByIoFile(tryFile, true);
        if (file != null) {
            return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
        }
    }
    // Try class firstly.
    PsiClass classElement = JavaPsiFacade.getInstance(project).findClass(reference, GlobalSearchScope.allScope(project));
    if (classElement != null) {
        VirtualFile file = PsiUtilCore.getVirtualFile(classElement);
        return BuckBuildUtil.getBuckFileFromDirectory(file.getParent());
    }
    // Then try package.
    PsiPackage packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
    if (packageElement != null) {
        PsiDirectory directory = packageElement.getDirectories()[0];
        return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
    }
    // Extract the package from the reference.
    int index = reference.lastIndexOf(".");
    if (index == -1) {
        return null;
    }
    reference = reference.substring(0, index);
    // Try to find the package again.
    packageElement = JavaPsiFacade.getInstance(project).findPackage(reference);
    if (packageElement != null) {
        PsiDirectory directory = packageElement.getDirectories()[0];
        return BuckBuildUtil.getBuckFileFromDirectory(directory.getVirtualFile());
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) BuckFile(com.facebook.buck.intellij.ideabuck.lang.BuckFile) File(java.io.File)

Example 4 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoTestRunConfigurationProducerTest method testSameConfigurationOnDirectory.

public void testSameConfigurationOnDirectory() {
    PsiFile file = myFixture.configureByText("a.go", "package main");
    PsiDirectory directory = file.getParent();
    assertNotNull(directory);
    ConfigurationContext configurationContext = new ConfigurationContext(directory);
    GotestRunConfigurationProducer producer = new GotestRunConfigurationProducer();
    GoTestRunConfiguration runConfiguration = createDirectoryConfiguration(GotestFramework.INSTANCE, directory.getVirtualFile().getPath(), directory.getVirtualFile().getPath());
    assertTrue(producer.isConfigurationFromContext(runConfiguration, configurationContext));
    runConfiguration = createDirectoryConfiguration(GotestFramework.INSTANCE, directory.getVirtualFile().getPath() + "_vl", directory.getVirtualFile().getPath());
    assertFalse(producer.isConfigurationFromContext(runConfiguration, configurationContext));
    runConfiguration = createDirectoryConfiguration(GobenchFramework.INSTANCE, directory.getVirtualFile().getPath(), directory.getVirtualFile().getPath());
    assertFalse(producer.isConfigurationFromContext(runConfiguration, configurationContext));
    runConfiguration = createDirectoryConfiguration(GotestFramework.INSTANCE, directory.getVirtualFile().getPath(), directory.getVirtualFile().getPath() + "_vl");
    assertFalse(producer.isConfigurationFromContext(runConfiguration, configurationContext));
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) GotestRunConfigurationProducer(com.goide.runconfig.testing.frameworks.gotest.GotestRunConfigurationProducer)

Example 5 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRunConfigurationProducerTest method testSameRunApplicationConfigurationOnDirectory.

public void testSameRunApplicationConfigurationOnDirectory() {
    PsiFile file = myFixture.addFileToProject("import/path/a.go", "package main; func main(){}");
    PsiDirectory directory = file.getParent();
    assertNotNull(directory);
    ConfigurationContext configurationContext = new ConfigurationContext(directory);
    GoApplicationRunConfigurationProducer producer = new GoApplicationRunConfigurationProducer();
    GoApplicationConfiguration runConfiguration = createRunAppPackageConfiguration("import/path");
    assertTrue(producer.isConfigurationFromContext(runConfiguration, configurationContext));
    runConfiguration = createRunAppPackageConfiguration("import/path/other");
    assertFalse(producer.isConfigurationFromContext(runConfiguration, configurationContext));
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) GoApplicationRunConfigurationProducer(com.goide.runconfig.application.GoApplicationRunConfigurationProducer) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) GoApplicationConfiguration(com.goide.runconfig.application.GoApplicationConfiguration)

Aggregations

PsiDirectory (com.intellij.psi.PsiDirectory)321 VirtualFile (com.intellij.openapi.vfs.VirtualFile)122 PsiFile (com.intellij.psi.PsiFile)111 PsiElement (com.intellij.psi.PsiElement)79 Project (com.intellij.openapi.project.Project)73 Module (com.intellij.openapi.module.Module)68 Nullable (org.jetbrains.annotations.Nullable)62 NotNull (org.jetbrains.annotations.NotNull)50 IdeView (com.intellij.ide.IdeView)31 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)24 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)24 PsiManager (com.intellij.psi.PsiManager)24 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 ArrayList (java.util.ArrayList)20 PsiPackage (com.intellij.psi.PsiPackage)17 File (java.io.File)15 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)11 IncorrectOperationException (com.intellij.util.IncorrectOperationException)11 Course (com.jetbrains.edu.learning.courseFormat.Course)11 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)10