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