diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceField/normalizeDeclarationWithDisabledFormatting_after.java b/java/java-tests/testData/refactoring/inplaceIntroduceField/normalizeDeclarationWithDisabledFormatting_after.java new file mode 100644 index 000000000000..6626aba8bc0d --- /dev/null +++ b/java/java-tests/testData/refactoring/inplaceIntroduceField/normalizeDeclarationWithDisabledFormatting_after.java @@ -0,0 +1,13 @@ +abstract class Main { + + private static String notification; + + public static void main(String notification) throws Exception { + Main.notification = notification; + System.out.println( + "Too large notification " + Main.notification + + " of " + notification.getClass() + + "\nListener=" + notification.substring(0)); + } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java index 6dac27f07eb8..907f4620c842 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceFieldTest.java @@ -115,6 +115,14 @@ public class InplaceIntroduceFieldTest extends AbstractJavaInplaceIntroduceTest } }); } + + public void testNormalizeDeclarationWithDisabledFormatting() throws Exception { + doTest(new Pass() { + @Override + public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) { + } + }); + } public void testEscapePosition() throws Exception { doTestEscape(); diff --git a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/InplaceVariableIntroducer.java b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/InplaceVariableIntroducer.java index 77c49123fce6..ad90339189d4 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/InplaceVariableIntroducer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/InplaceVariableIntroducer.java @@ -38,6 +38,7 @@ import com.intellij.psi.PsiNamedElement; import com.intellij.psi.SmartPointerManager; import com.intellij.psi.SmartPsiElementPointer; import com.intellij.psi.codeStyle.SuggestedNameInfo; +import com.intellij.psi.impl.source.PostprocessReformattingAspect; import com.intellij.refactoring.rename.NameSuggestionProvider; import com.intellij.refactoring.rename.PreferrableNameSuggestionProvider; import com.intellij.refactoring.rename.inplace.InplaceRefactoring; @@ -67,8 +68,8 @@ public abstract class InplaceVariableIntroducer extends In public InplaceVariableIntroducer(PsiNamedElement elementToRename, Editor editor, - Project project, - String title, E[] occurrences, + final Project project, + String title, E[] occurrences, @Nullable E expr) { super(editor, elementToRename, project); myTitle = title; @@ -78,12 +79,17 @@ public abstract class InplaceVariableIntroducer extends In final ASTNode astNode = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(expr.getLanguage()) .generateWhitespaceBetweenTokens(node.getTreePrev(), node); if (astNode != null) { - new WriteCommandAction(project, "Normalize declaration") { + PostprocessReformattingAspect.getInstance(project).disablePostprocessFormattingInside(new Runnable() { @Override - protected void run(@NotNull Result result) throws Throwable { - node.getTreeParent().addChild(astNode, node); + public void run() { + new WriteCommandAction(project, "Normalize declaration") { + @Override + protected void run(@NotNull Result result) throws Throwable { + node.getTreeParent().addChild(astNode, node); + } + }.execute(); } - }.execute(); + }); } myExpr = expr; }