mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lambda: get info for return types from type arguments
This commit is contained in:
@@ -289,6 +289,11 @@ public class LambdaUtil {
|
||||
public static boolean isFreeFromTypeInferenceArgs(final PsiParameter[] methodParameters,
|
||||
final PsiLambdaExpression lambdaExpression,
|
||||
final PsiExpression expression) {
|
||||
if (expression instanceof PsiCallExpression && ((PsiCallExpression)expression).getTypeArguments().length > 0) return true;
|
||||
if (expression instanceof PsiNewExpression) {
|
||||
final PsiJavaCodeReferenceElement classReference = ((PsiNewExpression)expression).getClassOrAnonymousClassReference();
|
||||
if (classReference != null && classReference.getTypeParameters().length > 0) return true;
|
||||
}
|
||||
final PsiParameter[] lambdaParams = lambdaExpression.getParameterList().getParameters();
|
||||
if (lambdaParams.length != methodParameters.length) return false;
|
||||
final boolean [] independent = new boolean[]{true};
|
||||
|
||||
+1
-1
@@ -629,7 +629,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
|
||||
}
|
||||
|
||||
final Pair<PsiType, ConstraintType> returnExprConstraint =
|
||||
getSubstitutionForTypeParameterConstraint(typeParam, returnType, exprType, false, PsiUtil.getLanguageLevel(method));
|
||||
getSubstitutionForTypeParameterConstraint(typeParam, returnType, exprType, true, PsiUtil.getLanguageLevel(method));
|
||||
if (returnExprConstraint != null) {
|
||||
if (returnExprConstraint == FAILED_INFERENCE) return returnExprConstraint;
|
||||
if (constraint != null) {
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import java.util.*;
|
||||
public class BugReportLambdaSquiggles<T> {
|
||||
|
||||
private T t;
|
||||
public <V> List<V> flatMap(Mapper<T, List<V>> mapper) {
|
||||
return mapper.map(t);
|
||||
}
|
||||
|
||||
static void bar( BugReportLambdaSquiggles<Integer> x) {
|
||||
x.flatMap(t1 -> new ArrayList<String>(t1));
|
||||
}
|
||||
|
||||
interface Mapper<T, U> {
|
||||
U map(T t);
|
||||
}
|
||||
}
|
||||
+4
@@ -68,6 +68,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testInferenceOnMethodCallSite() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInferFromTypeArgs() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAmbiguity1() throws Exception {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user