added readaction

This commit is contained in:
Alexey Kudravtsev
2014-08-15 11:22:07 +04:00
parent eb78c0fb6c
commit 1328a94f65
15 changed files with 270 additions and 123 deletions
@@ -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.
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.CodeInsightBundle;
import com.intellij.codeInsight.generation.GenerateMembersUtil;
import com.intellij.codeInsight.generation.OverrideImplementUtil;
import com.intellij.ide.util.MethodCellRenderer;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Logger;
@@ -38,6 +39,7 @@ import com.intellij.psi.util.PsiUtilCore;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.ui.components.JBList;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.*;
@@ -66,7 +68,12 @@ public class CopyAbstractMethodImplementationHandler {
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
searchExistingImplementations();
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
searchExistingImplementations();
}
});
}
}, CodeInsightBundle.message("searching.for.implementations"), false, myProject);
if (mySourceMethods.isEmpty()) {
@@ -152,7 +159,7 @@ public class CopyAbstractMethodImplementationHandler {
final List<PsiMethod> generatedMethods = new ArrayList<PsiMethod>();
new WriteCommandAction(myProject, getTargetFiles()) {
@Override
protected void run(final Result result) throws Throwable {
protected void run(@NotNull final Result result) throws Throwable {
for (PsiEnumConstant enumConstant : myTargetEnumConstants) {
PsiClass initializingClass = enumConstant.getOrCreateInitializingClass();
myTargetClasses.add(initializingClass);
@@ -186,7 +193,7 @@ public class CopyAbstractMethodImplementationHandler {
}
}
}.execute();
if (generatedMethods.size() > 0) {
if (!generatedMethods.isEmpty()) {
PsiMethod target = generatedMethods.get(0);
PsiFile psiFile = target.getContainingFile();
FileEditorManager fileEditorManager = FileEditorManager.getInstance(psiFile.getProject());
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 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.
@@ -96,7 +96,7 @@ public class ReplaceImplementsWithStaticImportAction extends BaseIntentionAction
JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(project));
if (objectClass == null) return false;
methods.removeAll(Arrays.asList(objectClass.getMethods()));
if (methods.size() > 0) return false;
if (!methods.isEmpty()) return false;
}
else if (targetClass.getMethods().length > 0) {
return false;
@@ -122,7 +122,7 @@ public class ReplaceImplementsWithStaticImportAction extends BaseIntentionAction
final PsiClass targetClass = (PsiClass)target;
new WriteCommandAction(project, getText()) {
@Override
protected void run(Result result) throws Throwable {
protected void run(@NotNull Result result) throws Throwable {
for (PsiField constField : targetClass.getAllFields()) {
final String fieldName = constField.getName();
final PsiClass containingClass = constField.getContainingClass();
@@ -159,30 +159,35 @@ public class ReplaceImplementsWithStaticImportAction extends BaseIntentionAction
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
for (PsiField field : targetClass.getAllFields()) {
final PsiClass containingClass = field.getContainingClass();
for (PsiReference reference : ReferencesSearch.search(field)) {
if (reference == null) {
continue;
}
final PsiElement refElement = reference.getElement();
if (encodeQualifier(containingClass, reference, targetClass)) continue;
final PsiFile psiFile = refElement.getContainingFile();
if (psiFile instanceof PsiJavaFile) {
Map<PsiField, Set<PsiReference>> references = refs.get(psiFile);
if (references == null) {
references = new HashMap<PsiField, Set<PsiReference>>();
refs.put(psiFile, references);
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
for (PsiField field : targetClass.getAllFields()) {
final PsiClass containingClass = field.getContainingClass();
for (PsiReference reference : ReferencesSearch.search(field)) {
if (reference == null) {
continue;
}
final PsiElement refElement = reference.getElement();
if (encodeQualifier(containingClass, reference, targetClass)) continue;
final PsiFile psiFile = refElement.getContainingFile();
if (psiFile instanceof PsiJavaFile) {
Map<PsiField, Set<PsiReference>> references = refs.get(psiFile);
if (references == null) {
references = new HashMap<PsiField, Set<PsiReference>>();
refs.put(psiFile, references);
}
Set<PsiReference> fieldsRefs = references.get(field);
if (fieldsRefs == null) {
fieldsRefs = new HashSet<PsiReference>();
references.put(field, fieldsRefs);
}
fieldsRefs.add(reference);
}
}
Set<PsiReference> fieldsRefs = references.get(field);
if (fieldsRefs == null) {
fieldsRefs = new HashSet<PsiReference>();
references.put(field, fieldsRefs);
}
fieldsRefs.add(reference);
}
}
}
});
}
}, FIND_CONSTANT_FIELD_USAGES, true, project)) {
return;
@@ -192,14 +197,19 @@ public class ReplaceImplementsWithStaticImportAction extends BaseIntentionAction
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
for (PsiClass psiClass : DirectClassInheritorsSearch.search(targetClass)) {
PsiFile containingFile = psiClass.getContainingFile();
if (!refs.containsKey(containingFile)) {
refs.put(containingFile, new HashMap<PsiField, Set<PsiReference>>());
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
for (PsiClass psiClass : DirectClassInheritorsSearch.search(targetClass)) {
PsiFile containingFile = psiClass.getContainingFile();
if (!refs.containsKey(containingFile)) {
refs.put(containingFile, new HashMap<PsiField, Set<PsiReference>>());
}
if (collectExtendsImplements(targetClass, psiClass.getExtendsList(), refs2Unimplement)) continue;
collectExtendsImplements(targetClass, psiClass.getImplementsList(), refs2Unimplement);
}
}
if (collectExtendsImplements(targetClass, psiClass.getExtendsList(), refs2Unimplement)) continue;
collectExtendsImplements(targetClass, psiClass.getImplementsList(), refs2Unimplement);
}
});
}
}, "Find references in implement/extends lists...", true, project)) {
return;
@@ -232,14 +242,19 @@ public class ReplaceImplementsWithStaticImportAction extends BaseIntentionAction
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable(){
@Override
public void run() {
for (PsiFile psiFile : refs.keySet()) {
final Collection<PsiImportStatementBase> red = codeStyleManager.findRedundantImports((PsiJavaFile)psiFile);
if (red != null) {
for (PsiImportStatementBase statementBase : red) {
redundant.add(pointerManager.createSmartPsiElementPointer(statementBase));
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
for (PsiFile psiFile : refs.keySet()) {
final Collection<PsiImportStatementBase> red = codeStyleManager.findRedundantImports((PsiJavaFile)psiFile);
if (red != null) {
for (PsiImportStatementBase statementBase : red) {
redundant.add(pointerManager.createSmartPsiElementPointer(statementBase));
}
}
}
}
}
});
}
}, "Collect redundant imports...", true, project)) return;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@@ -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.
@@ -59,6 +59,7 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
private Project myProject;
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
int offset = editor.getCaretModel().getOffset();
@@ -77,6 +78,7 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
}
}
@Override
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
if (elements.length != 1) return;
@@ -101,6 +103,7 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
final List<MemberInfo> memberInfos = MemberInfo.extractClassMembers(mySubclass, new MemberInfo.Filter<PsiMember>() {
@Override
public boolean includeMember(PsiMember element) {
return true;
}
@@ -112,8 +115,10 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
if (!dialog.isOK() || !dialog.isExtractSuperclass()) return;
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
@Override
public void run() {
final Runnable action = new Runnable() {
@Override
public void run() {
doRefactoring(project, mySubclass, dialog);
}
@@ -124,6 +129,7 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
}
@Override
public boolean checkConflicts(final ExtractSuperclassDialog dialog) {
final MemberInfo[] infos = ArrayUtil.toObjectArray(dialog.getSelectedMemberInfos(), MemberInfo.class);
final PsiDirectory targetDirectory = dialog.getTargetDirectory();
@@ -136,9 +142,17 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
}
final MultiMap<PsiElement,String> conflicts = new MultiMap<PsiElement, String>();
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
final PsiClass superClass = mySubclass.getExtendsListTypes().length > 0 || mySubclass instanceof PsiAnonymousClass ? mySubclass.getSuperClass() : null;
conflicts.putAllValues(PullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, targetPackage, targetDirectory, dialog.getContainmentVerifier(), false));
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
final PsiClass superClass =
mySubclass.getExtendsListTypes().length > 0 || mySubclass instanceof PsiAnonymousClass ? mySubclass.getSuperClass() : null;
conflicts.putAllValues(PullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, targetPackage, targetDirectory,
dialog.getContainmentVerifier(), false));
}
});
}
}, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) return false;
ExtractSuperClassUtil.checkSuperAccessible(targetDirectory, conflicts, mySubclass);
@@ -168,6 +182,7 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
final SmartPsiElementPointer<PsiClass> classPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(subclass);
final SmartPsiElementPointer<PsiClass> interfacePointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(superclass);
final Runnable turnRefsToSuperRunnable = new Runnable() {
@Override
public void run() {
ExtractClassUtil.askAndTurnRefsToSuper(project, classPointer, interfacePointer);
}
@@ -185,6 +200,7 @@ public class ExtractSuperclassHandler implements RefactoringActionHandler, Extra
return RefactoringBundle.message("extract.superclass.command.name", newName, DescriptiveNameUtil.getDescriptiveName(subclass));
}
@Override
public boolean isEnabledOnElements(PsiElement[] elements) {
return elements.length == 1 && elements[0] instanceof PsiClass && !((PsiClass) elements[0]).isInterface()
&&!((PsiClass)elements[0]).isEnum();
@@ -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.
@@ -17,6 +17,7 @@ package com.intellij.refactoring.inline;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.lang.StdLanguages;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
@@ -35,10 +36,12 @@ import com.intellij.refactoring.util.CommonRefactoringUtil;
public class InlineConstantFieldHandler extends JavaInlineActionHandler {
private static final String REFACTORING_NAME = RefactoringBundle.message("inline.field.title");
@Override
public boolean canInlineElement(PsiElement element) {
return element instanceof PsiField && StdLanguages.JAVA.equals(element.getLanguage());
}
@Override
public void inlineElement(Project project, Editor editor, PsiElement element) {
final PsiElement navigationElement = element.getNavigationElement();
final PsiField field = (PsiField)(navigationElement instanceof PsiField ? navigationElement : element);
@@ -66,13 +69,18 @@ public class InlineConstantFieldHandler extends JavaInlineActionHandler {
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
for (PsiReference reference : ReferencesSearch.search(field)) {
final PsiElement referenceElement = reference.getElement();
if (!(referenceElement instanceof PsiExpression && PsiUtil.isAccessedForReading((PsiExpression)referenceElement))) {
hasWriteUsages.set(true);
break;
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
for (PsiReference reference : ReferencesSearch.search(field)) {
final PsiElement referenceElement = reference.getElement();
if (!(referenceElement instanceof PsiExpression && PsiUtil.isAccessedForReading((PsiExpression)referenceElement))) {
hasWriteUsages.set(true);
break;
}
}
}
}
});
}
}, "Check if inline is possible...", true, project)) {
return;
@@ -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.
@@ -91,7 +91,7 @@ public class InlineToAnonymousClassHandler extends JavaInlineActionHandler {
});
}
}, "Searching for class \"" + element.getQualifiedName() + "\" inheritors ...", true, element.getProject())) return false;
return inheritors.size() == 0;
return inheritors.isEmpty();
}
@Override
@@ -124,7 +124,12 @@ public class InlineToAnonymousClassHandler extends JavaInlineActionHandler {
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable(){
@Override
public void run() {
errorMessage.set(getCannotInlineMessage(psiClass));
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
errorMessage.set(getCannotInlineMessage(psiClass));
}
});
}
}, "Check if inline is possible...", true, project)) return;
if (errorMessage.get() != null) {
@@ -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.
@@ -26,6 +26,7 @@ package com.intellij.refactoring.memberPullUp;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ScrollType;
@@ -55,6 +56,7 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
private PsiClass mySubclass;
private Project myProject;
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
int offset = editor.getCaretModel().getOffset();
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
@@ -78,6 +80,7 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
}
}
@Override
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
if (elements.length != 1) return;
myProject = project;
@@ -130,6 +133,7 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
mySubclass = aClass;
MemberInfoStorage memberInfoStorage = new MemberInfoStorage(mySubclass, new MemberInfo.Filter<PsiMember>() {
@Override
public boolean includeMember(PsiMember element) {
return true;
}
@@ -152,6 +156,7 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
@Override
public boolean checkConflicts(final PullUpDialog dialog) {
final List<MemberInfo> infos = dialog.getSelectedMemberInfos();
final MemberInfo[] memberInfos = infos.toArray(new MemberInfo[infos.size()]);
@@ -159,11 +164,18 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
if (!checkWritable(superClass, memberInfos)) return false;
final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
conflicts
.putAllValues(PullUpConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass, targetPackage, targetDirectory, dialog.getContainmentVerifier()));
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
conflicts
.putAllValues(PullUpConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass, targetPackage, targetDirectory, dialog.getContainmentVerifier()));
}
});
}
}, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) return false;
if (!conflicts.isEmpty()) {
@@ -185,6 +197,7 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
return true;
}
@Override
public boolean isEnabledOnElements(PsiElement[] elements) {
/*
if (elements.length == 1) {
@@ -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.
@@ -68,7 +68,7 @@ public class PullUpProcessor extends BaseRefactoringProcessor implements PullUpD
private final DocCommentPolicy myJavaDocPolicy;
private Set<PsiMember> myMembersAfterMove = null;
private Set<PsiMember> myMovedMembers = null;
private Map<Language, PullUpHelper<MemberInfo>> myProcessors = ContainerUtil.newHashMap();
private final Map<Language, PullUpHelper<MemberInfo>> myProcessors = ContainerUtil.newHashMap();
public PullUpProcessor(PsiClass sourceClass, PsiClass targetSuperClass, MemberInfo[] membersToMove, DocCommentPolicy javaDocPolicy) {
super(sourceClass.getProject());
@@ -78,11 +78,13 @@ public class PullUpProcessor extends BaseRefactoringProcessor implements PullUpD
myJavaDocPolicy = javaDocPolicy;
}
@Override
@NotNull
protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) {
return new PullUpUsageViewDescriptor();
}
@Override
@NotNull
protected UsageInfo[] findUsages() {
final List<UsageInfo> result = new ArrayList<UsageInfo>();
@@ -125,6 +127,7 @@ public class PullUpProcessor extends BaseRefactoringProcessor implements PullUpD
return data;
}
@Override
protected void performRefactoring(UsageInfo[] usages) {
moveMembersToBase();
moveFieldInitializations();
@@ -148,29 +151,35 @@ public class PullUpProcessor extends BaseRefactoringProcessor implements PullUpD
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
final Query<PsiClass> search = ClassInheritorsSearch.search(myTargetSuperClass);
final Set<VirtualFile> hierarchyFiles = new HashSet<VirtualFile>();
for (PsiClass aClass : search) {
final PsiFile containingFile = aClass.getContainingFile();
if (containingFile != null) {
final VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile != null) {
hierarchyFiles.add(virtualFile);
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
final Query<PsiClass> search = ClassInheritorsSearch.search(myTargetSuperClass);
final Set<VirtualFile> hierarchyFiles = new HashSet<VirtualFile>();
for (PsiClass aClass : search) {
final PsiFile containingFile = aClass.getContainingFile();
if (containingFile != null) {
final VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile != null) {
hierarchyFiles.add(virtualFile);
}
}
}
final Set<PsiMember> methodsToSearchDuplicates = new HashSet<PsiMember>();
for (PsiMember psiMember : myMembersAfterMove) {
if (psiMember instanceof PsiMethod && psiMember.isValid() && ((PsiMethod)psiMember).getBody() != null) {
methodsToSearchDuplicates.add(psiMember);
}
}
}
}
final Set<PsiMember> methodsToSearchDuplicates = new HashSet<PsiMember>();
for (PsiMember psiMember : myMembersAfterMove) {
if (psiMember instanceof PsiMethod && psiMember.isValid() && ((PsiMethod)psiMember).getBody() != null) {
methodsToSearchDuplicates.add(psiMember);
}
}
MethodDuplicatesHandler.invokeOnScope(myProject, methodsToSearchDuplicates, new AnalysisScope(myProject, hierarchyFiles), true);
MethodDuplicatesHandler.invokeOnScope(myProject, methodsToSearchDuplicates, new AnalysisScope(myProject, hierarchyFiles), true);
}
});
}
}, MethodDuplicatesHandler.REFACTORING_NAME, true, myProject);
}
@Override
protected String getCommandName() {
return RefactoringBundle.message("pullUp.command", DescriptiveNameUtil.getDescriptiveName(mySourceClass));
}
@@ -303,19 +312,23 @@ public class PullUpProcessor extends BaseRefactoringProcessor implements PullUpD
}
private class PullUpUsageViewDescriptor implements UsageViewDescriptor {
@Override
public String getProcessedElementsHeader() {
return "Pull up members from";
}
@Override
@NotNull
public PsiElement[] getElements() {
return new PsiElement[]{mySourceClass};
}
@Override
public String getCodeReferencesText(int usagesCount, int filesCount) {
return "Class to pull up members to \"" + RefactoringUIUtil.getDescription(myTargetSuperClass, true) + "\"";
}
@Override
public String getCommentReferencesText(int usagesCount, int filesCount) {
return null;
}
@@ -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.
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.ChangeContextUtil;
import com.intellij.codeInsight.intention.impl.CreateClassDialog;
import com.intellij.codeInsight.intention.impl.CreateSubclassAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
@@ -72,10 +73,12 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
myJavaDocPolicy = javaDocPolicy;
}
@Override
protected String getCommandName() {
return JavaPushDownHandler.REFACTORING_NAME;
}
@Override
@NotNull
protected UsageViewDescriptor createUsageViewDescriptor(UsageInfo[] usages) {
return new PushDownUsageViewDescriptor(myClass);
@@ -116,6 +119,7 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
return data;
}
@Override
@NotNull
protected UsageInfo[] findUsages() {
final PsiClass[] inheritors = ClassInheritorsSearch.search(myClass, false).toArray(PsiClass.EMPTY_ARRAY);
@@ -147,6 +151,7 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
return false;
}
@Override
protected boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) {
final UsageInfo[] usagesIn = refUsages.get();
final PushDownConflicts pushDownConflicts = new PushDownConflicts(myClass, myMemberInfos);
@@ -177,13 +182,19 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
}
}
Runnable runnable = new Runnable() {
@Override
public void run() {
for (UsageInfo usage : usagesIn) {
final PsiElement element = usage.getElement();
if (element instanceof PsiClass) {
pushDownConflicts.checkTargetClassConflicts((PsiClass)element, usagesIn.length > 1, element);
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
for (UsageInfo usage : usagesIn) {
final PsiElement element = usage.getElement();
if (element instanceof PsiClass) {
pushDownConflicts.checkTargetClassConflicts((PsiClass)element, usagesIn.length > 1, element);
}
}
}
}
});
}
};
@@ -204,6 +215,7 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
return showConflicts(pushDownConflicts.getConflicts(), usagesIn);
}
@Override
protected void refreshElements(PsiElement[] elements) {
if(elements.length == 1 && elements[0] instanceof PsiClass) {
myClass = (PsiClass) elements[0];
@@ -213,6 +225,7 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
}
}
@Override
protected void performRefactoring(UsageInfo[] usages) {
try {
encodeRefs();
@@ -509,6 +522,7 @@ public class PushDownProcessor extends BaseRefactoringProcessor {
decodeRefs(newMember, targetClass);
//rebind imports first
Collections.sort(refsToRebind, new Comparator<PsiReference>() {
@Override
public int compare(PsiReference o1, PsiReference o2) {
return PsiUtil.BY_POSITION.compare(o1.getElement(), o2.getElement());
}
@@ -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.
@@ -88,7 +88,7 @@ public class MoveClassesOrPackagesImpl {
if (element instanceof PsiDirectory) {
PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory)element);
LOG.assertTrue(aPackage != null);
if (aPackage.getQualifiedName().length() == 0) { //is default package
if (aPackage.getQualifiedName().isEmpty()) { //is default package
String message = RefactoringBundle.message("move.package.refactoring.cannot.be.applied.to.default.package");
CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("move.title"), message, HelpID.getMoveHelpID(element), project);
return null;
@@ -167,7 +167,7 @@ public class MoveClassesOrPackagesImpl {
message.append(RefactoringBundle.message("do.you.wish.to.continue"));
int ret =
Messages.showYesNoDialog(project, message.toString(), RefactoringBundle.message("warning.title"), Messages.getWarningIcon());
if (ret != 0) {
if (ret != Messages.YES) {
return false;
}
}
@@ -323,8 +323,15 @@ public class MoveClassesOrPackagesImpl {
if (selectedTarget == null) return;
final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
final Runnable analyzeConflicts = new Runnable() {
@Override
public void run() {
RefactoringConflictsUtil.analyzeModuleConflicts(project, Arrays.asList(directories), UsageInfo.EMPTY_ARRAY, selectedTarget, conflicts);
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
RefactoringConflictsUtil
.analyzeModuleConflicts(project, Arrays.asList(directories), UsageInfo.EMPTY_ARRAY, selectedTarget, conflicts);
}
});
}
};
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(analyzeConflicts, "Analyze Module Conflicts...", true, project)) {
@@ -345,8 +352,10 @@ public class MoveClassesOrPackagesImpl {
final Ref<IncorrectOperationException> ex = Ref.create(null);
final String commandDescription = RefactoringBundle.message("moving.directories.command");
Runnable runnable = new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
LocalHistoryAction a = LocalHistory.getInstance().startAction(commandDescription);
try {
@@ -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.
@@ -69,6 +69,7 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces
private final String mySuperClassName;
private final List<UsageInfo> myVariablesUsages = new ArrayList<UsageInfo>();
@Override
protected boolean preprocessUsages(Ref<UsageInfo[]> refUsages) {
UsageInfo[] usages = refUsages.get();
List<UsageInfo> filtered = new ArrayList<UsageInfo>();
@@ -93,8 +94,14 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces
}
Runnable runnable = new Runnable() {
@Override
public void run() {
myVariableRenamer.findUsages(myVariablesUsages, false, false);
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
myVariableRenamer.findUsages(myVariablesUsages, false, false);
}
});
}
};
@@ -338,6 +345,7 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces
if (substitutor == null) return;
final LocalSearchScope baseScope = new LocalSearchScope(ownerClass);
ReferencesSearch.search(typeParameter, baseScope).forEach(new Processor<PsiReference>() {
@Override
public boolean process(final PsiReference ref) {
final PsiElement element = ref.getElement();
final PsiElement parent = element.getParent();
@@ -708,6 +716,7 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces
}
class Colorer implements OneEndFunctor {
@Override
public Mark compute(Mark from, Mark edge, Mark to) {
VisitMark mark = new VisitMark((VisitMark)to);
@@ -737,6 +746,7 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces
private boolean myVisited;
private final PsiElement myElement;
@Override
public boolean coincidesWith(Mark x) {
return ((VisitMark)x).myVisited == myVisited;
}
@@ -773,10 +783,12 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces
myMark = new VisitMark(x);
}
@Override
public Mark getMark() {
return myMark;
}
@Override
public void setMark(Mark x) {
myMark = (VisitMark)x;
}
@@ -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.
@@ -178,8 +178,13 @@ public class SliceNullnessAnalyzer {
node(element, map).add(node(duplicate, map));
}
else {
SliceUsage sliceUsage = element.getValue();
final PsiElement value = sliceUsage.getElement();
final SliceUsage sliceUsage = element.getValue();
final PsiElement value = ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {
@Override
public PsiElement compute() {
return sliceUsage.getElement();
}
});
Nullness nullness = ApplicationManager.getApplication().runReadAction(new Computable<Nullness>() {
@Override
public Nullness compute() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 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.
@@ -15,6 +15,7 @@
*/
package com.intellij.refactoring.changeSignature;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Iconable;
@@ -88,7 +89,12 @@ public abstract class MethodNodeBase<M extends PsiElement> extends CheckedTreeNo
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
callers.set(computeCallers());
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
callers.set(computeCallers());
}
});
}
}, RefactoringBundle.message("caller.chooser.looking.for.callers"), true, myProject)) {
myCancelCallback.run();
@@ -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.
@@ -22,7 +22,7 @@ package com.intellij.tools;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.progress.ProgressIndicator;
@@ -107,19 +107,24 @@ public class ScanSourceCommentsAction extends AnAction {
descriptor.addFile(file);
}
private void scanCommentsInFile(Project project, final VirtualFile vFile) {
private void scanCommentsInFile(final Project project, final VirtualFile vFile) {
if (!vFile.isDirectory() && vFile.getFileType() instanceof LanguageFileType) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
if (psiFile == null) return;
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
if (psiFile == null) return;
for (PsiFile root : psiFile.getViewProvider().getAllFiles()) {
root.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitComment(PsiComment comment) {
commentFound(vFile, comment.getText());
for (PsiFile root : psiFile.getViewProvider().getAllFiles()) {
root.accept(new PsiRecursiveElementWalkingVisitor() {
@Override
public void visitComment(PsiComment comment) {
commentFound(vFile, comment.getText());
}
});
}
});
}
}
});
}
}
@@ -23,6 +23,7 @@ import com.intellij.codeInsight.daemon.impl.PsiElementListNavigator;
import com.intellij.codeInsight.navigation.ListBackgroundUpdaterTask;
import com.intellij.ide.util.MethodCellRenderer;
import com.intellij.ide.util.PsiElementListCellRenderer;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadActionProcessor;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
@@ -159,9 +160,14 @@ public class GroovyMarkerTypes {
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
for (GrAccessorMethod method : GroovyPropertyUtils.getFieldAccessors(field)) {
OverridingMethodsSearch.search(method, true).forEach(collectProcessor);
}
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
for (GrAccessorMethod method : GroovyPropertyUtils.getFieldAccessors(field)) {
OverridingMethodsSearch.search(method, true).forEach(collectProcessor);
}
}
});
}
}, "Searching for overriding methods", true, field.getProject(), (JComponent)e.getComponent())) {
return;
@@ -272,17 +278,22 @@ public class GroovyMarkerTypes {
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
for (GrMethod m : PsiImplUtil.getMethodOrReflectedMethods(method)) {
OverridingMethodsSearch.search(m, true).forEach(new ReadActionProcessor<PsiMethod>() {
@Override
public boolean processInReadAction(PsiMethod psiMethod) {
if (psiMethod instanceof GrReflectedMethod) {
psiMethod = ((GrReflectedMethod)psiMethod).getBaseMethod();
}
return collectProcessor.execute(psiMethod);
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
for (GrMethod m : PsiImplUtil.getMethodOrReflectedMethods(method)) {
OverridingMethodsSearch.search(m, true).forEach(new ReadActionProcessor<PsiMethod>() {
@Override
public boolean processInReadAction(PsiMethod psiMethod) {
if (psiMethod instanceof GrReflectedMethod) {
psiMethod = ((GrReflectedMethod)psiMethod).getBaseMethod();
}
return collectProcessor.execute(psiMethod);
}
});
}
});
}
}
});
}
}, MarkerType.SEARCHING_FOR_OVERRIDING_METHODS, true, method.getProject(), (JComponent)e.getComponent())) {
return;
@@ -17,6 +17,7 @@ package org.jetbrains.plugins.groovy.refactoring.memberPullUp;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ScrollType;
@@ -170,9 +171,16 @@ public class GrPullUpHandler implements RefactoringActionHandler, GrPullUpDialog
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
conflicts.putAllValues(GrPullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, targetPackage, targetDirectory, dialog.getContainmentVerifier()));
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
final PsiPackage targetPackage =
targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
conflicts.putAllValues(GrPullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, targetPackage, targetDirectory,
dialog.getContainmentVerifier()));
}
});
}
}, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) {
return false;