mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
correct lambda inference inside new expressions
This commit is contained in:
@@ -262,7 +262,16 @@ public class LambdaUtil {
|
||||
public static boolean dependsOnTypeParams(PsiType type,
|
||||
PsiLambdaExpression expr,
|
||||
PsiTypeParameter param2Check) {
|
||||
final TypeParamsChecker visitor = new TypeParamsChecker(expr);
|
||||
return depends(type, param2Check, new TypeParamsChecker(expr));
|
||||
}
|
||||
|
||||
public static boolean dependsOnTypeParams(PsiType type,
|
||||
PsiClass aClass,
|
||||
PsiMethod aMethod) {
|
||||
return depends(type, null, new TypeParamsChecker(aMethod, aClass));
|
||||
}
|
||||
|
||||
private static boolean depends(PsiType type, PsiTypeParameter param2Check, TypeParamsChecker visitor) {
|
||||
if (!visitor.startedInference()) return false;
|
||||
final Boolean accept = type.accept(visitor);
|
||||
if (param2Check != null) {
|
||||
@@ -328,8 +337,8 @@ public class LambdaUtil {
|
||||
}
|
||||
|
||||
final PsiElement gParent = expressionList.getParent();
|
||||
if (gParent instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression contextCall = (PsiMethodCallExpression)gParent;
|
||||
if (gParent instanceof PsiCallExpression) {
|
||||
final PsiCallExpression contextCall = (PsiCallExpression)gParent;
|
||||
final JavaResolveResult resolveResult = contextCall.resolveMethodGenerics();
|
||||
final PsiElement resolve = resolveResult.getElement();
|
||||
if (resolve instanceof PsiMethod) {
|
||||
@@ -403,6 +412,11 @@ public class LambdaUtil {
|
||||
private final PsiClass myClass;
|
||||
private final Set<PsiTypeParameter> myUsedTypeParams = new HashSet<PsiTypeParameter>();
|
||||
|
||||
private TypeParamsChecker(PsiMethod method, PsiClass aClass) {
|
||||
myMethod = method;
|
||||
myClass = aClass;
|
||||
}
|
||||
|
||||
public TypeParamsChecker(PsiLambdaExpression expression) {
|
||||
myClass = PsiUtil.resolveGenericsClassInType(getFunctionalInterfaceType(expression, false)).getElement();
|
||||
PsiElement parent = expression.getParent();
|
||||
|
||||
+11
-1
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
class Test1 {
|
||||
{
|
||||
Comparable<? extends Integer> c = (Integer o)->{
|
||||
@@ -46,3 +46,13 @@ class Test2<U> {
|
||||
}
|
||||
}
|
||||
|
||||
class TestNewExpression<E> {
|
||||
public TestNewExpression(Comparator<? super E> comparator) {
|
||||
//some code
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
TestNewExpression<String> strs = new TestNewExpression<String>((o1, o2) -> {
|
||||
return o2.compareToIgnoreCase(o1);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user