diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CopyAbstractMethodImplementationHandler.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CopyAbstractMethodImplementationHandler.java index ddddf94430f7..6f6dcf4d4d6f 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/CopyAbstractMethodImplementationHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/CopyAbstractMethodImplementationHandler.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. @@ -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 generatedMethods = new ArrayList(); 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()); diff --git a/java/java-impl/src/com/intellij/codeInspection/actions/ReplaceImplementsWithStaticImportAction.java b/java/java-impl/src/com/intellij/codeInspection/actions/ReplaceImplementsWithStaticImportAction.java index ce12094e74a3..5ced0c4fb766 100644 --- a/java/java-impl/src/com/intellij/codeInspection/actions/ReplaceImplementsWithStaticImportAction.java +++ b/java/java-impl/src/com/intellij/codeInspection/actions/ReplaceImplementsWithStaticImportAction.java @@ -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> references = refs.get(psiFile); - if (references == null) { - references = new HashMap>(); - 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> references = refs.get(psiFile); + if (references == null) { + references = new HashMap>(); + refs.put(psiFile, references); + } + Set fieldsRefs = references.get(field); + if (fieldsRefs == null) { + fieldsRefs = new HashSet(); + references.put(field, fieldsRefs); + } + fieldsRefs.add(reference); + } } - Set fieldsRefs = references.get(field); - if (fieldsRefs == null) { - fieldsRefs = new HashSet(); - 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>()); + 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>()); + } + 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 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 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() { diff --git a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperclassHandler.java b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperclassHandler.java index b8f24bc16f1f..b3e43eb93938 100644 --- a/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperclassHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/extractSuperclass/ExtractSuperclassHandler.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. @@ -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 memberInfos = MemberInfo.extractClassMembers(mySubclass, new MemberInfo.Filter() { + @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 conflicts = new MultiMap(); 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 classPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(subclass); final SmartPsiElementPointer 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(); diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldHandler.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldHandler.java index b82953534b8c..ddfb057460ab 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineConstantFieldHandler.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. @@ -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; diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassHandler.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassHandler.java index e17326844249..8d7995fbf1b0 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineToAnonymousClassHandler.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. @@ -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) { diff --git a/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHandler.java b/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHandler.java index 2cbf7a0adcee..5a21d945fd79 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPullUp/JavaPullUpHandler.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. @@ -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() { + @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 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 conflicts = new MultiMap(); 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) { diff --git a/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpProcessor.java b/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpProcessor.java index 4531e391f838..353898cafe51 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPullUp/PullUpProcessor.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. @@ -68,7 +68,7 @@ public class PullUpProcessor extends BaseRefactoringProcessor implements PullUpD private final DocCommentPolicy myJavaDocPolicy; private Set myMembersAfterMove = null; private Set myMovedMembers = null; - private Map> myProcessors = ContainerUtil.newHashMap(); + private final Map> 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 result = new ArrayList(); @@ -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 search = ClassInheritorsSearch.search(myTargetSuperClass); - final Set hierarchyFiles = new HashSet(); - 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 search = ClassInheritorsSearch.search(myTargetSuperClass); + final Set hierarchyFiles = new HashSet(); + 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 methodsToSearchDuplicates = new HashSet(); + for (PsiMember psiMember : myMembersAfterMove) { + if (psiMember instanceof PsiMethod && psiMember.isValid() && ((PsiMethod)psiMember).getBody() != null) { + methodsToSearchDuplicates.add(psiMember); + } } - } - } - final Set methodsToSearchDuplicates = new HashSet(); - 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; } diff --git a/java/java-impl/src/com/intellij/refactoring/memberPushDown/PushDownProcessor.java b/java/java-impl/src/com/intellij/refactoring/memberPushDown/PushDownProcessor.java index ca3298bc97b2..bb09c69c9fcc 100644 --- a/java/java-impl/src/com/intellij/refactoring/memberPushDown/PushDownProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/memberPushDown/PushDownProcessor.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. @@ -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 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() { + @Override public int compare(PsiReference o1, PsiReference o2) { return PsiUtil.BY_POSITION.compare(o1.getElement(), o2.getElement()); } diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesImpl.java b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesImpl.java index 3e92a19373ab..844eb2dc0611 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesImpl.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesImpl.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. @@ -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 conflicts = new MultiMap(); 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 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 { diff --git a/java/java-impl/src/com/intellij/refactoring/turnRefsToSuper/TurnRefsToSuperProcessorBase.java b/java/java-impl/src/com/intellij/refactoring/turnRefsToSuper/TurnRefsToSuperProcessorBase.java index 1ed6de9ced09..b4142228f01f 100644 --- a/java/java-impl/src/com/intellij/refactoring/turnRefsToSuper/TurnRefsToSuperProcessorBase.java +++ b/java/java-impl/src/com/intellij/refactoring/turnRefsToSuper/TurnRefsToSuperProcessorBase.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. @@ -69,6 +69,7 @@ public abstract class TurnRefsToSuperProcessorBase extends BaseRefactoringProces private final String mySuperClassName; private final List myVariablesUsages = new ArrayList(); + @Override protected boolean preprocessUsages(Ref refUsages) { UsageInfo[] usages = refUsages.get(); List filtered = new ArrayList(); @@ -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() { + @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; } diff --git a/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java b/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java index c75c30dfb470..b65932aeaa81 100644 --- a/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.java +++ b/java/java-impl/src/com/intellij/slicer/SliceNullnessAnalyzer.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. @@ -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() { + @Override + public PsiElement compute() { + return sliceUsage.getElement(); + } + }); Nullness nullness = ApplicationManager.getApplication().runReadAction(new Computable() { @Override public Nullness compute() { diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/MethodNodeBase.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/MethodNodeBase.java index 36e5352e0f8e..782ff452fbf4 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/MethodNodeBase.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/MethodNodeBase.java @@ -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 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(); diff --git a/platform/lang-impl/src/com/intellij/tools/ScanSourceCommentsAction.java b/platform/lang-impl/src/com/intellij/tools/ScanSourceCommentsAction.java index be3fa32182de..53d15d581927 100644 --- a/platform/lang-impl/src/com/intellij/tools/ScanSourceCommentsAction.java +++ b/platform/lang-impl/src/com/intellij/tools/ScanSourceCommentsAction.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. @@ -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()); + } + }); } - }); - } + } + }); } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyMarkerTypes.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyMarkerTypes.java index 3dc41bf408f5..38fac33ae3a3 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyMarkerTypes.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/codeInsight/GroovyMarkerTypes.java @@ -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() { - @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() { + @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; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/memberPullUp/GrPullUpHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/memberPullUp/GrPullUpHandler.java index 83d2a4088645..19480e0d80e8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/memberPullUp/GrPullUpHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/memberPullUp/GrPullUpHandler.java @@ -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;