Search in sources :

Example 51 with AccessToken

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

the class DataManagerImpl method getData.

@Nullable
private Object getData(@NotNull String dataId, final Component focusedComponent) {
    try (AccessToken ignored = ProhibitAWTEvents.start("getData")) {
        for (Component c = focusedComponent; c != null; c = c.getParent()) {
            final DataProvider dataProvider = getDataProviderEx(c);
            if (dataProvider == null)
                continue;
            Object data = getDataFromProvider(dataProvider, dataId, null);
            if (data != null)
                return data;
        }
    }
    return null;
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Nullable(org.jetbrains.annotations.Nullable)

Example 52 with AccessToken

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

the class MultipleFilesHyperlinkInfo method navigate.

@Override
public void navigate(@NotNull final Project project, @Nullable RelativePoint hyperlinkLocationPoint) {
    List<PsiFile> currentFiles = new ArrayList<>();
    AccessToken accessToken = ReadAction.start();
    try {
        for (VirtualFile file : myVirtualFiles) {
            if (!file.isValid())
                continue;
            PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
            if (psiFile != null) {
                // Sources may be downloaded.
                PsiElement navigationElement = psiFile.getNavigationElement();
                if (navigationElement instanceof PsiFile) {
                    currentFiles.add((PsiFile) navigationElement);
                    continue;
                }
                currentFiles.add(psiFile);
            }
        }
    } finally {
        accessToken.finish();
    }
    if (currentFiles.isEmpty())
        return;
    if (currentFiles.size() == 1) {
        new OpenFileHyperlinkInfo(myProject, currentFiles.get(0).getVirtualFile(), myLineNumber).navigate(project);
    } else {
        final JBList list = new JBList(currentFiles);
        int width = WindowManager.getInstance().getFrame(project).getSize().width;
        list.setCellRenderer(new GotoFileCellRenderer(width));
        JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Target File").setItemChoosenCallback(() -> {
            VirtualFile file = ((PsiFile) list.getSelectedValue()).getVirtualFile();
            new OpenFileHyperlinkInfo(myProject, file, myLineNumber).navigate(project);
        }).createPopup();
        if (hyperlinkLocationPoint != null) {
            popup.show(hyperlinkLocationPoint);
        } else {
            popup.showInFocusCenter();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OpenFileHyperlinkInfo(com.intellij.execution.filters.OpenFileHyperlinkInfo) GotoFileCellRenderer(com.intellij.ide.util.gotoByName.GotoFileCellRenderer) AccessToken(com.intellij.openapi.application.AccessToken) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) JBList(com.intellij.ui.components.JBList) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PsiElement(com.intellij.psi.PsiElement) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 53 with AccessToken

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

the class ClassesWithAnnotatedMembersSearcher method processQuery.

@Override
public void processQuery(@NotNull ClassesWithAnnotatedMembersSearch.Parameters queryParameters, @NotNull final Processor<PsiClass> consumer) {
    SearchScope scope = queryParameters.getScope();
    for (QueryExecutor executor : Extensions.getExtensions(ClassesWithAnnotatedMembersSearch.EP_NAME)) {
        if (executor instanceof ScopedQueryExecutor) {
            scope = scope.intersectWith(GlobalSearchScope.notScope(((ScopedQueryExecutor) executor).getScope(queryParameters)));
        }
    }
    final Set<PsiClass> processed = new HashSet<>();
    AnnotatedElementsSearch.searchPsiMembers(queryParameters.getAnnotationClass(), scope).forEach(member -> {
        PsiClass psiClass;
        AccessToken token = ReadAction.start();
        try {
            psiClass = member instanceof PsiClass ? (PsiClass) member : member.getContainingClass();
        } finally {
            token.finish();
        }
        if (psiClass != null && processed.add(psiClass)) {
            consumer.process(psiClass);
        }
        return true;
    });
}
Also used : QueryExecutor(com.intellij.util.QueryExecutor) ScopedQueryExecutor(com.intellij.psi.search.searches.ScopedQueryExecutor) AccessToken(com.intellij.openapi.application.AccessToken) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiClass(com.intellij.psi.PsiClass) ScopedQueryExecutor(com.intellij.psi.search.searches.ScopedQueryExecutor) HashSet(com.intellij.util.containers.hash.HashSet)

Example 54 with AccessToken

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

the class ProjectStructureConfigurable method reset.

@Override
public void reset() {
    // need this to ensure VFS operations will not block because of storage flushing
    // and other maintenance IO tasks run in background
    AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("Resetting Project Structure");
    try {
        myContext.reset();
        myProjectJdksModel.reset(myProject);
        Configurable toSelect = null;
        for (Configurable each : myName2Config) {
            if (myUiState.lastEditedConfigurable != null && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) {
                toSelect = each;
            }
            if (each instanceof MasterDetailsComponent) {
                ((MasterDetailsComponent) each).setHistory(myHistory);
            }
            each.reset();
        }
        myHistory.clear();
        if (toSelect == null && myName2Config.size() > 0) {
            toSelect = myName2Config.iterator().next();
        }
        removeSelected();
        navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false);
        if (myUiState.proportion > 0) {
            mySplitter.setProportion(myUiState.proportion);
        }
    } finally {
        token.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) MasterDetailsComponent(com.intellij.openapi.ui.MasterDetailsComponent) Configurable(com.intellij.openapi.options.Configurable) BaseConfigurable(com.intellij.openapi.options.BaseConfigurable) ArtifactsStructureConfigurable(com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactsStructureConfigurable) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable)

