From fa1cc17710d63dfc31e113ecfd17538b111b2e71 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 24 May 2016 14:35:40 +0300 Subject: [PATCH] make read action visible in stacktrace --- .../intellij/util/DebugReflectionUtil.java | 54 ++++++++++-------- .../intellij/find/impl/FindInProjectUtil.java | 38 ++++++------- .../intellij/ide/actions/GotoClassAction.java | 56 +++++++++---------- .../breakpoints/XBreakpointManagerImpl.java | 10 +--- 4 files changed, 78 insertions(+), 80 deletions(-) diff --git a/platform/core-impl/src/com/intellij/util/DebugReflectionUtil.java b/platform/core-impl/src/com/intellij/util/DebugReflectionUtil.java index 3b0889d8340f..c3fa4336e453 100644 --- a/platform/core-impl/src/com/intellij/util/DebugReflectionUtil.java +++ b/platform/core-impl/src/com/intellij/util/DebugReflectionUtil.java @@ -16,7 +16,9 @@ package com.intellij.util; import com.intellij.openapi.application.AccessToken; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.concurrency.AtomicFieldUpdater; import com.intellij.util.containers.FList; @@ -154,30 +156,36 @@ public class DebugReflectionUtil { @Override public String toString() { - BackLink backLink = this; - String result = ""; - while (backLink != null) { - String valueStr; - AccessToken token = ReadAction.start(); - try { - valueStr = backLink.value instanceof FList - ? "FList (size="+((FList)backLink.value).size()+")" : - backLink.value instanceof Collection ? "Collection (size="+((Collection)backLink.value).size()+")" : - String.valueOf(backLink.value); - valueStr = StringUtil.first(StringUtil.convertLineSeparators(valueStr, "\\n"), 200, true); + return + ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public String compute() { + String result = ""; + BackLink backLink = BackLink.this; + while (backLink != null) { + String valueStr; + AccessToken token = ReadAction.start(); + try { + valueStr = backLink.value instanceof FList + ? "FList (size=" + ((FList)backLink.value).size() + ")" : + backLink.value instanceof Collection ? "Collection (size=" + ((Collection)backLink.value).size() + ")" : + String.valueOf(backLink.value); + valueStr = StringUtil.first(StringUtil.convertLineSeparators(valueStr, "\\n"), 200, true); + } + catch (Throwable e) { + valueStr = "(" + e.getMessage() + " while computing .toString())"; + } + finally { + token.finish(); + } + Field field = backLink.field; + String fieldName = field == null ? "?" : field.getDeclaringClass().getName() + "." + field.getName(); + result += "via '" + fieldName + "'; Value: '" + valueStr + "' of " + backLink.value.getClass() + "\n"; + backLink = backLink.backLink; + } + return result; } - catch (Throwable e) { - valueStr = "(" + e.getMessage() + " while computing .toString())"; - } - finally { - token.finish(); - } - Field field = backLink.field; - String fieldName = field == null ? "?" : field.getDeclaringClass().getName()+"."+field.getName(); - result += "via '" + fieldName + "'; Value: '" + valueStr + "' of " + backLink.value.getClass() + "\n"; - backLink = backLink.backLink; - } - return result; + }); } } } diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java index 43af897576d1..6c699097b778 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindInProjectUtil.java @@ -23,9 +23,7 @@ import com.intellij.icons.AllIcons; import com.intellij.ide.DataManager; import com.intellij.navigation.ItemPresentation; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -403,27 +401,27 @@ public class FindInProjectUtil { public static String buildStringToFindForIndicesFromRegExp(@NotNull String stringToFind, @NotNull Project project) { if (!Registry.is("idea.regexp.search.uses.indices")) return ""; - final AccessToken accessToken = ReadAction.start(); - try { - final List topLevelRegExpChars = getTopLevelRegExpChars("a", project); - if (topLevelRegExpChars.size() != 1) return ""; + return ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public String compute() { + final List topLevelRegExpChars = getTopLevelRegExpChars("a", project); + if (topLevelRegExpChars.size() != 1) return ""; - // leave only top level regExpChars - return StringUtil.join(getTopLevelRegExpChars(stringToFind, project), new Function() { - final Class regExpCharPsiClass = topLevelRegExpChars.get(0).getClass(); + // leave only top level regExpChars + return StringUtil.join(getTopLevelRegExpChars(stringToFind, project), new Function() { + final Class regExpCharPsiClass = topLevelRegExpChars.get(0).getClass(); - @Override - public String fun(PsiElement element) { - if(regExpCharPsiClass.isInstance(element)) { - String text = element.getText(); - if (!text.startsWith("\\")) return text; + @Override + public String fun(PsiElement element) { + if (regExpCharPsiClass.isInstance(element)) { + String text = element.getText(); + if (!text.startsWith("\\")) return text; + } + return " "; } - return " "; - } - }, ""); - } finally { - accessToken.finish(); - } + }, ""); + } + }); } public static class StringUsageTarget implements ConfigurableUsageTarget, ItemPresentation, TypeSafeDataProvider { diff --git a/platform/lang-impl/src/com/intellij/ide/actions/GotoClassAction.java b/platform/lang-impl/src/com/intellij/ide/actions/GotoClassAction.java index f2f55cda1656..0d3630ea0e8d 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/GotoClassAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/GotoClassAction.java @@ -31,8 +31,7 @@ import com.intellij.navigation.AnonymousElementProvider; import com.intellij.navigation.ChooseByNameRegistry; import com.intellij.navigation.NavigationItem; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.AccessToken; -import com.intellij.openapi.application.ReadAction; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -93,39 +92,38 @@ public class GotoClassAction extends GotoActionBase implements DumbAware { @Override public void elementChosen(ChooseByNamePopup popup, Object element) { - AccessToken token = ReadAction.start(); - try { - if (element instanceof PsiElement && ((PsiElement)element).isValid()) { - PsiElement psiElement = getElement(((PsiElement)element), popup); - psiElement = psiElement.getNavigationElement(); - VirtualFile file = PsiUtilCore.getVirtualFile(psiElement); + ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override + public void run() { + if (element instanceof PsiElement && ((PsiElement)element).isValid()) { + PsiElement psiElement = getElement(((PsiElement)element), popup); + psiElement = psiElement.getNavigationElement(); + VirtualFile file = PsiUtilCore.getVirtualFile(psiElement); - if (file != null && popup.getLinePosition() != -1) { - OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition()); - Navigatable n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested()); - if (n.canNavigate()) { - n.navigate(true); - return; + if (file != null && popup.getLinePosition() != -1) { + OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition()); + Navigatable n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested()); + if (n.canNavigate()) { + n.navigate(true); + return; + } + } + + if (file != null && popup.getMemberPattern() != null) { + NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested()); + Navigatable member = findMember(popup.getMemberPattern(), psiElement, file); + if (member != null) { + member.navigate(true); + } } - } - if (file != null && popup.getMemberPattern() != null) { NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested()); - Navigatable member = findMember(popup.getMemberPattern(), psiElement, file); - if (member != null) { - member.navigate(true); - } } - - NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested()); + else { + EditSourceUtil.navigate(((NavigationItem)element), true, popup.isOpenInCurrentWindowRequested()); + } } - else { - EditSourceUtil.navigate(((NavigationItem)element), true, popup.isOpenInCurrentWindowRequested()); - } - } - finally { - token.finish(); - } + }); } }, IdeBundle.message("go.to.class.toolwindow.title"), true); } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java index fd4520054364..d249f55eec1e 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java @@ -16,9 +16,7 @@ package com.intellij.xdebugger.impl.breakpoints; import com.intellij.openapi.Disposable; -import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -401,8 +399,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta myDefaultBreakpoints.clear(); myBreakpointsDefaults.clear(); - AccessToken token = ReadAction.start(); - try { + ApplicationManager.getApplication().runReadAction(() -> { for (BreakpointState breakpointState : state.getDefaultBreakpoints()) { loadBreakpoint(breakpointState, true); } @@ -430,10 +427,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta } myDependentBreakpointManager.loadState(); - } - finally { - token.finish(); - } + }); myLineBreakpointManager.updateBreakpointsUI(); myTime = state.getTime(); myDefaultGroup = state.getDefaultGroup();