Search in sources :

Example 91 with PsiManager

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

the class XsltIncludeIndex method _process.

private static boolean _process(VirtualFile[] files, Project project, Processor<XmlFile> processor) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, (NullableFunction<VirtualFile, PsiFile>) file -> psiManager.findFile(file));
    for (final PsiFile psiFile : psiFiles) {
        if (XsltSupport.isXsltFile(psiFile)) {
            if (!processor.process((XmlFile) psiFile)) {
                return false;
            }
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileIncludeManager(com.intellij.psi.impl.include.FileIncludeManager) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XsltSupport(org.intellij.lang.xpath.xslt.XsltSupport) NullableFunction(com.intellij.util.NullableFunction) ContainerUtil(com.intellij.util.containers.ContainerUtil) PsiManager(com.intellij.psi.PsiManager) Nullable(org.jetbrains.annotations.Nullable) Comparing(com.intellij.openapi.util.Comparing) Processor(com.intellij.util.Processor) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull) XmlFile(com.intellij.psi.xml.XmlFile) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

Example 92 with PsiManager

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

the class MethodTypeInferencer method compute.

@Override
@Nullable
public PsiType compute() {
    List<GrStatement> returns = ControlFlowUtils.collectReturns(myBlock);
    if (returns.isEmpty())
        return PsiType.VOID;
    PsiType result = null;
    PsiManager manager = myBlock.getManager();
    for (GrStatement returnStatement : returns) {
        GrExpression value = null;
        if (returnStatement instanceof GrReturnStatement) {
            value = ((GrReturnStatement) returnStatement).getReturnValue();
        } else if (returnStatement instanceof GrExpression) {
            value = (GrExpression) returnStatement;
        }
        if (value != null) {
            result = TypesUtil.getLeastUpperBoundNullable(result, value.getType(), manager);
        }
    }
    return result;
}
Also used : PsiManager(com.intellij.psi.PsiManager) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrReturnStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement) GrStatement(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 93 with PsiManager

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

the class TempFileSystemTest method testMove.

public void testMove() {
    ProjectRootManager rootManager = ProjectRootManager.getInstance(getProject());
    VirtualFile sourceRoot = rootManager.getContentSourceRoots()[0];
    PsiManager psiManager = PsiManager.getInstance(getProject());
    PsiDirectory psiSourceRoot = psiManager.findDirectory(sourceRoot);
    PsiFile psiFile = ApplicationManager.getApplication().runWriteAction(new Computable<PsiFile>() {

        @Override
        public PsiFile compute() {
            return psiSourceRoot.createFile("TestDocument.xml");
        }
    });
    PsiDirectory subdirectory = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {

        @Override
        public PsiDirectory compute() {
            return psiSourceRoot.createSubdirectory("com");
        }
    });
    PlatformTestCase.move(psiFile.getVirtualFile(), subdirectory.getVirtualFile());
    assertTrue(psiFile.isValid());
    ApplicationManager.getApplication().runWriteAction(() -> psiFile.delete());
    assertFalse(psiFile.isValid());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager)

Example 94 with PsiManager

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

the class BackwardDependenciesBuilder method analyze.

@Override
public void analyze() {
    final DependenciesBuilder builder = new ForwardDependenciesBuilder(getProject(), myForwardScope, getScopeOfInterest());
    builder.setTotalFileCount(myTotalFileCount);
    builder.analyze();
    subtractScope(builder, getScope());
    final PsiManager psiManager = PsiManager.getInstance(getProject());
    psiManager.startBatchFilesProcessingMode();
    try {
        final int fileCount = getScope().getFileCount();
        final boolean includeTestSource = getScope().isIncludeTestSource();
        getScope().accept(virtualFile -> {
            if (!includeTestSource && TestSourcesFilter.isTestSources(virtualFile, getProject())) {
                return true;
            }
            ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
            if (indicator != null) {
                if (indicator.isCanceled()) {
                    throw new ProcessCanceledException();
                }
                indicator.setText(AnalysisScopeBundle.message("package.dependencies.progress.text"));
                indicator.setText2(getRelativeToProjectPath(virtualFile));
                if (fileCount > 0) {
                    indicator.setFraction(((double) ++myFileCount) / myTotalFileCount);
                }
            }
            ApplicationManager.getApplication().runReadAction(() -> {
                PsiFile file = psiManager.findFile(virtualFile);
                if (file != null) {
                    final PsiElement navigationElement = file.getNavigationElement();
                    if (navigationElement instanceof PsiFile) {
                        file = (PsiFile) navigationElement;
                    }
                    final Map<PsiFile, Set<PsiFile>> dependencies = builder.getDependencies();
                    for (final PsiFile psiFile : dependencies.keySet()) {
                        if (dependencies.get(psiFile).contains(file)) {
                            Set<PsiFile> fileDeps = getDependencies().get(file);
                            if (fileDeps == null) {
                                fileDeps = new HashSet<>();
                                getDependencies().put(file, fileDeps);
                            }
                            fileDeps.add(psiFile);
                        }
                    }
                    psiManager.dropResolveCaches();
                }
            });
            return true;
        });
    } finally {
        psiManager.finishBatchFilesProcessingMode();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PsiManager(com.intellij.psi.PsiManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 95 with PsiManager

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

the class GoToLinkTargetAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = getEventProject(e);
    VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    if (project != null && file != null && file.is(VFileProperty.SYMLINK)) {
        VirtualFile target = file.getCanonicalFile();
        if (target != null) {
            PsiManager psiManager = PsiManager.getInstance(project);
            PsiFileSystemItem psiFile = target.isDirectory() ? psiManager.findDirectory(target) : psiManager.findFile(target);
            if (psiFile != null) {
                ProjectView.getInstance(project).select(psiFile, target, false);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PsiManager(com.intellij.psi.PsiManager) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

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