From 614deb2e243b733f8e6cfd0faa7a0de80bf35895 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Thu, 13 Oct 2016 18:47:37 +0200 Subject: [PATCH] postfix completion: inplace introduce variable: ensure doc committed when handler is started inside writeAction test: switch on inplace mode in tests EA-86900 - RE: PostprocessReformattingAspect.beforeDocumentChanged --- .../templates/IntroduceVariablePostfixTemplate.java | 5 +++++ .../introduceVariable/JavaVariableInplaceIntroducer.java | 1 + .../template/postfix/templates/var/add_after.java | 2 +- .../template/postfix/templates/var/anonymous.java | 7 +++++++ .../template/postfix/templates/var/anonymous_after.java | 9 +++++++++ .../template/postfix/templates/var/simple_after.java | 2 +- .../postfix/templates/VarPostfixTemplateTest.java | 4 ++++ 7 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/var/anonymous.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/templates/var/anonymous_after.java diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceVariablePostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceVariablePostfixTemplate.java index e1cf9bae64f9..7bf1e8cd03bd 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceVariablePostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/IntroduceVariablePostfixTemplate.java @@ -86,6 +86,11 @@ public class IntroduceVariablePostfixTemplate extends PostfixTemplateWithExpress } }; } + + @Override + protected boolean isInplaceAvailableInTestMode() { + return true; + } }; } } \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/JavaVariableInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/JavaVariableInplaceIntroducer.java index aac8eb5b523f..c6ad929835b0 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/JavaVariableInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/JavaVariableInplaceIntroducer.java @@ -422,6 +422,7 @@ public class JavaVariableInplaceIntroducer extends AbstractJavaInplaceIntroducer finally { myDeleteSelf = true; } + PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(myEditor.getDocument()); initOccurrencesMarkers(); return variable; } diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/var/add_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/var/add_after.java index 05f95bdd2d87..2dc9a7fc158f 100644 --- a/java/java-tests/testData/codeInsight/template/postfix/templates/var/add_after.java +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/var/add_after.java @@ -1,5 +1,5 @@ public class Foo { void m(Object o) { - int foo = 1; + int foo = 1; } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/var/anonymous.java b/java/java-tests/testData/codeInsight/template/postfix/templates/var/anonymous.java new file mode 100644 index 000000000000..2a6c4ab541fc --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/var/anonymous.java @@ -0,0 +1,7 @@ +public class Foo { + void m() { + foo(new Runnable() {public void run()}.var); + } + + void foo(Runnable r) {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/var/anonymous_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/var/anonymous_after.java new file mode 100644 index 000000000000..2fd8e29b5395 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/var/anonymous_after.java @@ -0,0 +1,9 @@ +public class Foo { + void m() { + Runnable foo = new Runnable() { + public void run() + }; foo(foo); + } + + void foo(Runnable r) {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/var/simple_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/var/simple_after.java index 3922fc499e94..0f00e0f7f506 100644 --- a/java/java-tests/testData/codeInsight/template/postfix/templates/var/simple_after.java +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/var/simple_after.java @@ -1,5 +1,5 @@ public class Foo { void m(Object o) { - boolean foo = o instanceof String; + boolean foo = o instanceof String; } } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/VarPostfixTemplateTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/VarPostfixTemplateTest.java index 13cabdd086e0..fb7e841eca85 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/VarPostfixTemplateTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/VarPostfixTemplateTest.java @@ -34,4 +34,8 @@ public class VarPostfixTemplateTest extends PostfixTemplateTestCase { public void testAdd() { doTest(); } + + public void testAnonymous() { + doTest(); + } }