From 01bf7bfecdd8bf5e49e47c44b4119f475a0d05cd Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 28 Nov 2016 11:33:31 +0100 Subject: [PATCH] write access for elements which probably differ from the current file --- .../analysis/IncreaseLanguageLevelFix.java | 9 ++-- .../impl/quickfix/AddMethodBodyFix.java | 9 +++- .../quickfix/AddNewArrayExpressionFix.java | 6 +++ .../daemon/impl/quickfix/AddReturnFix.java | 8 +++- .../quickfix/AddVariableInitializerFix.java | 8 +++- .../quickfix/ConvertSwitchToIfIntention.java | 6 +++ .../daemon/impl/quickfix/DeleteCatchFix.java | 8 +++- .../impl/quickfix/DeleteMethodBodyFix.java | 9 +++- .../impl/quickfix/DeleteMultiCatchFix.java | 8 +++- .../impl/quickfix/GeneralizeCatchFix.java | 8 +++- .../daemon/impl/quickfix/InsertNewFix.java | 6 +++ .../daemon/impl/quickfix/InsertSuperFix.java | 8 +++- .../quickfix/MakeMethodConstructorFix.java | 9 +++- .../quickfix/MakeVarargParameterLastFix.java | 9 +++- .../daemon/impl/quickfix/MoveCatchUpFix.java | 9 +++- .../quickfix/MoveClassToSeparateFileFix.java | 13 +++--- .../impl/quickfix/NegationBroadScopeFix.java | 8 +++- .../impl/quickfix/RemoveNewQualifierFix.java | 13 +++--- .../quickfix/ReuseVariableDeclarationFix.java | 8 +++- .../VariableAccessFromInnerClassFix.java | 45 ++++++++++--------- .../MagicConstantInspection.java | 5 ++- .../codeInsight/intention/IntentionLike.java | 16 ++++--- .../intention/impl/PriorityActionWrapper.java | 7 +-- .../ExternalAnnotatorInspectionVisitor.java | 7 +-- .../codeInspection/ex/QuickFixWrapper.java | 6 ++- .../impl/PriorityIntentionActionWrapper.java | 10 +++-- .../codeInspection/IntentionWrapper.java | 10 +++-- .../daemon/quickFix/CreateFileFix.java | 7 +-- .../impl/ShowIntentionActionsHandler.java | 6 +-- .../impl/config/IntentionActionWrapper.java | 11 +++-- .../inplace/ApplyChangeSignatureAction.java | 7 ++- .../impl/CodeInsightTestFixtureImpl.java | 7 ++- ...onvertConcatenationToGstringIntention.java | 5 ++- .../ConvertStringToMultilineIntention.java | 6 ++- .../quickfix/PyRenameElementQuickFix.java | 6 ++- .../quickfix/RenameParameterQuickFix.java | 7 +-- .../spellchecker/quickfixes/RenameTo.java | 7 +-- .../htmlInspections/SwitchToHtml5Action.java | 9 ++-- 38 files changed, 241 insertions(+), 105 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/IncreaseLanguageLevelFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/IncreaseLanguageLevelFix.java index d2720899a142..760ad0fa4959 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/IncreaseLanguageLevelFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/IncreaseLanguageLevelFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 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,9 +26,11 @@ import com.intellij.openapi.projectRoots.ex.JavaSdkUtil; import com.intellij.openapi.roots.JavaProjectModelModificationService; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author cdr @@ -73,9 +75,10 @@ public class IncreaseLanguageLevelFix implements IntentionAction { JavaProjectModelModificationService.getInstance(project).changeLanguageLevel(module, myLevel); } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return false; + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return null; } @Override diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodBodyFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodBodyFix.java index 337679fcd17a..c6d958bc8462 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodBodyFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddMethodBodyFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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.daemon.QuickFixBundle; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiModifier; @@ -52,6 +53,12 @@ public class AddMethodBodyFix implements IntentionAction { myMethod.getManager().isInProject(myMethod); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myMethod; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) { PsiUtil.setModifierProperty(myMethod, PsiModifier.ABSTRACT, false); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java index 4ecdb03001bf..c7d83c7ae485 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddNewArrayExpressionFix.java @@ -56,6 +56,12 @@ public class AddNewArrayExpressionFix implements IntentionAction { return getType() != null; } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myInitializer; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { PsiManager manager = file.getManager(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddReturnFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddReturnFix.java index 3be7cd714e5b..c388e31dc603 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddReturnFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddReturnFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -55,6 +55,12 @@ public class AddReturnFix implements IntentionAction { ; } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myMethod; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) { String value = suggestReturnValue(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddVariableInitializerFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddVariableInitializerFix.java index f43f059680ab..29690467d913 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddVariableInitializerFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddVariableInitializerFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -65,6 +65,12 @@ public class AddVariableInitializerFix implements IntentionAction { ; } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myVariable; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { final LookupElement[] suggestedInitializers = suggestInitializer(myVariable); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java index 51e8182ad144..cf8eedcde1ea 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java @@ -71,6 +71,12 @@ public class ConvertSwitchToIfIntention implements IntentionAction { doProcessIntention(mySwitchExpression); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return mySwitchExpression; + } + @Override public boolean startInWriteAction() { return true; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteCatchFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteCatchFix.java index c028e85ea5e9..265e63046326 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteCatchFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteCatchFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -47,6 +47,12 @@ public class DeleteCatchFix implements IntentionAction { return myCatchParameter.isValid() && PsiManager.getInstance(project).isInProject(myCatchParameter.getContainingFile()); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myCatchParameter; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) { final PsiTryStatement tryStatement = ((PsiCatchSection)myCatchParameter.getDeclarationScope()).getTryStatement(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteMethodBodyFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteMethodBodyFix.java index 2d23168404a6..15bb9b0b1005 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteMethodBodyFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteMethodBodyFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiCodeBlock; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiMethod; import com.intellij.util.IncorrectOperationException; @@ -52,6 +53,12 @@ public class DeleteMethodBodyFix implements IntentionAction { return myMethod.isValid() && myMethod.getManager().isInProject(myMethod) && myMethod.getBody() != null; } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myMethod; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { final PsiCodeBlock body = myMethod.getBody(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteMultiCatchFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteMultiCatchFix.java index dc20a2bdaf0c..f7bee3dc4281 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteMultiCatchFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/DeleteMultiCatchFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -52,6 +52,12 @@ public class DeleteMultiCatchFix implements IntentionAction { return myTypeElement.isValid() && PsiManager.getInstance(project).isInProject(myTypeElement.getContainingFile()); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myTypeElement; + } + @Override public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { final PsiElement parentType = myTypeElement.getParent(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/GeneralizeCatchFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/GeneralizeCatchFix.java index e4120bc66aac..b8a1b78468bc 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/GeneralizeCatchFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/GeneralizeCatchFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -78,6 +78,12 @@ public class GeneralizeCatchFix implements IntentionAction { return myCatchParameter != null; } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myElement; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { PsiElementFactory factory = JavaPsiFacade.getInstance(myElement.getProject()).getElementFactory(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/InsertNewFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/InsertNewFix.java index a6f889de1eb1..660775834b50 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/InsertNewFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/InsertNewFix.java @@ -50,6 +50,12 @@ public class InsertNewFix implements IntentionAction { return myMethodCall.isValid() && myMethodCall.getManager().isInProject(myMethodCall); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myMethodCall; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { PsiElementFactory factory = JavaPsiFacade.getInstance(myMethodCall.getProject()).getElementFactory(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/InsertSuperFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/InsertSuperFix.java index 6d4614aec9e0..c75426239e8e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/InsertSuperFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/InsertSuperFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -54,6 +54,12 @@ public class InsertSuperFix implements IntentionAction, HighPriorityAction { ; } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myConstructor; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) { PsiStatement superCall = diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MakeMethodConstructorFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MakeMethodConstructorFix.java index c8b84cd0debd..ee08e589cde4 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MakeMethodConstructorFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MakeMethodConstructorFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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.daemon.QuickFixBundle; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiMethod; import com.intellij.util.IncorrectOperationException; @@ -51,6 +52,12 @@ public class MakeMethodConstructorFix implements IntentionAction { return myMethod.isValid() && myMethod.getReturnTypeElement() != null && myMethod.getManager().isInProject(myMethod); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myMethod; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { myMethod.getReturnTypeElement().delete(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MakeVarargParameterLastFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MakeVarargParameterLastFix.java index 89176a870b68..f4d8a0c00b03 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MakeVarargParameterLastFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MakeVarargParameterLastFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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.daemon.QuickFixBundle; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiParameter; import com.intellij.util.IncorrectOperationException; @@ -51,6 +52,12 @@ public class MakeVarargParameterLastFix implements IntentionAction { return myParameter.isValid() && myParameter.getManager().isInProject(myParameter); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myParameter; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { myParameter.getParent().add(myParameter); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MoveCatchUpFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MoveCatchUpFix.java index 5581c4d085e7..cff50fef97e5 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MoveCatchUpFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MoveCatchUpFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -21,6 +21,7 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiCatchSection; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiTryStatement; import com.intellij.psi.util.PsiUtil; @@ -63,6 +64,12 @@ public class MoveCatchUpFix implements IntentionAction { PsiUtil.resolveClassInType(myMoveBeforeSection.getCatchType())); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myCatchSection; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) { PsiTryStatement statement = myCatchSection.getTryStatement(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MoveClassToSeparateFileFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MoveClassToSeparateFileFix.java index 713dd666ac93..23649091c5ea 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MoveClassToSeparateFileFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MoveClassToSeparateFileFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.project.Project; -import com.intellij.psi.JavaDirectoryService; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiDirectory; -import com.intellij.psi.PsiFile; +import com.intellij.psi.*; import com.intellij.psi.impl.file.JavaDirectoryServiceImpl; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -67,6 +64,12 @@ public class MoveClassToSeparateFileFix implements IntentionAction { return true; } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myClass; + } + @Override public void invoke(@NotNull Project project, @Nullable Editor editor, @NotNull PsiFile file) { PsiDirectory dir = file.getContainingDirectory(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/NegationBroadScopeFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/NegationBroadScopeFix.java index 64d27b47261e..be1135f39685 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/NegationBroadScopeFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/NegationBroadScopeFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -81,6 +81,12 @@ public class NegationBroadScopeFix implements IntentionAction { return binaryExpression.getLOperand() == myPrefixExpression && TypeConversionUtil.isBooleanType(binaryExpression.getType()); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myPrefixExpression; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { if (!isAvailable(project, editor, file)) return; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveNewQualifierFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveNewQualifierFix.java index 3b0bacfa1209..12536f681c1e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveNewQualifierFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveNewQualifierFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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,10 +19,7 @@ import com.intellij.codeInsight.daemon.QuickFixBundle; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiJavaCodeReferenceElement; -import com.intellij.psi.PsiNewExpression; +import com.intellij.psi.*; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; @@ -60,6 +57,12 @@ public class RemoveNewQualifierFix implements IntentionAction { expression.isValid() && (aClass == null || aClass.isValid()) && expression.getManager().isInProject(expression); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return expression; + } + @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { PsiJavaCodeReferenceElement classReference = expression.getClassReference(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReuseVariableDeclarationFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReuseVariableDeclarationFix.java index 4cc25af69ea3..eb8d48de83dd 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReuseVariableDeclarationFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ReuseVariableDeclarationFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -62,6 +62,12 @@ public class ReuseVariableDeclarationFix implements IntentionAction { myVariable.getManager().isInProject(myVariable); } + @NotNull + @Override + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myVariable; + } + @Override public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException { final PsiVariable refVariable = findPreviousVariable(); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/VariableAccessFromInnerClassFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/VariableAccessFromInnerClassFix.java index f8fea8dbf95b..532199968579 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/VariableAccessFromInnerClassFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/VariableAccessFromInnerClassFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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,10 +15,12 @@ */ package com.intellij.codeInsight.daemon.impl.quickfix; +import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInsight.daemon.QuickFixBundle; import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil; import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; @@ -101,25 +103,28 @@ public class VariableAccessFromInnerClassFix implements IntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, PsiFile file) { - try { - switch (myFixType) { - case MAKE_FINAL: - makeFinal(); - break; - case MAKE_ARRAY: - makeArray(); - break; - case COPY_TO_FINAL: - copyToFinal(); - break; + if (!FileModificationService.getInstance().preparePsiElementsForWrite(myContext, myVariable)) return; + WriteAction.run(() -> { + try { + switch (myFixType) { + case MAKE_FINAL: + makeFinal(); + break; + case MAKE_ARRAY: + makeArray(); + break; + case COPY_TO_FINAL: + copyToFinal(); + break; + } } - } - catch (IncorrectOperationException e) { - LOG.error(e); - } - finally { - getVariablesToFix().clear(); - } + catch (IncorrectOperationException e) { + LOG.error(e); + } + finally { + getVariablesToFix().clear(); + } + }); } private void makeArray() { @@ -354,6 +359,6 @@ public class VariableAccessFromInnerClassFix implements IntentionAction { @Override public boolean startInWriteAction() { - return true; + return false; } } diff --git a/java/java-impl/src/com/intellij/codeInspection/magicConstant/MagicConstantInspection.java b/java/java-impl/src/com/intellij/codeInspection/magicConstant/MagicConstantInspection.java index 7cbc5349879c..d6873d945cad 100644 --- a/java/java-impl/src/com/intellij/codeInspection/magicConstant/MagicConstantInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/magicConstant/MagicConstantInspection.java @@ -207,9 +207,10 @@ public class MagicConstantInspection extends BaseJavaLocalInspectionTool { return "Attach annotations"; } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return false; + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return null; } @Override diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionLike.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionLike.java index 3408ae0d84a7..b3ab39393715 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionLike.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/IntentionLike.java @@ -16,6 +16,10 @@ package com.intellij.codeInsight.intention; import com.intellij.openapi.application.WriteActionAware; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * An interface that {@link IntentionAction} and {@link com.intellij.codeInspection.LocalQuickFix} share. @@ -26,17 +30,17 @@ import com.intellij.openapi.application.WriteActionAware; public interface IntentionLike extends WriteActionAware { /** - * Controls whether this intention/fix is going to modify the current editor file. - * If {@code true}, and the file is read-only, - * it will be made writable (honoring version control integration) before the intention/fix is invoked.

+ * Controls whether this intention/fix is going to modify the file. + * If {@code @NotNull}, and the file is read-only, + * it will be made writable (honoring version control integration) before the intention/fix is invoked.

* * By default, as a heuristic, returns the same as {@link #startInWriteAction()}.

* * If the action is going to modify multiple files, or the set of the files is unknown in advance, please * don't bother overriding this method, return {@code false} from {@link #startInWriteAction()}, and call {@link com.intellij.codeInsight.FileModificationService} methods in the implementation, and take write actions yourself as needed. */ - default boolean shouldMakeCurrentFileWritable() { - return startInWriteAction(); + @Nullable + default PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return startInWriteAction() ? file : null; } - } diff --git a/platform/analysis-api/src/com/intellij/codeInsight/intention/impl/PriorityActionWrapper.java b/platform/analysis-api/src/com/intellij/codeInsight/intention/impl/PriorityActionWrapper.java index 3585489432ca..a873fed13b1a 100644 --- a/platform/analysis-api/src/com/intellij/codeInsight/intention/impl/PriorityActionWrapper.java +++ b/platform/analysis-api/src/com/intellij/codeInsight/intention/impl/PriorityActionWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -61,9 +61,10 @@ public abstract class PriorityActionWrapper extends LocalQuickFixAndIntentionAct return fix.startInWriteAction(); } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return fix.shouldMakeCurrentFileWritable(); + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return fix.getElementToMakeWritable(file); } @NotNull diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ExternalAnnotatorInspectionVisitor.java b/platform/analysis-impl/src/com/intellij/codeInspection/ExternalAnnotatorInspectionVisitor.java index 4c3a69791191..67f19f8a3403 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ExternalAnnotatorInspectionVisitor.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ExternalAnnotatorInspectionVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -169,9 +169,10 @@ public class ExternalAnnotatorInspectionVisitor extends PsiElementVisitor { myAction.invoke(project, null, getPsiFile(descriptor)); } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return myAction.shouldMakeCurrentFileWritable(); + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myAction.getElementToMakeWritable(file); } @Nullable diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java index 13e15b3b801d..15c78ec8a58d 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/QuickFixWrapper.java @@ -30,6 +30,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; /** @@ -97,9 +98,10 @@ public class QuickFixWrapper implements IntentionAction { return getFix().startInWriteAction(); } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return getFix().shouldMakeCurrentFileWritable(); + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return getFix().getElementToMakeWritable(file); } public LocalQuickFix getFix() { diff --git a/platform/lang-api/src/com/intellij/codeInsight/intention/impl/PriorityIntentionActionWrapper.java b/platform/lang-api/src/com/intellij/codeInsight/intention/impl/PriorityIntentionActionWrapper.java index 3a8ea981c469..a7cf7720edf2 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/intention/impl/PriorityIntentionActionWrapper.java +++ b/platform/lang-api/src/com/intellij/codeInsight/intention/impl/PriorityIntentionActionWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2016 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,9 +20,11 @@ import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.intention.LowPriorityAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Danila Ponomarenko @@ -55,10 +57,10 @@ public abstract class PriorityIntentionActionWrapper implements IntentionAction public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { action.invoke(project, editor, file); } - + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return action.shouldMakeCurrentFileWritable(); + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return action.getElementToMakeWritable(file); } @Override diff --git a/platform/lang-api/src/com/intellij/codeInspection/IntentionWrapper.java b/platform/lang-api/src/com/intellij/codeInspection/IntentionWrapper.java index 8c2511e8f42f..5f5fa138a32d 100644 --- a/platform/lang-api/src/com/intellij/codeInspection/IntentionWrapper.java +++ b/platform/lang-api/src/com/intellij/codeInspection/IntentionWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2016 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,9 +22,11 @@ import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Created by IntelliJ IDEA. @@ -68,10 +70,10 @@ public class IntentionWrapper implements LocalQuickFix, IntentionAction, ActionC public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { myAction.invoke(project, editor, file); } - + @Nullable @Override - public final boolean shouldMakeCurrentFileWritable() { - return myAction.shouldMakeCurrentFileWritable(); + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return myAction.getElementToMakeWritable(file); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/quickFix/CreateFileFix.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/quickFix/CreateFileFix.java index fae9f85394e3..2e602f060700 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/quickFix/CreateFileFix.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/quickFix/CreateFileFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -94,9 +94,10 @@ public class CreateFileFix extends LocalQuickFixAndIntentionActionOnPsiElement { return CodeInsightBundle.message("create.file.family"); } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return false; + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return null; } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java index 56dd5ef5f0a8..d0b1fc667ff6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -188,8 +188,8 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler { } private static void invokeIntention(@NotNull IntentionAction action, @NotNull Editor editor, @NotNull PsiFile file) { - if (action.shouldMakeCurrentFileWritable() && - !FileModificationService.getInstance().preparePsiElementsForWrite(file)) { + PsiElement elementToMakeWritable = action.getElementToMakeWritable(file); + if (elementToMakeWritable != null && !FileModificationService.getInstance().preparePsiElementsForWrite(elementToMakeWritable)) { return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionActionWrapper.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionActionWrapper.java index 00303043428e..0a2f5177d5e3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionActionWrapper.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionActionWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -18,13 +18,15 @@ package com.intellij.codeInsight.intention.impl.config; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInsight.intention.IntentionActionBean; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.diagnostic.Logger; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class IntentionActionWrapper implements IntentionAction { private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper"); @@ -66,9 +68,10 @@ public class IntentionActionWrapper implements IntentionAction { return getDelegate().startInWriteAction(); } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return getDelegate().shouldMakeCurrentFileWritable(); + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return getDelegate().getElementToMakeWritable(file); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/inplace/ApplyChangeSignatureAction.java b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/inplace/ApplyChangeSignatureAction.java index 7539f60bc6b5..696641212aa5 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/changeSignature/inplace/ApplyChangeSignatureAction.java +++ b/platform/lang-impl/src/com/intellij/refactoring/changeSignature/inplace/ApplyChangeSignatureAction.java @@ -18,11 +18,13 @@ package com.intellij.refactoring.changeSignature.inplace; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; import com.intellij.refactoring.BaseRefactoringIntentionAction; import com.intellij.refactoring.RefactoringBundle; import com.intellij.refactoring.changeSignature.ChangeInfo; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * User: anna @@ -73,9 +75,10 @@ public class ApplyChangeSignatureAction extends BaseRefactoringIntentionAction { detector.performChange(currentInfo, editor, initialSignature); } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return true; + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return file; } @Override diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 2a643c41f7eb..c61c55e78a16 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -58,7 +58,10 @@ import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; -import com.intellij.openapi.application.*; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ReadAction; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.*; @@ -1740,7 +1743,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig public static boolean invokeIntention(@NotNull IntentionAction action, PsiFile file, Editor editor, String actionText) { // Test that action will automatically clear the read-only attribute if modification is necessary. // If your test fails due to this, make sure that your quick-fix/intention - // overrides "shouldMakeCurrentFileWritable" or has the following line: + // overrides "getElementToMakeWritable" or has the following line: // if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; ReadonlyStatusHandlerImpl handler = (ReadonlyStatusHandlerImpl)ReadonlyStatusHandler.getInstance(file.getProject()); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/strings/ConvertConcatenationToGstringIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/strings/ConvertConcatenationToGstringIntention.java index 82ced1713790..3bdfb2f6f29c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/strings/ConvertConcatenationToGstringIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/strings/ConvertConcatenationToGstringIntention.java @@ -89,9 +89,10 @@ public class ConvertConcatenationToGstringIntention extends Intention { } } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return true; + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return file; } @Override diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/strings/ConvertStringToMultilineIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/strings/ConvertStringToMultilineIntention.java index 20b16e62cda7..a6c2dbed2314 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/strings/ConvertStringToMultilineIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/strings/ConvertStringToMultilineIntention.java @@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pass; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IElementType; import com.intellij.refactoring.IntroduceTargetChooser; import com.intellij.util.Function; @@ -252,9 +253,10 @@ public class ConvertStringToMultilineIntention extends Intention { }; } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return true; + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return file; } @Override diff --git a/python/src/com/jetbrains/python/inspections/quickfix/PyRenameElementQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/PyRenameElementQuickFix.java index 83f2d15049ab..31135944e295 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/PyRenameElementQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/PyRenameElementQuickFix.java @@ -24,6 +24,7 @@ import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; import com.intellij.psi.PsiNameIdentifierOwner; import com.intellij.psi.PsiReference; import com.intellij.psi.search.LocalSearchScope; @@ -99,9 +100,10 @@ public class PyRenameElementQuickFix implements LocalQuickFix { return false; } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return true; + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return file; } private static void renameInUnitTestMode(@NotNull Project project, @NotNull PsiNameIdentifierOwner nameOwner, diff --git a/python/src/com/jetbrains/python/inspections/quickfix/RenameParameterQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/RenameParameterQuickFix.java index b19febf369db..451268d8b72e 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/RenameParameterQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/RenameParameterQuickFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -53,11 +53,6 @@ public class RenameParameterQuickFix implements LocalQuickFix { return PyBundle.message("QFIX.rename.parameter.to.$0", myNewName); } - @Override - public boolean shouldMakeCurrentFileWritable() { - return true; - } - @Override public boolean startInWriteAction() { return false; diff --git a/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java b/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java index 6ab7dd1fb6ba..12dcb3b32763 100644 --- a/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java +++ b/spellchecker/src/com/intellij/spellchecker/quickfixes/RenameTo.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -114,11 +114,6 @@ public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix { } } - @Override - public boolean shouldMakeCurrentFileWritable() { - return true; - } - @Override public boolean startInWriteAction() { return false; diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/SwitchToHtml5Action.java b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/SwitchToHtml5Action.java index afe471c35f2b..d1f07a6d4129 100644 --- a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/SwitchToHtml5Action.java +++ b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/SwitchToHtml5Action.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -23,10 +23,12 @@ import com.intellij.codeInspection.ProblemDescriptor; import com.intellij.javaee.ExternalResourceManagerEx; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; import com.intellij.xml.Html5SchemaProvider; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Eugene.Kudelevsky @@ -65,9 +67,10 @@ public class SwitchToHtml5Action implements LocalQuickFix, IntentionAction { applyFix(project); } + @Nullable @Override - public boolean shouldMakeCurrentFileWritable() { - return false; + public PsiElement getElementToMakeWritable(@NotNull PsiFile file) { + return null; } private static void applyFix(Project project) {