Search in sources :

Example 81 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class GeneratePluginClassAction method update.

public void update(final AnActionEvent e) {
    super.update(e);
    final Presentation presentation = e.getPresentation();
    if (presentation.isEnabled()) {
        final Project project = e.getProject();
        final Module module = e.getData(LangDataKeys.MODULE);
        if (project != null && module != null && PsiUtil.isPluginModule(module)) {
            final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
            if (view != null) {
                // from com.intellij.ide.actions.CreateClassAction.update()
                ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
                PsiDirectory[] dirs = view.getDirectories();
                for (PsiDirectory dir : dirs) {
                    if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
                        return;
                    }
                }
            }
        }
        presentation.setEnabledAndVisible(false);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Presentation(com.intellij.openapi.actionSystem.Presentation) Module(com.intellij.openapi.module.Module) IdeView(com.intellij.ide.IdeView)

Example 82 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class PsiDiffContentFactory method fromPsiElement.

@Nullable
private static DiffContent fromPsiElement(@NotNull PsiElement psiElement) {
    DiffContentFactory factory = DiffContentFactory.getInstance();
    if (psiElement instanceof PsiFile) {
        return factory.create(psiElement.getProject(), ((PsiFile) psiElement).getVirtualFile());
    } else if (psiElement instanceof PsiDirectory) {
        return factory.create(psiElement.getProject(), ((PsiDirectory) psiElement).getVirtualFile());
    }
    PsiFile containingFile = psiElement.getContainingFile();
    if (containingFile == null) {
        String text = psiElement.getText();
        if (text == null)
            return null;
        return factory.create(psiElement.getProject(), text, psiElement.getLanguage().getAssociatedFileType(), false);
    }
    DocumentContent wholeFileContent = factory.createDocument(psiElement.getProject(), containingFile.getVirtualFile());
    if (wholeFileContent == null)
        return null;
    return factory.createFragment(psiElement.getProject(), wholeFileContent, psiElement.getTextRange());
}
Also used : DiffContentFactory(com.intellij.diff.DiffContentFactory) PsiDirectory(com.intellij.psi.PsiDirectory) DocumentContent(com.intellij.diff.contents.DocumentContent) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class ClassBrowser method configureDialog.

private void configureDialog(final TreeClassChooser dialog) {
    final String className = getText();
    final PsiClass psiClass = findClass(className);
    if (psiClass == null)
        return;
    final PsiDirectory directory = psiClass.getContainingFile().getContainingDirectory();
    if (directory != null)
        dialog.selectDirectory(directory);
    dialog.select(psiClass);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiClass(com.intellij.psi.PsiClass)

Example 84 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class LocationUtil method isJarAttached.

public static boolean isJarAttached(@NotNull Location location, final PsiDirectory[] directories, final String... fqns) {
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(location.getProject());
    final Module locationModule = location.getModule();
    if (locationModule != null) {
        for (String fqn : fqns) {
            if (facade.findClass(fqn, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(locationModule, true)) != null)
                return true;
        }
    } else {
        for (PsiDirectory directory : directories) {
            final Module module = ModuleUtilCore.findModuleForFile(directory.getVirtualFile(), location.getProject());
            if (module != null) {
                GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, true);
                for (String fqn : fqns) {
                    if (facade.findClass(fqn, scope) != null) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module)

Example 85 with PsiDirectory

use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.

the class ReformatFilesWithFiltersTest method testDirectoryScope.

public void testDirectoryScope() throws IOException {
    TestFileStructure fileTree = new TestFileStructure(getModule(), myWorkingDirectory);
    PsiFile java1 = fileTree.addTestFile("Test1.java", "empty content");
    PsiFile php1 = fileTree.addTestFile("Pair1.php", "empty content");
    PsiFile js1 = fileTree.addTestFile("Pair1.js", "empty content");
    PsiDirectory outer = fileTree.createDirectoryAndMakeItCurrent("toFormat");
    PsiFile java2 = fileTree.addTestFile("Test2.java", "empty content");
    PsiFile php2 = fileTree.addTestFile("Pair2.php", "empty content");
    PsiFile js2 = fileTree.addTestFile("Pair2.js", "empty content");
    PsiDirectory inner = fileTree.createDirectoryAndMakeItCurrent("toFormat");
    PsiFile java3 = fileTree.addTestFile("Test3.java", "empty content");
    PsiFile php3 = fileTree.addTestFile("Pair3.php", "empty content");
    PsiFile js3 = fileTree.addTestFile("Pair3.js", "empty content");
    reformatDirectoryWithScopeFilter(myWorkingDirectory, directoryScope(outer, true));
    assertWasFormatted(java2, php2, js2, java3, php3, js3);
    assertWasNotFormatted(java1, php1, js1);
    reformatDirectoryWithScopeFilter(myWorkingDirectory, directoryScope(outer, false));
    assertWasFormatted(java2, php2, js2);
    assertWasNotFormatted(java1, php1, js1, java3, php3, js3);
    reformatDirectoryWithScopeFilter(myWorkingDirectory, directoryScope(inner, true));
    assertWasFormatted(java3, php3, js3);
    assertWasNotFormatted(java1, php1, js1, java2, php2, js2);
    reformatDirectoryWithScopeFilter(myWorkingDirectory, directoryScope(myWorkingDirectory, false).union(directoryScope(inner, false)));
    assertWasFormatted(java3, php3, js3, java1, php1, js1);
    assertWasNotFormatted(java2, php2, js2);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile)

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