java: expression context for array.stream postfix template IDEA-157975

This commit is contained in:
Andrey Starovoyt
2016-10-04 16:54:06 +03:00
parent f6614075a5
commit 2e7d6eb8af
4 changed files with 27 additions and 3 deletions
@@ -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
@@ -0,0 +1,9 @@
package templates;
public class Foo {
void m(int[] array) {
if (array.stream<caret>) {
}
}
}
@@ -0,0 +1,11 @@
package templates;
import java.util.Arrays;
public class Foo {
void m(int[] array) {
if (Arrays.stream(array)) {
}
}
}
@@ -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();