Search in sources :

Example 86 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.

the class SocketInputHandlerImpl method getResourceBundleFromModuleSource.

private static PropertiesFile getResourceBundleFromModuleSource(Module module, final String bundleName) {
    final AccessToken token = ReadAction.start();
    try {
        final PsiManager psiManager = PsiManager.getInstance(module.getProject());
        final List<VirtualFile> result = new ArrayList<>();
        FileTypeIndex.processFiles(PropertiesFileType.INSTANCE, file -> {
            if (file.getNameWithoutExtension().equals(bundleName)) {
                result.add(file);
                if (file.getParent().getName().equals("en_US")) {
                    return false;
                }
            }
            return true;
        }, module.getModuleScope(false));
        PropertiesFile defaultResourceBundle = null;
        for (VirtualFile file : result) {
            PsiFile psiFile = psiManager.findFile(file);
            if (psiFile != null) {
                if (file.getParent().getName().equals("en_US")) {
                    defaultResourceBundle = (PropertiesFile) psiFile;
                } else {
                    return (PropertiesFile) psiFile;
                }
            }
        }
        return defaultResourceBundle;
    } finally {
        token.finish();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AccessToken(com.intellij.openapi.application.AccessToken) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFile(com.intellij.psi.PsiFile)

Example 87 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.

the class ModuleInfoUtil method collectLocalStyle.

public static List<LocalStyleHolder> collectLocalStyle(final ModuleInfo moduleInfo, final String flexSdkVersion, final StringWriter stringWriter, final ProblemsHolder problemsHolder, ProjectComponentReferenceCounter projectComponentReferenceCounter, AssetCounter assetCounter) {
    Project project = moduleInfo.getModule().getProject();
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.waitForSmartMode();
    }
    final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
    if (psiDocumentManager.hasUncommitedDocuments()) {
        final Semaphore semaphore = new Semaphore();
        semaphore.down();
        Application application = ApplicationManager.getApplication();
        LogMessageUtil.LOG.assertTrue(!application.isReadAccessAllowed());
        application.invokeLater(() -> psiDocumentManager.performWhenAllCommitted(() -> semaphore.up()));
        semaphore.waitFor();
    }
    final AccessToken token = ReadAction.start();
    try {
        if (moduleInfo.isApp()) {
            return collectApplicationLocalStyle(moduleInfo.getModule(), flexSdkVersion, problemsHolder, stringWriter, projectComponentReferenceCounter, assetCounter);
        } else {
            return collectLibraryLocalStyle(moduleInfo.getModule(), stringWriter, problemsHolder, projectComponentReferenceCounter, assetCounter);
        }
    } finally {
        token.finish();
    }
}
Also used : Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken) Semaphore(com.intellij.util.concurrency.Semaphore) DumbService(com.intellij.openapi.project.DumbService) Application(com.intellij.openapi.application.Application)

Example 88 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.

the class ComplexRenderAction method collectChanges.

