Search in sources :

Example 71 with Application

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);
}
Also used : Application(com.intellij.openapi.application.Application) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 72 with Application

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;
    }
}
Also used : Project(com.intellij.openapi.project.Project) Application(com.intellij.openapi.application.Application)

Example 73 with Application

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());
}
Also used : Application(com.intellij.openapi.application.Application)

Example 74 with Application

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);
            }
        }
    });
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveHandler(com.intellij.openapi.vfs.impl.ArchiveHandler) Set(java.util.Set) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) Application(com.intellij.openapi.application.Application)

Example 75 with Application

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();
    }
}
Also used : Application(com.intellij.openapi.application.Application)

Aggregations

Application (com.intellij.openapi.application.Application)188 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 IOException (java.io.IOException)14 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)9 ModalityState (com.intellij.openapi.application.ModalityState)8 Ref (com.intellij.openapi.util.Ref)7 ArrayList (java.util.ArrayList)7 List (java.util.List)6 ApplicationImpl (com.intellij.openapi.application.impl.ApplicationImpl)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)4 Document (com.intellij.openapi.editor.Document)4 Module (com.intellij.openapi.module.Module)4 Computable (com.intellij.openapi.util.Computable)4 PsiFile (com.intellij.psi.PsiFile)4 File (java.io.File)4 Editor (com.intellij.openapi.editor.Editor)3