Search in sources :

Example 41 with PsiManager

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

the class InjectedPsiCachedValueProvider method compute.

@Override
public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement element) {
    PsiFile hostPsiFile = element.getContainingFile();
    if (hostPsiFile == null)
        return null;
    FileViewProvider viewProvider = hostPsiFile.getViewProvider();
    final DocumentEx hostDocument = (DocumentEx) viewProvider.getDocument();
    if (hostDocument == null)
        return null;
    PsiManager psiManager = viewProvider.getManager();
    final Project project = psiManager.getProject();
    InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project);
    final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile);
    return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument);
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) Project(com.intellij.openapi.project.Project) FileViewProvider(com.intellij.psi.FileViewProvider) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile)

Example 42 with PsiManager

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

the class BasicTest method createJetFileList.

private static List<KtFile> createJetFileList(@NotNull Project project, @NotNull List<String> list, @Nullable String root) {
    List<KtFile> libFiles = Lists.newArrayList();
    PsiManager psiManager = PsiManager.getInstance(project);
    VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
    VirtualFile rootFile = root == null ? null : fileSystem.findFileByPath(root);
    for (String libFileName : list) {
        VirtualFile virtualFile = rootFile == null ? fileSystem.findFileByPath(libFileName) : rootFile.findFileByRelativePath(libFileName);
        //TODO logging?
        assert virtualFile != null : "virtual file is missing, most likely the file doesn't exist: " + libFileName;
        PsiFile psiFile = psiManager.findFile(virtualFile);
        libFiles.add((KtFile) psiFile);
    }
    return libFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) PsiManager(com.intellij.psi.PsiManager) KtFile(org.jetbrains.kotlin.psi.KtFile) PsiFile(com.intellij.psi.PsiFile)

Example 43 with PsiManager

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

the class Struts2ModelValidator method getFilesToProcess.

public Collection<VirtualFile> getFilesToProcess(final Project project, final CompileContext context) {
    final StrutsManager strutsManager = StrutsManager.getInstance(project);
    final PsiManager psiManager = PsiManager.getInstance(project);
    // cache validation settings per module
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final FactoryMap<Module, Boolean> enabledForModule = new FactoryMap<Module, Boolean>() {

        protected Boolean create(final Module module) {
            return isEnabledForModule(module);
        }
    };
    final Set<VirtualFile> files = new THashSet<>();
    for (final VirtualFile file : context.getCompileScope().getFiles(StdFileTypes.XML, false)) {
        final Module module = context.getModuleByFile(file);
        if (module != null && enabledForModule.get(module)) {
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile instanceof XmlFile) {
                final StrutsModel model = strutsManager.getModelByFile((XmlFile) psiFile);
                if (model != null) {
                    for (final XmlFile configFile : model.getConfigFiles()) {
                        ContainerUtil.addIfNotNull(files, configFile.getVirtualFile());
                    }
                }
            }
        }
    }
    InspectionValidatorUtil.expandCompileScopeIfNeeded(files, context);
    return files;
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) PsiManager(com.intellij.psi.PsiManager) THashSet(gnu.trove.THashSet) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Example 44 with PsiManager

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

the class ValidatorModelValidator method getFilesToProcess.

public Collection<VirtualFile> getFilesToProcess(final Project project, final CompileContext context) {
    final PsiManager psiManager = PsiManager.getInstance(project);
    final ValidatorManager validatorManager = ValidatorManager.getInstance(project);
    // cache S2facet/validation settings per module
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final FactoryMap<Module, Boolean> enabledForModule = new FactoryMap<Module, Boolean>() {

        protected Boolean create(final Module module) {
            return isEnabledForModule(module) && StrutsFacet.getInstance(module) != null;
        }
    };
    // collect all validation.xml files located in sources of S2-modules
    final Set<VirtualFile> files = new THashSet<>();
    for (final VirtualFile file : context.getProjectCompileScope().getFiles(StdFileTypes.XML, true)) {
        if (StringUtil.endsWith(file.getName(), FILENAME_EXTENSION_VALIDATION_XML)) {
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile instanceof XmlFile && validatorManager.isValidatorsFile((XmlFile) psiFile)) {
                final Module module = ModuleUtilCore.findModuleForFile(file, project);
                if (module != null && enabledForModule.get(module)) {
                    files.add(file);
                }
            }
        }
    }
    // add validator-config.xml if not default one from xwork.jar
    final Set<VirtualFile> descriptorFiles = new THashSet<>();
    for (final Module module : ModuleManager.getInstance(project).getModules()) {
        if (enabledForModule.get(module)) {
            final PsiFile psiFile = validatorManager.getValidatorConfigFile(module);
            if (psiFile != null && validatorManager.isCustomValidatorConfigFile(psiFile)) {
                InspectionValidatorUtil.addFile(descriptorFiles, psiFile);
            }
        }
    }
    files.addAll(InspectionValidatorUtil.expandCompileScopeIfNeeded(descriptorFiles, context));
    return files;
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ValidatorManager(com.intellij.struts2.dom.validator.ValidatorManager) XmlFile(com.intellij.psi.xml.XmlFile) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) THashSet(gnu.trove.THashSet)

Example 45 with PsiManager

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

the class Tester method testFiles.

protected void testFiles(final Tester tester, VirtualFile[] files, VirtualFile[] auxiliaryFiles) throws Exception {
    VirtualFile[] testFiles = configureByFiles(getRawProjectRoot(), files, auxiliaryFiles);
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    for (int i = 0, n = testFiles.length; i < n; i++) {
        final VirtualFile file = testFiles[i];
        if (!file.getName().endsWith(JavaScriptSupportLoader.MXML_FILE_EXTENSION_DOT)) {
            continue;
        }
        final VirtualFile originalVFile = files[i];
        final XmlFile xmlFile = (XmlFile) psiManager.findFile(file);
        assert xmlFile != null;
        final Callable<Void> action = () -> {
            tester.test(file, xmlFile, originalVFile);
            return null;
        };
        if (TIMEOUT == 0) {
            action.call();
        } else {
            ApplicationManager.getApplication().executeOnPooledThread(action).get(TIMEOUT, TimeUnit.SECONDS);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) PsiManager(com.intellij.psi.PsiManager)

Aggregations

PsiManager (com.intellij.psi.PsiManager)97 VirtualFile (com.intellij.openapi.vfs.VirtualFile)69 PsiFile (com.intellij.psi.PsiFile)51 NotNull (org.jetbrains.annotations.NotNull)25 PsiDirectory (com.intellij.psi.PsiDirectory)24 Project (com.intellij.openapi.project.Project)17 Module (com.intellij.openapi.module.Module)16 Nullable (org.jetbrains.annotations.Nullable)16 PsiElement (com.intellij.psi.PsiElement)15 ArrayList (java.util.ArrayList)15 File (java.io.File)14 XmlFile (com.intellij.psi.xml.XmlFile)11 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)10 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)8 PsiClass (com.intellij.psi.PsiClass)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)4 IOException (java.io.IOException)4 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)4