From 81b47cefd9691ff5342d18656290c2dfc13ab291 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 22 Aug 2014 14:33:52 +0400 Subject: [PATCH] read action --- .../internal/StaticIconFieldsAction.java | 33 +++++++++++++++---- .../duplicates/MethodDuplicatesHandler.java | 20 +++++++---- .../intellij/slicer/SliceLeafAnalyzer.java | 27 +++++++-------- .../slicer/SliceNullnessAnalyzer.java | 13 +++++--- .../ConvertParameterToMapEntryIntention.java | 31 +++++++++++++---- 5 files changed, 86 insertions(+), 38 deletions(-) diff --git a/java/java-impl/src/com/intellij/internal/StaticIconFieldsAction.java b/java/java-impl/src/com/intellij/internal/StaticIconFieldsAction.java index 2864db6608e6..7fae15f159b7 100644 --- a/java/java-impl/src/com/intellij/internal/StaticIconFieldsAction.java +++ b/java/java-impl/src/com/intellij/internal/StaticIconFieldsAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,12 @@ package com.intellij.internal; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.LangDataKeys; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.searches.ReferencesSearch; @@ -49,19 +51,36 @@ public class StaticIconFieldsAction extends AnAction { ProgressManager.getInstance().run(new Task.Backgroundable(project, "Searching icons usages") { @Override public void run(@NotNull ProgressIndicator indicator) { - JavaPsiFacade facade = JavaPsiFacade.getInstance(project); - GlobalSearchScope all = GlobalSearchScope.allScope(project); - PsiClass allIcons = facade.findClass("com.intellij.icons.AllIcons", all); + final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); + final GlobalSearchScope all = GlobalSearchScope.allScope(project); + PsiClass allIcons = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public PsiClass compute() { + return facade.findClass("com.intellij.icons.AllIcons", all); + } + }); searchFields(allIcons, view, indicator); - for (PsiClass iconsClass : facade.findPackage("icons").getClasses(all)) { + PsiClass[] classes = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public PsiClass[] compute() { + return facade.findPackage("icons").getClasses(all); + } + }); + for (PsiClass iconsClass : classes) { searchFields(iconsClass, view, indicator); } } }); } - private static void searchFields(PsiClass allIcons, final UsageView view, ProgressIndicator indicator) { - indicator.setText("Searching for: " + allIcons.getQualifiedName()); + private static void searchFields(final PsiClass allIcons, final UsageView view, final ProgressIndicator indicator) { + ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override + public void run() { + indicator.setText("Searching for: " + allIcons.getQualifiedName()); + } + }); + ReferencesSearch.search(allIcons).forEach(new Processor() { @Override public boolean process(PsiReference reference) { diff --git a/java/java-impl/src/com/intellij/refactoring/util/duplicates/MethodDuplicatesHandler.java b/java/java-impl/src/com/intellij/refactoring/util/duplicates/MethodDuplicatesHandler.java index 876617b516e4..4bd3d6db70a5 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/duplicates/MethodDuplicatesHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/util/duplicates/MethodDuplicatesHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,13 +28,14 @@ import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.WindowManager; import com.intellij.psi.*; @@ -71,7 +72,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler { } final AnalysisScope scope = new AnalysisScope(file); - final Module module = ModuleUtil.findModuleForPsiElement(file); + final Module module = ModuleUtilCore.findModuleForPsiElement(file); final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog(RefactoringBundle.message("replace.method.duplicates.scope.chooser.title", REFACTORING_NAME), RefactoringBundle.message("replace.method.duplicates.scope.chooser.message"), project, scope, module != null ? module.getName() : null, false, @@ -134,13 +135,18 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler { } final Map> memberWithModulesMap = new HashMap>(); - for (PsiMember member : members) { - final Module module = ModuleUtil.findModuleForPsiElement(member); + for (final PsiMember member : members) { + final Module module = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public Module compute() { + return ModuleUtilCore.findModuleForPsiElement(member); + } + }); if (module != null) { final HashSet dependencies = new HashSet(); ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { - ModuleUtil.collectModulesDependsOn(module, dependencies); + ModuleUtilCore.collectModulesDependsOn(module, dependencies); } }); memberWithModulesMap.put(member, dependencies); @@ -158,7 +164,7 @@ public class MethodDuplicatesHandler implements RefactoringActionHandler { progressIndicator.setText2(ProjectUtil.calcRelativeToProjectPath(virtualFile, project)); } } - final Module targetModule = ModuleUtil.findModuleForPsiElement(file); + final Module targetModule = ModuleUtilCore.findModuleForPsiElement(file); if (targetModule == null) return; for (Map.Entry> entry : memberWithModulesMap.entrySet()) { final Set dependencies = entry.getValue(); diff --git a/java/java-impl/src/com/intellij/slicer/SliceLeafAnalyzer.java b/java/java-impl/src/com/intellij/slicer/SliceLeafAnalyzer.java index d59129174520..a08464fbd7ce 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceLeafAnalyzer.java +++ b/java/java-impl/src/com/intellij/slicer/SliceLeafAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -244,7 +244,7 @@ public class SliceLeafAnalyzer { final SliceNodeGuide guide = new SliceNodeGuide(treeStructure); WalkingState walkingState = new WalkingState(guide) { @Override - public void visit(@NotNull SliceNode element) { + public void visit(@NotNull final SliceNode element) { element.calculateDupNode(); node(element, map).clear(); SliceNode duplicate = element.getDuplicate(); @@ -252,20 +252,21 @@ public class SliceLeafAnalyzer { node(element, map).addAll(node(duplicate, map)); } else { - final SliceUsage sliceUsage = element.getValue(); + ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override + public void run() { + final SliceUsage sliceUsage = element.getValue(); - Collection children = element.getChildren(); - if (children.isEmpty()) { - PsiElement value = ApplicationManager.getApplication().runReadAction(new Computable() { - @Override - public PsiElement compute() { - return sliceUsage.indexNesting == 0 ? sliceUsage.getElement() : null; + Collection children = element.getChildren(); + if (children.isEmpty()) { + PsiElement value = sliceUsage.indexNesting == 0 ? sliceUsage.getElement() : null; + if (value != null) { + node(element, map).addAll(ContainerUtil.singleton(value, LEAF_ELEMENT_EQUALITY)); + } } - }); - if (value != null) { - node(element, map).addAll(ContainerUtil.singleton(value, LEAF_ELEMENT_EQUALITY)); } - } + }); + super.visit(element); } } diff --git a/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java b/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java index b65932aeaa81..ba6f8602ba46 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java +++ b/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java @@ -170,7 +170,7 @@ public class SliceNullnessAnalyzer { final SliceLeafAnalyzer.SliceNodeGuide guide = new SliceLeafAnalyzer.SliceNodeGuide(treeStructure); WalkingState walkingState = new WalkingState(guide) { @Override - public void visit(@NotNull SliceNode element) { + public void visit(@NotNull final SliceNode element) { element.calculateDupNode(); node(element, map).clear(); SliceNode duplicate = element.getDuplicate(); @@ -178,11 +178,10 @@ public class SliceNullnessAnalyzer { node(element, map).add(node(duplicate, map)); } else { - final SliceUsage sliceUsage = element.getValue(); final PsiElement value = ApplicationManager.getApplication().runReadAction(new Computable() { @Override public PsiElement compute() { - return sliceUsage.getElement(); + return element.getValue().getElement(); } }); Nullness nullness = ApplicationManager.getApplication().runReadAction(new Computable() { @@ -198,7 +197,13 @@ public class SliceNullnessAnalyzer { group(element, map, NullAnalysisResult.NOT_NULLS).add(value); } else { - Collection children = element.getChildren(); + Collection children = ApplicationManager.getApplication().runReadAction( + new Computable>() { + @Override + public Collection compute() { + return element.getChildren(); + } + }); if (children.isEmpty()) { group(element, map, NullAnalysisResult.UNKNOWNS).add(value); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ConvertParameterToMapEntryIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ConvertParameterToMapEntryIntention.java index 318db55df11b..befb360e5885 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ConvertParameterToMapEntryIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/parameterToEntry/ConvertParameterToMapEntryIntention.java @@ -23,6 +23,7 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -459,17 +460,33 @@ public class ConvertParameterToMapEntryIntention extends Intention { } }; ReferencesSearch.search(namedElem).forEach(consumer); - if (namedElem instanceof GrField && ((GrField)namedElem).isProperty()) { - final GrAccessorMethod[] getters = ((GrField)namedElem).getGetters(); + boolean isProperty = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public Boolean compute() { + return namedElem instanceof GrField && ((GrField)namedElem).isProperty(); + } + }); + if (isProperty) { + final GrAccessorMethod[] getters = ApplicationManager.getApplication().runReadAction(new Computable() { + @Override + public GrAccessorMethod[] compute() { + return ((GrField)namedElem).getGetters(); + } + }); for (GrAccessorMethod getter : getters) { MethodReferencesSearch.search(getter).forEach(consumer); } } - for (PsiReference reference : references) { - final PsiElement element = reference.getElement(); - if (element != null) { - occurrences.add(element); - } + for (final PsiReference reference : references) { + ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override + public void run() { + final PsiElement element = reference.getElement(); + if (element != null) { + occurrences.add(element); + } + } + }); } }