diff --git a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/StreamPostfixTemplate.java b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/StreamPostfixTemplate.java index c1603123d715..13f49004a571 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/StreamPostfixTemplate.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/postfix/templates/StreamPostfixTemplate.java @@ -20,11 +20,11 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils.selectorTopmost; +import static com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset; public class StreamPostfixTemplate extends StringBasedPostfixTemplate { public StreamPostfixTemplate() { - super("stream", "Arrays.stream(expr)", JavaPostfixTemplatesUtils.atLeastJava8Selector(selectorTopmost(JavaPostfixTemplatesUtils.IS_ARRAY))); + super("stream", "Arrays.stream(expr)", JavaPostfixTemplatesUtils.atLeastJava8Selector(selectorAllExpressionsWithCurrentOffset(JavaPostfixTemplatesUtils.IS_ARRAY))); } @Nullable diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/stream/expressionContext.java b/java/java-tests/testData/codeInsight/template/postfix/templates/stream/expressionContext.java new file mode 100644 index 000000000000..5ab071b9a259 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/stream/expressionContext.java @@ -0,0 +1,9 @@ +package templates; + +public class Foo { + void m(int[] array) { + if (array.stream) { + + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/templates/stream/expressionContext_after.java b/java/java-tests/testData/codeInsight/template/postfix/templates/stream/expressionContext_after.java new file mode 100644 index 000000000000..f8db444f3fcb --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/templates/stream/expressionContext_after.java @@ -0,0 +1,11 @@ +package templates; + +import java.util.Arrays; + +public class Foo { + void m(int[] array) { + if (Arrays.stream(array)) { + + } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/StreamPostfixTemplateTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/StreamPostfixTemplateTest.java index c3828b3cf1e0..f7d84be36c6c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/StreamPostfixTemplateTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/templates/StreamPostfixTemplateTest.java @@ -51,7 +51,11 @@ public class StreamPostfixTemplateTest extends PostfixTemplateTestCase { public void testSimple() { doTest(); } - + + public void testExpressionContext() { + doTest(); + } + public void testDoNotExpandOnJavaLess8() { LanguageLevelProjectExtension.getInstance(myFixture.getProject()).setLanguageLevel(LanguageLevel.JDK_1_6); doTest();