EA-81535 - IOE: CheckUtil.checkWritable

This commit is contained in:
Anna.Kozlova
2016-04-19 19:05:54 +02:00
parent cdf1ec874f
commit dcee197878
2 changed files with 22 additions and 28 deletions
@@ -116,9 +116,10 @@ public class AddImportAction implements QuestionAction {
}
if (finalChoice) {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
addImport(myReference, selectedValue);
return FINAL_CHOICE;
return doFinalStep(() -> {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
addImport(myReference, selectedValue);
});
}
return getExcludesStep(selectedValue.getQualifiedName(), myProject);
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.FileModificationService;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.daemon.impl.actions.AddImportAction;
import com.intellij.codeInsight.hint.QuestionAction;
@@ -22,7 +23,7 @@ import com.intellij.codeInsight.intention.impl.AddSingleMemberStaticImportAction
import com.intellij.ide.util.PsiClassListCellRenderer;
import com.intellij.ide.util.PsiElementListCellRenderer;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.markup.TextAttributes;
@@ -91,27 +92,18 @@ public class StaticImportMethodQuestionAction<T extends PsiMember> implements Qu
private void doImport(final T toImport) {
final Project project = toImport.getProject();
CommandProcessor.getInstance().executeCommand(project, new Runnable(){
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
PsiElement element = myRef.getElement();
if (element != null) {
AddSingleMemberStaticImportAction.bindAllClassRefs(element.getContainingFile(), toImport, toImport.getName(), toImport.getContainingClass());
}
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
});
final PsiElement element = myRef.getElement();
if (element == null) return;
if (!FileModificationService.getInstance().prepareFileForWrite(element.getContainingFile())) return;
WriteCommandAction.runWriteCommandAction(project, QuickFixBundle.message("add.import"), null, () -> {
try {
AddSingleMemberStaticImportAction
.bindAllClassRefs(element.getContainingFile(), toImport, toImport.getName(), toImport.getContainingClass());
}
}, QuickFixBundle.message("add.import"), this);
catch (IncorrectOperationException e) {
LOG.error(e);
}
});
}
private void chooseAndImport(final Editor editor, final Project project) {
@@ -139,10 +131,11 @@ public class StaticImportMethodQuestionAction<T extends PsiMember> implements Qu
}
if (finalChoice) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
LOG.assertTrue(selectedValue.isValid());
doImport(selectedValue);
return FINAL_CHOICE;
return doFinalStep(() -> {
PsiDocumentManager.getInstance(project).commitAllDocuments();
LOG.assertTrue(selectedValue.isValid());
doImport(selectedValue);
});
}
return AddImportAction.getExcludesStep(PsiUtil.getMemberQualifiedName(selectedValue), project);