mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
read action
This commit is contained in:
@@ -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<PsiClass>() {
|
||||
@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<PsiClass[]>() {
|
||||
@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<PsiReference>() {
|
||||
@Override
|
||||
public boolean process(PsiReference reference) {
|
||||
|
||||
+13
-7
@@ -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<PsiMember, Set<Module>> memberWithModulesMap = new HashMap<PsiMember, Set<Module>>();
|
||||
for (PsiMember member : members) {
|
||||
final Module module = ModuleUtil.findModuleForPsiElement(member);
|
||||
for (final PsiMember member : members) {
|
||||
final Module module = ApplicationManager.getApplication().runReadAction(new Computable<Module>() {
|
||||
@Override
|
||||
public Module compute() {
|
||||
return ModuleUtilCore.findModuleForPsiElement(member);
|
||||
}
|
||||
});
|
||||
if (module != null) {
|
||||
final HashSet<Module> dependencies = new HashSet<Module>();
|
||||
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<PsiMember, Set<Module>> entry : memberWithModulesMap.entrySet()) {
|
||||
final Set<Module> dependencies = entry.getValue();
|
||||
|
||||
@@ -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<SliceNode> walkingState = new WalkingState<SliceNode>(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<? extends AbstractTreeNode> children = element.getChildren();
|
||||
if (children.isEmpty()) {
|
||||
PsiElement value = ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {
|
||||
@Override
|
||||
public PsiElement compute() {
|
||||
return sliceUsage.indexNesting == 0 ? sliceUsage.getElement() : null;
|
||||
Collection<? extends AbstractTreeNode> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class SliceNullnessAnalyzer {
|
||||
final SliceLeafAnalyzer.SliceNodeGuide guide = new SliceLeafAnalyzer.SliceNodeGuide(treeStructure);
|
||||
WalkingState<SliceNode> walkingState = new WalkingState<SliceNode>(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<PsiElement>() {
|
||||
@Override
|
||||
public PsiElement compute() {
|
||||
return sliceUsage.getElement();
|
||||
return element.getValue().getElement();
|
||||
}
|
||||
});
|
||||
Nullness nullness = ApplicationManager.getApplication().runReadAction(new Computable<Nullness>() {
|
||||
@@ -198,7 +197,13 @@ public class SliceNullnessAnalyzer {
|
||||
group(element, map, NullAnalysisResult.NOT_NULLS).add(value);
|
||||
}
|
||||
else {
|
||||
Collection<? extends AbstractTreeNode> children = element.getChildren();
|
||||
Collection<? extends AbstractTreeNode> children = ApplicationManager.getApplication().runReadAction(
|
||||
new Computable<Collection<? extends AbstractTreeNode>>() {
|
||||
@Override
|
||||
public Collection<? extends AbstractTreeNode> compute() {
|
||||
return element.getChildren();
|
||||
}
|
||||
});
|
||||
if (children.isEmpty()) {
|
||||
group(element, map, NullAnalysisResult.UNKNOWNS).add(value);
|
||||
}
|
||||
|
||||
+24
-7
@@ -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<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
return namedElem instanceof GrField && ((GrField)namedElem).isProperty();
|
||||
}
|
||||
});
|
||||
if (isProperty) {
|
||||
final GrAccessorMethod[] getters = ApplicationManager.getApplication().runReadAction(new Computable<GrAccessorMethod[]>() {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user