Example 55 with AccessToken

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

the class DaemonRespondToChangesTest method testDaemonDisablesItselfDuringHeavyProcessing.

public void testDaemonDisablesItselfDuringHeavyProcessing() throws Exception {
    executeWithReparseDelay(() -> {
        runHeavyProcessing = false;
        try {
            final Set<Editor> applied = Collections.synchronizedSet(new THashSet<>());
            final Set<Editor> collected = Collections.synchronizedSet(new THashSet<>());
            registerFakePass(applied, collected);
            configureByText(PlainTextFileType.INSTANCE, "");
            Editor editor = getEditor();
            EditorTracker editorTracker = getProject().getComponent(EditorTracker.class);
            editorTracker.setActiveEditors(Collections.singletonList(editor));
            while (HeavyProcessLatch.INSTANCE.isRunning()) {
                UIUtil.dispatchAllInvocationEvents();
            }
            // restart daemon
            type("xxx");
            assertTrue(editorTracker.getActiveEditors().contains(editor));
            assertSame(editor, FileEditorManager.getInstance(myProject).getSelectedTextEditor());
            // wait for first pass to complete
            long start = System.currentTimeMillis();
            while (myDaemonCodeAnalyzer.isRunning() || !applied.contains(editor)) {
                UIUtil.dispatchAllInvocationEvents();
                if (System.currentTimeMillis() - start > 10000) {
                    fail("Too long waiting for daemon");
                }
            }
            runHeavyProcessing = true;
            ApplicationManager.getApplication().executeOnPooledThread(() -> {
                AccessToken token = HeavyProcessLatch.INSTANCE.processStarted("my own heavy op");
                try {
                    while (runHeavyProcessing) {
                    }
                } finally {
                    token.finish();
                }
            });
            while (!HeavyProcessLatch.INSTANCE.isRunning()) {
                UIUtil.dispatchAllInvocationEvents();
            }
            applied.clear();
            collected.clear();
            // try to restart daemon
            type("xxx");
            start = System.currentTimeMillis();
            while (System.currentTimeMillis() < start + 5000) {
                // it should not restart
                assertEmpty(applied);
                assertEmpty(collected);
                UIUtil.dispatchAllInvocationEvents();
            }
        } finally {
            runHeavyProcessing = false;
        }
    });
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

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