Search in sources :

Example 31 with PsiDirectory

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

the class DissociateResourceBundleAction method dissociate.

public static void dissociate(final Collection<ResourceBundle> resourceBundles, final Project project) {
    final Set<PsiFileSystemItem> toUpdateInProjectView = new HashSet<>();
    for (ResourceBundle resourceBundle : resourceBundles) {
        for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
            PsiDirectory containingDirectory = propertiesFile.getContainingFile().getContainingDirectory();
            if (containingDirectory != null) {
                toUpdateInProjectView.add(containingDirectory);
            }
        }
        ResourceBundleManager.getInstance(project).dissociateResourceBundle(resourceBundle);
    }
    AbstractProjectViewPane currentProjectViewPane = ProjectView.getInstance(project).getCurrentProjectViewPane();
    if (currentProjectViewPane == null) {
        return;
    }
    AbstractTreeBuilder treeBuilder = currentProjectViewPane.getTreeBuilder();
    if (treeBuilder != null) {
        for (PsiFileSystemItem item : toUpdateInProjectView) {
            treeBuilder.queueUpdateFrom(item, false);
        }
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) HashSet(com.intellij.util.containers.HashSet)

Example 32 with PsiDirectory

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

the class CustomResourceBundleTest method testCustomResourceBundleFilesMovedOrDeleted.

public void testCustomResourceBundleFilesMovedOrDeleted() throws IOException {
    final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("resources-dev/my-app-dev.properties", ""));
    final PropertiesFile file2 = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("resources-dev/my-app-test.properties", ""));
    final PropertiesFile file3 = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("resources-prod/my-app-prod.properties", ""));
    assertNotNull(file);
    assertNotNull(file2);
    assertNotNull(file3);
    assertOneElement(file.getResourceBundle().getPropertiesFiles());
    assertOneElement(file2.getResourceBundle().getPropertiesFiles());
    assertOneElement(file3.getResourceBundle().getPropertiesFiles());
    final ResourceBundleManager resourceBundleBaseNameManager = ResourceBundleManager.getInstance(getProject());
    resourceBundleBaseNameManager.combineToResourceBundle(list(file, file2, file3), "my-app");
    assertSize(3, file.getResourceBundle().getPropertiesFiles());
    final PsiDirectory newDir = PsiManager.getInstance(getProject()).findDirectory(myFixture.getTempDirFixture().findOrCreateDir("new-resources-dir"));
    new MoveFilesOrDirectoriesProcessor(getProject(), new PsiElement[] { file2.getContainingFile() }, newDir, false, false, null, null).run();
    ApplicationManager.getApplication().runWriteAction(() -> file3.getContainingFile().delete());
    assertSize(2, file.getResourceBundle().getPropertiesFiles());
    final ResourceBundleManagerState state = ResourceBundleManager.getInstance(getProject()).getState();
    assertNotNull(state);
    assertSize(1, state.getCustomResourceBundles());
    assertSize(2, state.getCustomResourceBundles().get(0).getFileUrls());
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) MoveFilesOrDirectoriesProcessor(com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 33 with PsiDirectory

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

the class CustomResourceBundleTest method testResourceBundleManagerUpdatesProperlyWhileDirRemoval.

public void testResourceBundleManagerUpdatesProperlyWhileDirRemoval() {
    myFixture.addFileToProject("qwe/asd/p.properties", "");
    final PsiFile file = myFixture.addFileToProject("qwe/asd/p_en.properties", "");
    final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(file);
    assertNotNull(propertiesFile);
    final ResourceBundleManager resourceBundleManager = ResourceBundleManager.getInstance(getProject());
    resourceBundleManager.dissociateResourceBundle(propertiesFile.getResourceBundle());
    final PropertiesFile propFile1 = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("qwe1/asd1/p.properties", ""));
    final PropertiesFile propFile2 = PropertiesImplUtil.getPropertiesFile(myFixture.addFileToProject("qwe1/asd1/p_abc.properties", ""));
    assertNotNull(propFile1);
    assertNotNull(propFile2);
    resourceBundleManager.combineToResourceBundle(ContainerUtil.newArrayList(propFile1, propFile2), "p");
    final PsiFile someFile = myFixture.addFileToProject("to_remove/asd.txt", "");
    final PsiDirectory toRemove = someFile.getParent();
    assertNotNull(toRemove);
    ApplicationManager.getApplication().runWriteAction(toRemove::delete);
    final ResourceBundleManagerState state = resourceBundleManager.getState();
    assertNotNull(state);
    assertSize(1, state.getCustomResourceBundles());
    assertSize(2, state.getDissociatedFiles());
    final PsiDirectory directory = propertiesFile.getParent().getParent();
    assertNotNull(directory);
    ApplicationManager.getApplication().runWriteAction(directory::delete);
    assertSize(1, state.getCustomResourceBundles());
    assertSize(0, state.getDissociatedFiles());
    final PsiDirectory directory1 = propFile1.getParent().getParent();
    assertNotNull(directory1);
    ApplicationManager.getApplication().runWriteAction(directory1::delete);
    assertSize(0, state.getCustomResourceBundles());
    assertSize(0, state.getDissociatedFiles());
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 34 with PsiDirectory

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

the class CleanPycAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final PsiElement[] elements = e.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
    if (elements == null)
        return;
    final List<File> pycFiles = new ArrayList<>();
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        for (PsiElement element : elements) {
            PsiDirectory dir = (PsiDirectory) element;
            collectPycFiles(new File(dir.getVirtualFile().getPath()), pycFiles);
        }
        FileUtil.asyncDelete(pycFiles);
    }, "Cleaning up .pyc files...", false, e.getProject());
    final StatusBar statusBar = WindowManager.getInstance().getIdeFrame(e.getProject()).getStatusBar();
    statusBar.setInfo("Deleted " + pycFiles.size() + " bytecode file" + (pycFiles.size() != 1 ? "s" : ""));
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) ArrayList(java.util.ArrayList) File(java.io.File) StatusBar(com.intellij.openapi.wm.StatusBar) PsiElement(com.intellij.psi.PsiElement)

Example 35 with PsiDirectory

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

the class CreatePackageAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
    if (view == null) {
        return;
    }
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final PsiDirectory directory = DirectoryChooserUtil.getOrChooseDirectory(view);
    if (directory == null)
        return;
    final CreateDirectoryOrPackageHandler validator = new CreateDirectoryOrPackageHandler(project, directory, false, ".") {

        @Override
        protected void createDirectories(String subDirName) {
            super.createDirectories(subDirName);
            PsiFileSystemItem element = getCreatedElement();
            if (element instanceof PsiDirectory) {
                createInitPyInHierarchy((PsiDirectory) element, directory);
            }
        }
    };
    Messages.showInputDialog(project, IdeBundle.message("prompt.enter.new.package.name"), IdeBundle.message("title.new.package"), Messages.getQuestionIcon(), "", validator);
    final PsiFileSystemItem result = validator.getCreatedElement();
    if (result != null) {
        view.selectElement(result);
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) CreateDirectoryOrPackageHandler(com.intellij.ide.actions.CreateDirectoryOrPackageHandler) IdeView(com.intellij.ide.IdeView) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

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