diff --git a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java index be077e257346..c6280cfc159f 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java @@ -530,7 +530,7 @@ public abstract class AbstractInplaceIntroducer pointer = ApplicationManager.getApplication().runWriteAction(new Computable>() { - @Override - public SmartPsiElementPointer compute() { - GrVariable var = runRefactoring(myContext, settings, false); - return var != null ? SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(var) : null; - } - }); - - if (pointer != null) { - GrVariable var = pointer.getElement(); - if (var != null) { - myVarMarker = myContext.getEditor().getDocument().createRangeMarker(var.getTextRange()); - } - return var; - } - else { - return null; + GrVariable var = runRefactoring(myContext, settings, false); + if (var != null) { + myVarMarker = myContext.getEditor().getDocument().createRangeMarker(var.getTextRange()); } + return var; } protected abstract GrVariable runRefactoring(GrIntroduceContext context, Settings settings, boolean processUsages); + protected final GrVariable refactorInWriteAction(Computable computable) { + SmartPsiElementPointer pointer = WriteAction.compute(() -> { + GrVariable var = computable.compute(); + return var != null ? SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(var) : null; + }); + return pointer != null ? pointer.getElement() : null; + } + @Nullable protected abstract Settings getInitialSettingsForInplace(@NotNull GrIntroduceContext context, @NotNull OccurrencesChooser.ReplaceChoice choice, diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/constant/GrInplaceConstantIntroducer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/constant/GrInplaceConstantIntroducer.java index 519d92b90168..0404b4753f5c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/constant/GrInplaceConstantIntroducer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/constant/GrInplaceConstantIntroducer.java @@ -92,13 +92,15 @@ public class GrInplaceConstantIntroducer extends GrAbstractInplaceIntroducer { + if (processUsages) { + return new GrIntroduceConstantProcessor(context, settings).run(); + } + else { + PsiElement scope = context.getScope(); + return new GrIntroduceConstantProcessor(context, settings).addDeclaration(scope instanceof GroovyFileBase ? ((GroovyFileBase)scope).getScriptClass() : (PsiClass)scope).getVariables()[0]; + } + }); } @Nullable diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrInplaceFieldIntroducer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrInplaceFieldIntroducer.java index d6057ad9bd5c..a1a9ef181ecf 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrInplaceFieldIntroducer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrInplaceFieldIntroducer.java @@ -97,9 +97,11 @@ public class GrInplaceFieldIntroducer extends GrAbstractInplaceIntroducer { GrIntroduceFieldProcessor processor = new GrIntroduceFieldProcessor(context, settings); return processUsages ? processor.run() : processor.insertField((PsiClass)context.getScope()).getVariables()[0]; + }); } @Nullable diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrInplaceParameterIntroducer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrInplaceParameterIntroducer.java index b703768a909a..73a8270ca31d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrInplaceParameterIntroducer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/parameter/GrInplaceParameterIntroducer.java @@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.refactoring.introduce.parameter; import com.intellij.codeInsight.template.TextResult; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.editor.event.DocumentAdapter; import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.impl.DocumentMarkupModel; @@ -203,8 +204,7 @@ public class GrInplaceParameterIntroducer extends GrAbstractInplaceIntroducer new GrIntroduceParameterProcessor(settings, wrapper).performRefactoring(UsageInfo.EMPTY_ARRAY)); } GrParametersOwner owner = settings.getToReplaceIn(); return ArrayUtil.getLastElement(owner.getParameters()); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/variable/GrIntroduceVariableHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/variable/GrIntroduceVariableHandler.java index 46d90d2a3050..9d5f361bfa61 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/variable/GrIntroduceVariableHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/variable/GrIntroduceVariableHandler.java @@ -158,12 +158,7 @@ public class GrIntroduceVariableHandler extends GrIntroduceHandlerBase processUsages ? processExpression(context, settings) : addVariable(context, settings)); } @Override