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();
}
}
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();
}
}
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);
}
}
}
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);
}
Aggregations