diff --git a/java/java-impl/src/com/intellij/codeInsight/template/macro/ExpectedTypeMacro.java b/java/java-impl/src/com/intellij/codeInsight/template/macro/ExpectedTypeMacro.java index 6ff95abaf7c1..7ab498399180 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/macro/ExpectedTypeMacro.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/macro/ExpectedTypeMacro.java @@ -76,19 +76,13 @@ public class ExpectedTypeMacro extends Macro { final Project project = context.getProject(); PsiType[] types = null; - final int offset = context.getTemplateStartOffset(); PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument()); assert file != null; final PsiFile fileCopy = (PsiFile)file.copy(); + BlockSupport.getInstance(project).reparseRange(fileCopy, context.getTemplateStartOffset(), context.getTemplateEndOffset(), + CompletionUtil.DUMMY_IDENTIFIER); - new WriteCommandAction(project) { - @Override - protected void run(com.intellij.openapi.application.Result result) throws Throwable { - final BlockSupport blockSupport = ServiceManager.getService(project, BlockSupport.class); - blockSupport.reparseRange(fileCopy, offset, offset, CompletionUtil.DUMMY_IDENTIFIER); - } - }.execute(); - PsiElement element = fileCopy.findElementAt(offset); + PsiElement element = fileCopy.findElementAt(context.getTemplateStartOffset()); if (element instanceof PsiIdentifier && element.getParent() instanceof PsiExpression) { ExpectedTypeInfo[] infos = ExpectedTypesProvider.getExpectedTypes((PsiExpression)element.getParent(), true); diff --git a/java/java-tests/testData/codeInsight/template/AsListToar-out.java b/java/java-tests/testData/codeInsight/template/AsListToar-out.java new file mode 100644 index 000000000000..79695238bc6e --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/AsListToar-out.java @@ -0,0 +1,9 @@ +import java.util.Arrays; +import java.util.List; + +class Foo { + + static void foo(List ls) { + List ls2 = Arrays.asList(ls.toArray(new String[ls.size()])); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/AsListToar.java b/java/java-tests/testData/codeInsight/template/AsListToar.java new file mode 100644 index 000000000000..befb6ceb4d44 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/AsListToar.java @@ -0,0 +1,9 @@ +import java.util.Arrays; +import java.util.List; + +class Foo { + + static void foo(List ls) { + List ls2 = Arrays.asList(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy index 454df188c95e..e187c32dfc93 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy @@ -237,6 +237,13 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { checkResult(); } + public void testAsListToar() { + configure(); + startTemplate("toar", "other") + myFixture.type('\n\t') + checkResult(); + } + public void testVarargToar() { configure(); startTemplate("toar", "other")