Search in sources :

Example 56 with PsiManager

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

the class GoImportReferenceSet method computeDefaultContexts.

@NotNull
@Override
public Collection<PsiFileSystemItem> computeDefaultContexts() {
    PsiFile file = getContainingFile();
    if (file == null || !file.isValid() || isAbsolutePathReference()) {
        return Collections.emptyList();
    }
    PsiManager psiManager = file.getManager();
    Module module = ModuleUtilCore.findModuleForPsiElement(file);
    Project project = file.getProject();
    LinkedHashSet<VirtualFile> sourceRoots = GoVendoringUtil.isVendoringEnabled(module) ? GoSdkUtil.getVendoringAwareSourcesPathsToLookup(project, module, file.getVirtualFile()) : GoSdkUtil.getSourcesPathsToLookup(project, module);
    return ContainerUtil.mapNotNull(sourceRoots, psiManager::findDirectory);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with PsiManager

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

the class GoFmtCheckinFactory method createHandler.

@Override
@NotNull
public CheckinHandler createHandler(@NotNull CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
    return new CheckinHandler() {

        @Override
        public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
            JCheckBox checkBox = new JCheckBox("Go fmt");
            return new RefreshableOnComponent() {

                @Override
                @NotNull
                public JComponent getComponent() {
                    JPanel panel = new JPanel(new BorderLayout());
                    panel.add(checkBox, BorderLayout.WEST);
                    return panel;
                }

                @Override
                public void refresh() {
                }

                @Override
                public void saveState() {
                    PropertiesComponent.getInstance(panel.getProject()).setValue(GO_FMT, Boolean.toString(checkBox.isSelected()));
                }

                @Override
                public void restoreState() {
                    checkBox.setSelected(enabled(panel));
                }
            };
        }

        @Override
        public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer<Object, Object> additionalDataConsumer) {
            if (enabled(panel)) {
                Ref<Boolean> success = Ref.create(true);
                FileDocumentManager.getInstance().saveAllDocuments();
                for (PsiFile file : getPsiFiles()) {
                    VirtualFile virtualFile = file.getVirtualFile();
                    new GoFmtFileAction().doSomething(virtualFile, ModuleUtilCore.findModuleForPsiElement(file), file.getProject(), "Go fmt", true, result -> {
                        if (!result)
                            success.set(false);
                    });
                }
                if (!success.get()) {
                    return showErrorMessage(executor);
                }
            }
            return super.beforeCheckin();
        }

        @NotNull
        private ReturnResult showErrorMessage(@Nullable CommitExecutor executor) {
            String[] buttons = new String[] { "&Details...", commitButtonMessage(executor, panel), CommonBundle.getCancelButtonText() };
            int answer = Messages.showDialog(panel.getProject(), "<html><body>GoFmt returned non-zero code on some of the files.<br/>" + "Would you like to commit anyway?</body></html>\n", "Go Fmt", null, buttons, 0, 1, UIUtil.getWarningIcon());
            if (answer == Messages.OK) {
                return ReturnResult.CLOSE_WINDOW;
            }
            if (answer == Messages.NO) {
                return ReturnResult.COMMIT;
            }
            return ReturnResult.CANCEL;
        }

        @NotNull
        private List<PsiFile> getPsiFiles() {
            Collection<VirtualFile> files = panel.getVirtualFiles();
            List<PsiFile> psiFiles = ContainerUtil.newArrayList();
            PsiManager manager = PsiManager.getInstance(panel.getProject());
            for (VirtualFile file : files) {
                PsiFile psiFile = manager.findFile(file);
                if (psiFile instanceof GoFile) {
                    psiFiles.add(psiFile);
                }
            }
            return psiFiles;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GoFile(com.goide.psi.GoFile) PsiManager(com.intellij.psi.PsiManager) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) CommitExecutor(com.intellij.openapi.vcs.changes.CommitExecutor) PairConsumer(com.intellij.util.PairConsumer) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with PsiManager

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

the class ThumbnailViewUI method getSelectedElements.

@NotNull
private PsiElement[] getSelectedElements() {
    VirtualFile[] selectedFiles = getSelectedFiles();
    Set<PsiElement> psiElements = new HashSet<>(selectedFiles.length);
    PsiManager psiManager = PsiManager.getInstance(thumbnailView.getProject());
    for (VirtualFile file : selectedFiles) {
        PsiFile psiFile = psiManager.findFile(file);
        PsiElement element = psiFile != null ? psiFile : psiManager.findDirectory(file);
        if (element != null) {
            psiElements.add(element);
        }
    }
    return PsiUtilCore.toPsiElementArray(psiElements);
}
Also used : PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with PsiManager

use of com.intellij.psi.PsiManager in project android by JetBrains.

the class AndroidManifestsGroupNode method findFileToOpen.

@Nullable
private VirtualFile findFileToOpen(@NotNull Set<VirtualFile> files) {
    VirtualFile bestFile = Iterables.getFirst(files, null);
    PsiManager psiManager = PsiManager.getInstance(myProject);
    for (VirtualFile f : files) {
        PsiFile psiFile = psiManager.findFile(f);
        if (psiFile == null) {
            continue;
        }
        IdeaSourceProvider sourceProvider = AndroidManifestFileNode.getSourceProvider(getValue(), psiFile);
        if (sourceProvider != null && SdkConstants.FD_MAIN.equals(sourceProvider.getName())) {
            bestFile = f;
        }
    }
    return bestFile;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) Nullable(org.jetbrains.annotations.Nullable)

Example 60 with PsiManager

use of com.intellij.psi.PsiManager in project android by JetBrains.

the class AndroidManifestsGroupNode method getChildren.

@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
    PsiManager psiManager = PsiManager.getInstance(myProject);
    List<AbstractTreeNode> children = Lists.newArrayList();
    for (VirtualFile manifest : mySources) {
        if (!manifest.isValid()) {
            continue;
        }
        PsiFile psiFile = psiManager.findFile(manifest);
        if (psiFile != null) {
            AndroidFacet facet = getValue();
            assert facet != null : "Android Facet for module cannot be null";
            children.add(new AndroidManifestFileNode(myProject, psiFile, getSettings(), facet));
        }
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiManager(com.intellij.psi.PsiManager) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiManager (com.intellij.psi.PsiManager)120 VirtualFile (com.intellij.openapi.vfs.VirtualFile)84 PsiFile (com.intellij.psi.PsiFile)61 PsiDirectory (com.intellij.psi.PsiDirectory)31 NotNull (org.jetbrains.annotations.NotNull)26 Project (com.intellij.openapi.project.Project)20 File (java.io.File)19 PsiElement (com.intellij.psi.PsiElement)18 ArrayList (java.util.ArrayList)18 Module (com.intellij.openapi.module.Module)17 Nullable (org.jetbrains.annotations.Nullable)16 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 XmlFile (com.intellij.psi.xml.XmlFile)11 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)9 PsiClass (com.intellij.psi.PsiClass)7 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)6 HashSet (java.util.HashSet)6 Nullable (javax.annotation.Nullable)5 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4