mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
StaticPseudoFunctionalStyleMethodInspection: doesn't throw exception when lambda is variable
This commit is contained in:
+6
@@ -449,6 +449,12 @@ class PseudoLambdaReplaceTemplate {
|
||||
final String methodName = functionalInterfaceMethod.getName();
|
||||
return JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(expression.getText() + "::" + methodName, null);
|
||||
}
|
||||
if (expression instanceof PsiReferenceExpression) {
|
||||
final PsiType expressionType = expression.getType();
|
||||
final PsiMethod method = LambdaUtil.getFunctionalInterfaceMethod(expressionType);
|
||||
LOG.assertTrue(method != null);
|
||||
return JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(expression.getText() + "::" + method.getName(), null);
|
||||
}
|
||||
return AnonymousCanBeLambdaInspection.replacePsiElementWithLambda(expression, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import java.lang.String;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class c {
|
||||
void m() {
|
||||
final Function<String, String> function = (Function<String, String>)new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String input) {
|
||||
Collectors c;
|
||||
ArrayList l;
|
||||
System.out.println(input);
|
||||
//do something
|
||||
int i = 1;
|
||||
return input;
|
||||
}
|
||||
};
|
||||
Iterables.transfo<caret>rm(Collections.emptyList(), function);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import java.lang.String;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class c {
|
||||
void m() {
|
||||
final Function<String, String> function = (Function<String, String>)new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String input) {
|
||||
Collectors c;
|
||||
ArrayList l;
|
||||
System.out.println(input);
|
||||
//do something
|
||||
int i = 1;
|
||||
return input;
|
||||
}
|
||||
};
|
||||
Collections.<String>emptyList().stream().map(function::apply).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+4
@@ -108,6 +108,10 @@ public class StaticPseudoFunctionalStyleMethodTest extends JavaCodeInsightFixtur
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testLambdaIsVariable() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void _testReplaceWithMethodReference() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user