mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
stream postfix template shouldn't be available for primitive arrays except long[], double[], int[]
This commit is contained in:
+16
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,15 +16,28 @@
|
||||
package com.intellij.codeInsight.template.postfix.templates;
|
||||
|
||||
import com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.codeInsight.template.postfix.util.JavaPostfixTemplatesUtils.selectorAllExpressionsWithCurrentOffset;
|
||||
|
||||
public class StreamPostfixTemplate extends StringBasedPostfixTemplate {
|
||||
private static final Condition<PsiElement> IS_SUPPORTED_ARRAY = element -> {
|
||||
if (!(element instanceof PsiExpression)) return false;
|
||||
|
||||
PsiType type = ((PsiExpression)element).getType();
|
||||
if (!(type instanceof PsiArrayType)) return false;
|
||||
|
||||
PsiType componentType = ((PsiArrayType)type).getComponentType();
|
||||
if (!(componentType instanceof PsiPrimitiveType)) return true;
|
||||
|
||||
return componentType.equals(PsiType.INT) || componentType.equals(PsiType.LONG) || componentType.equals(PsiType.DOUBLE);
|
||||
};
|
||||
|
||||
public StreamPostfixTemplate() {
|
||||
super("stream", "Arrays.stream(expr)", JavaPostfixTemplatesUtils.atLeastJava8Selector(selectorAllExpressionsWithCurrentOffset(JavaPostfixTemplatesUtils.IS_ARRAY)));
|
||||
super("stream", "Arrays.stream(expr)", JavaPostfixTemplatesUtils.atLeastJava8Selector(selectorAllExpressionsWithCurrentOffset(IS_SUPPORTED_ARRAY)));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class Test {
|
||||
void m(byte[] ss) {
|
||||
ss.stream<caret>
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class Test {
|
||||
void m(byte[] ss) {
|
||||
ss.stream
|
||||
}
|
||||
}
|
||||
+4
@@ -57,6 +57,10 @@ public class StreamPostfixTemplateTest extends PostfixTemplateTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNotAvailable() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDoNotExpandOnJavaLess8() {
|
||||
IdeaTestUtil.setModuleLanguageLevel(myModule, LanguageLevel.JDK_1_6, myFixture.getTestRootDisposable());
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user