use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class AbstractExternalFilter method getExternalDocInfo.
@Nullable
@SuppressWarnings({ "HardCodedStringLiteral" })
public String getExternalDocInfo(final String url) throws Exception {
Application app = ApplicationManager.getApplication();
if (!app.isUnitTestMode() && app.isDispatchThread() || app.isWriteAccessAllowed()) {
LOG.error("May block indefinitely: shouldn't be called from EDT or under write lock");
return null;
}
if (url == null || !MyJavadocFetcher.ourFree) {
return null;
}
MyJavadocFetcher fetcher = new MyJavadocFetcher(url, new MyDocBuilder() {
@Override
public void buildFromStream(String url, Reader input, StringBuilder result) throws IOException {
doBuildFromStream(url, input, result);
}
});
try {
app.executeOnPooledThread(fetcher).get();
} catch (Exception e) {
return null;
}
Exception exception = fetcher.myException;
if (exception != null) {
fetcher.myException = null;
throw exception;
}
return correctDocText(url, fetcher.data);
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class ExternalAnnotationsManagerImpl method annotateExternally.
@Override
public void annotateExternally(@NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQName, @NotNull final PsiFile fromFile, @Nullable final PsiNameValuePair[] value) throws CanceledConfigurationException {
Application application = ApplicationManager.getApplication();
application.assertIsDispatchThread();
LOG.assertTrue(!application.isWriteAccessAllowed());
final Project project = myPsiManager.getProject();
final PsiFile containingFile = listOwner.getContainingFile();
if (!(containingFile instanceof PsiJavaFile)) {
notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
return;
}
final String packageName = ((PsiJavaFile) containingFile).getPackageName();
final VirtualFile containingVirtualFile = containingFile.getVirtualFile();
LOG.assertTrue(containingVirtualFile != null);
final List<OrderEntry> entries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(containingVirtualFile);
if (entries.isEmpty()) {
notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
return;
}
for (final OrderEntry entry : entries) {
if (entry instanceof ModuleOrderEntry)
continue;
VirtualFile[] roots = AnnotationOrderRootType.getFiles(entry);
roots = filterByReadOnliness(roots);
if (roots.length > 0) {
chooseRootAndAnnotateExternally(listOwner, annotationFQName, fromFile, project, packageName, roots, value);
} else {
if (application.isUnitTestMode() || application.isHeadlessEnvironment()) {
notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
return;
}
DumbService.getInstance(project).setAlternativeResolveEnabled(true);
try {
if (!setupRootAndAnnotateExternally(entry, project, listOwner, annotationFQName, fromFile, packageName, value)) {
throw CanceledConfigurationException.INSTANCE;
}
} finally {
DumbService.getInstance(project).setAlternativeResolveEnabled(false);
}
}
break;
}
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class JavadocQuarantineStatusCleaner method cleanIfNeeded.
public static void cleanIfNeeded(@NotNull VirtualFile javadocFolder) {
Application application = ApplicationManager.getApplication();
assert !application.isDispatchThread();
if (!SystemInfo.isMac || !javadocFolder.isInLocalFileSystem() || !javadocFolder.isDirectory())
return;
String folderPath = VfsUtilCore.virtualToIoFile(javadocFolder).getAbsolutePath();
// UserDefinedFileAttributeView isn't supported by JDK for HFS+ extended attributes on OS X, so we resort to JNA
if (XAttrUtil.getXAttr(folderPath, QUARANTINE_ATTRIBUTE) == null)
return;
application.invokeLater(() -> {
int result = Messages.showYesNoDialog(ApplicationBundle.message("quarantine.dialog.message"), ApplicationBundle.message("quarantine.dialog.title"), null);
if (result == Messages.YES) {
cleanQuarantineStatusInBackground(folderPath);
}
}, ModalityState.any());
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class JrtFileSystemImpl method checkSubscription.
private void checkSubscription() {
if (mySubscribed.getAndSet(true))
return;
Application app = ApplicationManager.getApplication();
app.getMessageBus().connect(app).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
Set<VirtualFile> toRefresh = null;
for (VFileEvent event : events) {
if (event.getFileSystem() instanceof LocalFileSystem && event instanceof VFileContentChangeEvent) {
VirtualFile file = event.getFile();
if (file != null && "release".equals(file.getName())) {
String homePath = file.getParent().getPath();
ArchiveHandler handler = myHandlers.remove(homePath);
if (handler != null) {
handler.dispose();
VirtualFile root = findFileByPath(composeRootPath(homePath));
if (root != null) {
((NewVirtualFile) root).markDirtyRecursively();
if (toRefresh == null)
toRefresh = ContainerUtil.newHashSet();
toRefresh.add(root);
}
}
}
}
}
if (toRefresh != null) {
boolean async = !ApplicationManager.getApplication().isUnitTestMode();
RefreshQueue.getInstance().refresh(async, true, null, toRefresh);
}
}
});
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class PostprocessReformattingAspect method postponeFormattingInside.
public <T> T postponeFormattingInside(@NotNull Computable<T> computable) {
Application application = ApplicationManager.getApplication();
application.assertIsDispatchThread();
try {
incrementPostponedCounter();
return computable.compute();
} finally {
decrementPostponedCounter();
}
}
Aggregations