private void collectChanges(List<DocumentFactoryManager.DocumentInfo> documentInfos, THashMap<ModuleInfo, List<LocalStyleHolder>> localStyleSources) {
    final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    final DocumentFactoryManager documentFactoryManager = DocumentFactoryManager.getInstance();
    final Client client = Client.getInstance();
    for (Document document : documents) {
        final VirtualFile file = fileDocumentManager.getFile(document);
        if (file == null) {
            continue;
        }
        boolean isMxml = JavaScriptSupportLoader.isFlexMxmFile(file);
        if (isMxml || file.getFileType() == CssFileType.INSTANCE) {
            if (!collectChangedLocalStyleSources(localStyleSources, file) && onlyStyle) {
                // if onlyStyle and we didn't find changed local style sources, so, it is new style source - we must collect style sources for appropriate module
                Project p = ProjectUtil.guessProjectForFile(file);
                if (p != null) {
                    ModuleInfo info = client.getRegisteredModules().getNullableInfo(ModuleUtilCore.findModuleForFile(file, p));
                    if (info != null) {
                        localStyleSources.put(info, Collections.emptyList());
                    }
                }
            }
        }
        final DocumentFactoryManager.DocumentInfo info = isMxml ? documentFactoryManager.getNullableInfo(file) : null;
        if (info == null) {
            continue;
        } else if (onlyStyle) {
            info.documentModificationStamp = document.getModificationStamp();
            continue;
        }
        if (info.documentModificationStamp == document.getModificationStamp()) {
            continue;
        }
        final Project project = ProjectUtil.guessProjectForFile(file);
        if (project == null) {
            continue;
        }
        final Module module = ModuleUtilCore.findModuleForFile(file, project);
        if (module == null) {
            continue;
        }
        final XmlFile psiFile;
        final AccessToken token = ReadAction.start();
        try {
            psiFile = (XmlFile) PsiDocumentManager.getInstance(project).getPsiFile(document);
            if (psiFile == null) {
                continue;
            }
        } finally {
            token.finish();
        }
        if (client.updateDocumentFactory(info.getId(), module, psiFile, reportProblems)) {
            info.documentModificationStamp = document.getModificationStamp();
            documentInfos.add(info);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) AccessToken(com.intellij.openapi.application.AccessToken) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document) Module(com.intellij.openapi.module.Module)

Example 89 with AccessToken

use of com.intellij.openapi.application.AccessToken in project intellij-plugins by JetBrains.

the class Client method writeDocumentFactory.

/**
   * You must rollback block out if this method returns false
   */
private boolean writeDocumentFactory(DocumentInfo documentInfo, Module module, XmlFile psiFile, ProblemsHolder problemsHolder) throws IOException {
    final AccessToken token = ReadAction.start();
    final int flags;
    try {
        final JSClass jsClass = XmlBackedJSClassFactory.getXmlBackedClass(psiFile);
        assert jsClass != null;
        out.writeAmfUtf(jsClass.getQualifiedName());
        if (ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.SPARK_APPLICATION) || ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.MX_APPLICATION)) {
            flags = 1;
        } else if (ActionScriptClassResolver.isParentClass(jsClass, FlexCommonTypeNames.IUI_COMPONENT)) {
            flags = 0;
        } else {
            flags = 2;
        }
    } finally {
        token.finish();
    }
    out.write(flags);
    Pair<ProjectComponentReferenceCounter, List<RangeMarker>> result = new MxmlWriter(out, problemsHolder, registeredModules.getInfo(module).getFlexLibrarySet().assetCounterInfo.demanded).write(psiFile);
    if (result == null) {
        return false;
    }
    blockOut.end();
    documentInfo.setRangeMarkers(result.second);
    return result.first.unregistered.isEmpty() || registerDocumentReferences(result.first.unregistered, module, problemsHolder);
}
Also used : ProjectComponentReferenceCounter(com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter) MxmlWriter(com.intellij.flex.uiDesigner.mxml.MxmlWriter) AccessToken(com.intellij.openapi.application.AccessToken) ArrayList(java.util.ArrayList) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass)

Aggregations

AccessToken (com.intellij.openapi.application.AccessToken)89 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 Nullable (org.jetbrains.annotations.Nullable)15 Module (com.intellij.openapi.module.Module)12 Document (com.intellij.openapi.editor.Document)10 Project (com.intellij.openapi.project.Project)10 GitRepository (git4idea.repo.GitRepository)9 ArrayList (java.util.ArrayList)8 PsiElement (com.intellij.psi.PsiElement)7 NotNull (org.jetbrains.annotations.NotNull)6 File (java.io.File)5 IOException (java.io.IOException)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 CompileContext (com.intellij.openapi.compiler.CompileContext)3 CompileTask (com.intellij.openapi.compiler.CompileTask)3 PsiFile (com.intellij.psi.PsiFile)3 List (java.util.List)3 ProjectComponentReferenceCounter (com.intellij.flex.uiDesigner.mxml.ProjectComponentReferenceCounter)2 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)2