diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java
index c75265125f1a..6555abe23376 100644
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java
+++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java
@@ -2635,13 +2635,6 @@ public class HighlightUtil {
@Nullable
public static HighlightInfo checkLambdaFeature(final PsiLambdaExpression expression) {
- final HighlightInfo info = checkFeature(expression, Feature.LAMBDA_EXPRESSIONS);
- if (info != null) return info;
- if (expression.getParent() instanceof PsiExpressionList) {
- // todo[r.sh] stub; remove after implementing support in TypeConversionUtil
- final String message = "Lambda expressions type check is not yet implemented";
- return HighlightInfo.createHighlightInfo(HighlightInfoType.WEAK_WARNING, expression, message);
- }
- return null;
+ return checkFeature(expression, Feature.LAMBDA_EXPRESSIONS);
}
}
diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaHighlightInfoFilter.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaHighlightInfoFilter.java
deleted file mode 100644
index 7fde93aad8db..000000000000
--- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/analysis/JavaHighlightInfoFilter.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2000-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.codeInsight.daemon.impl.analysis;
-
-import com.intellij.codeInsight.daemon.impl.HighlightInfo;
-import com.intellij.codeInsight.daemon.impl.HighlightInfoFilter;
-import com.intellij.lang.annotation.HighlightSeverity;
-import com.intellij.psi.*;
-import com.intellij.psi.util.PsiTreeUtil;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * A filter to temporarily suppress highlighting errors inside lambda expressions.
- * todo[r.sh] stub; remove after implementing type inference
- */
-public class JavaHighlightInfoFilter implements HighlightInfoFilter {
- @Override
- public boolean accept(@NotNull final HighlightInfo info, @Nullable final PsiFile file) {
- if (!(file instanceof PsiJavaFile)) return true;
- if (info.getSeverity() != HighlightSeverity.ERROR) return true;
- if (description(info, "Lambda expressions are not supported at this language level")) return true;
-
- final PsiElement element = file.findElementAt(info.getStartOffset());
- if (element == null) return true;
- final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class, false);
- if (lambdaExpression != null) {
- if (lambdaExpression.getParent() instanceof PsiExpressionList) return false;
- if (isLambdaInAmbiguousCall(info, element)) return false;
- }
- return true;
- }
-
- private static boolean isLambdaInAmbiguousCall(final HighlightInfo info, final PsiElement element) {
- if (!description(info, "Ambiguous method call")) return false;
- final PsiElement exprList = element.getParent();
- if (!(exprList instanceof PsiExpressionList)) return false;
- return PsiTreeUtil.getChildOfType(exprList, PsiLambdaExpression.class) != null;
- }
-
- private static boolean description(final HighlightInfo info, final String prefix) {
- return info.description != null && info.description.startsWith(prefix);
- }
-}
diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/LambdaUtil.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/LambdaUtil.java
index 87743e188a4f..12f8004304bf 100644
--- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/LambdaUtil.java
+++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/LambdaUtil.java
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.tree.java;
import com.intellij.psi.*;
import com.intellij.psi.util.*;
+import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -114,19 +115,13 @@ public class LambdaUtil {
final int parameterIndex = ((PsiParameterList)paramParent).getParameterIndex(param);
if (parameterIndex > -1) {
final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(param, PsiLambdaExpression.class);
- if (lambdaExpression != null) {
- final PsiElement parent = lambdaExpression.getParent();
- PsiType type = null;
- if (parent instanceof PsiTypeCastExpression) {
- type = ((PsiTypeCastExpression)parent).getType();
- } else if (parent instanceof PsiVariable) {
- type = ((PsiVariable)parent).getType();
- }
- if (type instanceof PsiClassType) {
- final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)type).resolveGenerics();
- final MethodSignature methodSignature = getFunction(resolveResult.getElement());
- if (methodSignature != null) {
- return resolveResult.getSubstitutor().substitute(methodSignature.getParameterTypes()[parameterIndex]);
+ final PsiClassType.ClassResolveResult resolveResult = getFunctionInterfaceType(lambdaExpression);
+ if (resolveResult != null) {
+ final MethodSignature methodSignature = getFunction(resolveResult.getElement());
+ if (methodSignature != null) {
+ final PsiType[] types = methodSignature.getParameterTypes();
+ if (parameterIndex < types.length) {
+ return resolveResult.getSubstitutor().substitute(types[parameterIndex]);
}
}
}
@@ -134,4 +129,46 @@ public class LambdaUtil {
}
return new PsiLambdaParameterType(param);
}
+
+ @Nullable
+ public static PsiClassType.ClassResolveResult getFunctionInterfaceType(@Nullable PsiLambdaExpression lambdaExpression) {
+ if (lambdaExpression != null) {
+ final PsiElement parent = lambdaExpression.getParent();
+ PsiType type = null;
+ if (parent instanceof PsiTypeCastExpression) {
+ type = ((PsiTypeCastExpression)parent).getType();
+ }
+ else if (parent instanceof PsiVariable) {
+ type = ((PsiVariable)parent).getType();
+ }
+ else if (parent instanceof PsiExpressionList) {
+ final PsiExpressionList expressionList = (PsiExpressionList)parent;
+ final int lambdaIdx = ArrayUtil.find(expressionList.getExpressions(), lambdaExpression);
+ if (lambdaIdx > -1) {
+ final PsiElement gParent = expressionList.getParent();
+ if (gParent instanceof PsiMethodCallExpression) {
+ final JavaResolveResult resolveResult = ((PsiMethodCallExpression)gParent).resolveMethodGenerics();
+ final PsiElement resolve = resolveResult.getElement();
+ if (resolve instanceof PsiMethod) {
+ final PsiParameter[] parameters = ((PsiMethod)resolve).getParameterList().getParameters();
+ if (lambdaIdx < parameters.length) {
+ type = resolveResult.getSubstitutor().substitute(parameters[lambdaIdx].getType());
+ }
+ }
+ }
+ }
+ }
+ else if (parent instanceof PsiReturnStatement) {
+ final PsiMethod method = PsiTreeUtil.getParentOfType(parent, PsiMethod.class);
+ if (method != null) {
+ type = method.getReturnType();
+ }
+ }
+
+ if (type instanceof PsiClassType) {
+ return ((PsiClassType)type).resolveGenerics();
+ }
+ }
+ return null;
+ }
}
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/LambdaExpressions.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/LambdaExpressions.java
index 0565649cadc9..2ab94e139476 100644
--- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/LambdaExpressions.java
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/LambdaExpressions.java
@@ -28,7 +28,7 @@ class C {
void test() {
Simplest simplest = () -> { };
- use(() -> { });
+ use(() -> { });
IntParser intParser = (String s) -> Integer.parseInt(s);
}
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/FormalParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/FormalParams.java
index 5bc3abf128d9..385738c28f61 100644
--- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/FormalParams.java
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/FormalParams.java
@@ -9,4 +9,10 @@ class Foo {
I ii1 = (final int k)->{
String s = k;
};
+
+ void bazz() {
+ bar((String s) -> {
+ System.out.println(s);});
+ }
+ void bar(I i){}
}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/InferredParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/InferredParams.java
index 2c1322337ec1..af7bbc9b814c 100644
--- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/InferredParams.java
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/InferredParams.java
@@ -1,5 +1,3 @@
-import java.lang.String;
-
interface I {
void m(int i);
}
@@ -19,5 +17,19 @@ class Foo {
String s = ab;
int i = ab;
};
+
+ A bazz() {
+ bar((o) -> {
+ String s = o;
+ int i = o;
+ });
+ return (i) -> {
+ Integer k = i;
+ int n = i;
+ String s = i;
+ };
+ }
+
+ void bar(A a){}
}
diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/MethodApplicability.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/MethodApplicability.java
index 9c779b8081c7..cd82c711775f 100644
--- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/MethodApplicability.java
+++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/params/MethodApplicability.java
@@ -15,7 +15,7 @@ class Foo {
void bar() {
foo((p) -> {
- System.out.println(p);
+ System.out.println(p);
});
foo((p, k) -> {
diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml
index 7eee4094abd1..5cc31d889e58 100644
--- a/resources/src/META-INF/IdeaPlugin.xml
+++ b/resources/src/META-INF/IdeaPlugin.xml
@@ -378,7 +378,6 @@
-